The WLM corporation has asked for your help in creating a system to determine employee salaries.
WLM has employees with ids from
to
such that employee
is the CEO. Each employee except for the CEO has exactly one boss. We say that employee
is a superior of employee
if
is the boss of
or
is a superior of the boss of
. The team of employee
is defined as the set of employees that have
as their superior and
themselves.
WLM would like to be able to process the following two queries efficiently:
c A S
: change the salary of employeeto
.
q A
: compute the total salary of employee's team.
Input Specification
The first line of input contains one integer
, the number of employees in the company.
The next
lines each two integers
, the boss and salary of employee
, respectively.
will be equal to zero as employee
is the CEO.
The next line contains a single integer
, the number of queries to process.
The next
lines each contain a single query in the format described above.
Output Specification
For each query of type q A
, print the answer on a separate line.
Sample Input 1
5
0 1
1 1
1 1
2 1
2 1
5
q 1
c 4 2
q 2
c 3 5
q 1
Sample Output 1
5
4
10
Comments