#P7369. [COCI 2018/2019 #4] Elder

[COCI 2018/2019 #4] Elder

Description

After watching eight Harry Potter movies in a week, Nikola realized how powerful the Elder Wand is. If the Elder Wand currently serves wizard A, and wizard A is defeated by wizard B, then the Elder Wand will start serving wizard B.

Now several wizards will have NN duels. Given the wizard the Elder Wand initially serves and the results of the NN duels, find:

  1. After the NN duels, who the Elder Wand serves.
  2. How many wizards has the Elder Wand served in total?

Input Format

The first line contains one uppercase letter, representing the wizard the Elder Wand initially serves.

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

Each of the next NN lines contains two uppercase letters Z1Z_1 and Z2Z_2 separated by a space, meaning that in the ii-th duel, wizard Z1Z_1 defeated wizard Z2Z_2.

Output Format

Output one uppercase letter on the first line, representing the answer to question 1.

Output one integer on the second line, representing the answer to question 2.

A
3
B A
C B
D A
C
3
N
5
D A
N B
B A
C D
F A
N
1
X
4
A X
B X
X A
D A
X
2

Hint

Explanation for Sample 1

The Elder Wand initially serves wizard A. After the first duel, the Elder Wand starts serving B. After the second duel, the Elder Wand starts serving C. The third duel after that does not affect who the Elder Wand serves.

Constraints

For 100%100\% of the testdata, 1N1001 \le N \le 100.

Scoring

In each test case, the first line is worth 22 points and the second line is worth 33 points, for a total of 55 points per test case. If you only want to get the points for one line, please output any number on the other line as well; otherwise, it cannot be judged correctly.

A Special Judge is needed for scoring; see the attachment for details.

Notes

The score of this problem follows the original COCI setting, with a full score of 5050.

Translated from COCI2018-2019 CONTEST #4 T1 Elder.

Translated by ChatGPT 5