P29600 [洛谷] [COCI2018-2019#4] Elder
普及-
题目描述

Problem Description

After watching all eight Harry Potter movies in a week, Nikola experienced the immense power of the Elder Wand. The Elder Wand pledges allegiance to a wizard A. If wizard A is defeated by wizard B, the Elder Wand will then pledge allegiance to wizard B.

Several wizards will engage in N duels. Given the initial wizard the Elder Wand pledges allegiance to and the results of N duels, determine:

  1. The wizard the Elder Wand pledges allegiance to after N duels.
  2. How many different wizards the Elder Wand has pledged allegiance to?

Input Format

The first line contains a single uppercase letter representing the initial wizard the Elder Wand pledges allegiance to.

The second line contains an integer N, representing the number of duels.

The next N lines, each containing two uppercase letters Z1 and Z2 separated by a space, represent the i-th duel where wizard Z1 defeats wizard Z2.

Output Format

The first line contains a single uppercase letter representing the answer to the first question.

The second line contains an integer representing the answer to the second question.

Sample Input and Output

Input Sample #1

A
3
B A
C B
D A

Output Sample #1

C
3

Input Sample #2

N
5
D A
N B
B A
C D
F A

Output Sample #2

N
1

Input Sample #3

X
4
A X
B X
X A
D A

Output Sample #3

X
2

Notes

Sample 1 Explanation

The Elder Wand initially pledges allegiance to wizard A. After the first duel, it pledges allegiance to B. After the second duel, it pledges allegiance to C. The third duel has no effect on the allegiance of the Elder Wand.

Data Size and Constraints

For 100% of the data, $1 \le N \le 100$.

Scoring Method

Each test case is worth 5 points. The first line is worth 2 points, and the second line is worth 3 points. If you only want to score for one line, please output any number on the other line to ensure proper scoring.

The Special Judge required for scoring is detailed in the attachment.

Note

This problem's score is set according to the original COCI contest, with a maximum score of 50.

Translated from COCI2018-2019 CONTEST #4 T1 Elder.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
A 3 B A C B D A
样例输出
C 3