Task
Pablo is one of the most notorious men in the Wild West, well known for his influence upon cities interconnected by roads forming a tree structure. Pablo's trusted men are traffickers, transporting merchandise relentlessly. Each trafficker is defined by a pair a cities as follows: the trafficker travels starting with time from city towards city , on the shortest path. At each integer moment of time each trafficker delivers one unit of merchandise, then moves on to the next city.
Pablo's traffickers are not easy to track: once a trafficker reaches his destination city and delivers the merchandise, at the next moment of time he teleports back to city (if at time he delivers merchandise in city , then at time he will deliver in city ). As business is flourishing and it would be a shame for it to stop, the traffickers will follow their routes forever.
Although the system put in place by Pablo seems unbreachable, he wonders whether there is any room for improvement. Thus, he will perform types of queries over the system:
- : Add a trafficker travelling between the pair of cities .
- : Remove a trafficker travelling between the pair of cities (u, v). It is guaranteed that such a trafficker exists.
- : Pablo wishes to know how many units of merchandise are delivered in total by all the existing traffickers, in all the cities along the shortest path between cities and inclusive, between times and inclusive.
Input data
The first line contains , the number of cities. The following lines contain integers and each, signifying that there is a direct road between cities and .
The next line contains , the number of traffickers initially present in Pablo's network. The following lines each contain numbers and , the pair of cities defining the path of a trafficker.
The next line contains , the number of queries Pablo intends to perform. The following lines each contain a query in the format mentioned above.
Output data
For each query of type output the answer on a separate line.
Constraints and clarifications
- The path of each trafficker covers at most cities (including its endpoints).
- Test cases will be scored individually.
# | Points | Constraints |
---|---|---|
1 | 15 | |
2 | 45 | |
3 | 40 | No additional constraints. |
Example
stdin
5
1 2
2 3
2 4
1 5
1
4 1
3
3 3 5 0 3
1 2 5
3 4 5 1 5
stdout
2
10
Explanation
Trafficker delivers units of merchandise on the path between times and :
- at city at time ;
- at city at time .