QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#14380. Query on a graph

Statistics

You are given a connected graph with $N$ nodes and $N$ edges. In this graph each node has a weight, and each edge has the same length of one unit. Define $D(u, v)$ as the distance between node $u$ and node $v$. Define $S(u, k)$ as the set of nodes $x$ which satisfy $D(u, x) \leq k$.

We will ask you to perform some instructions of the following forms.

  • MODIFY $u$ $k$ $d$: weight of all nodes in $S(u, k)$ increase by $d$ or decrease by $-d$.
  • QUERY $u$ $k$: ask for the sum of weight of all nodes in $S(u, k)$.

In the beginning, the weight of all nodes are $0$.

Input

The first line of input contains an integer $t$, the number of test cases. $t$ test cases follow.

For each test case, in the first line there is an integer $N(N \leq 100000)$.

The $i$-th line of the next $N$ line describes the $i$-th edge: two integers $u,v$ denotes an edge between $u$ and $v$.

In the next line, an integer $Q(Q \leq 100000)$ indicates the number of instructions.

Next $Q$ lines contain instructions MODIFY $u$ $k$ $d$ or QUERY $u$ $k$, where $|d| \leq 100$ and $0 \leq k \leq 2$.

Output

For each MODIFY instruction, output a integer in a line.

Example

Input

2
6
1 2
2 3
3 4
4 1
4 5
3 6
5
MODIFY 1 1 3
MODIFY 3 1 2
MODIFY 5 2 1
QUERY 3 2
QUERY 4 1
6
1 2
2 3
3 1
1 4
2 5
3 6
5
MODIFY 3 1 5
MODIFY 2 2 2
QUERY 6 1
MODIFY 4 1 -2
QUERY 2 2

Output

21
14
14
28
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.