In a fast-growing firm, new employees are hired all the time. Every new employee p is given exactly one direct superior. That superior's own superiors (direct and indirect) automatically become indirect superiors of p as well.
We call the direct superior of p a superior of degree 0. The superior of a degree-0 superior is a superior of degree 1, and in general the superior of a degree-k superior is a superior of degree k+1. So each employee is a subordinate of their direct superior and of every higher-degree superior above them. Together this forms a single hierarchy of all employees, with the company's founder at the very top.
The company keeps a full history of everyone who has joined since it was founded. From time to time an employee wants to know, for a given degree k, how many current employees have them as a superior of exactly degree k. Write a program that answers these questions.
The first line contains an integer n (1≤n≤105), the number of events. The next n lines each describe one event, in chronological order.
A hiring event is the character Z followed by two integers p and s (2≤p≤105, and p is distinct across all hires): p is the number of the new employee and s is the number of the direct superior. s is always the number of an employee who is already working at the company. The founder has number 1.
A question event is the character P followed by two integers q and k (1≤q≤105, 0≤k≤105): employee q asks how many current employees have q as a superior of exactly degree k.
Before the first event, the founder is the only person at the firm.
For each question event, print a single line with one integer: the number of current employees for whom q is a superior of exactly degree k.
