Quick Answer

Time limit1sMemory limit128 MB

Problem

Joe is fond of computer games. He is now facing a large map dotted with fortified towns. His opponent can issue commands that connect or disconnect towns.

Think of the towns as being organized into groups. Two towns are connected exactly when they belong to the same group. Initially every town sits alone in its own group and is isolated.

  • A connect command merges the two groups that contain the two named towns into a single group. So connecting to any one town also connects you to every town already in that town's group.
  • A disconnect command takes a single named town out of its current group, isolating it again. The other towns that shared its group stay connected to one another. The removed town keeps no memory of its former connections, so it must be reconnected explicitly.

Between the opponent's commands, questions of the form "is town $i$ connected with town $j$?" appear. Write a program that counts how many questions are answered "yes" and how many are answered "no".

Input

The input may contain several data sets; each data set describes one map together with its commands, in the following form:

  • The first line holds the number of towns $N$ ($N \le 10000$).
  • Then each command appears on its own line:
    • c i j — merge the groups containing towns $i$ and $j$ ($1 \le i, j \le N$).
    • d i — remove town $i$ from its group, isolating it ($1 \le i \le N$).
    • q i j — the question: is town $i$ connected with town $j$? ($1 \le i, j \le N$).
    • e — marks the end of the current data set's command list.

The c, d, and q commands may appear in any order, and each command is processed against the current configuration. Several data sets may follow one another until the end of the file.

Output

For each data set, print on one line the number of questions answered "yes", $N_1$, and the number answered "no", $N_2$. Write the two numbers in the form N_1 , N_2, separated by a space, a comma, and a space (,). For instance, the data set in the example below has 2 "yes" answers and 2 "no" answers, so it prints 2 , 2.