Traffickers

Time limit: 2.5s Memory limit: 512MB Input: Output:

Task

Pablo is one of the most notorious men in the Wild West, well known for his influence upon NN 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 (u,v)(u, v) as follows: the trafficker travels starting with time 00 from city uu towards city vv, 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 vv and delivers the merchandise, at the next moment of time he teleports back to city uu (if at time tt he delivers merchandise in city vv, then at time t+1t + 1 he will deliver in city uu). 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 33 types of queries over the system:

  • 1 u v1 \ u \ v: Add a trafficker travelling between the pair of cities (u,v)(u, v).
  • 2 u v2 \ u \ v: Remove a trafficker travelling between the pair of cities (u, v). It is guaranteed that such a trafficker exists.
  • 3 u v t1 t23 \ u \ v \ t_1 \ t_2: 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 uu and vv inclusive, between times t1t_1 and t2t_2 inclusive.

Input data

The first line contains NN, the number of cities. The following N1N - 1 lines contain 22 integers uu and vv each, signifying that there is a direct road between cities uu and vv.

The next line contains KK, the number of traffickers initially present in Pablo's network. The following KK lines each contain 22 numbers uu and vv, the pair of cities defining the path of a trafficker.

The next line contains QQ, the number of queries Pablo intends to perform. The following QQ lines each contain a query in the format mentioned above.

Output data

For each query of type 33 output the answer on a separate line.

Constraints and clarifications

  • 1N30 0001 \leq N \leq 30 \ 000
  • 0K50 0000 \leq K \leq 50 \ 000
  • 1Q50 0001 \leq Q \leq 50 \ 000
  • 0t1t22 000 000 0000 \leq t_1 \leq t_2 \leq 2 \ 000 \ 000 \ 000
  • The path of each trafficker covers at most 2020 cities (including its endpoints).
  • Test cases will be scored individually.
# Points Constraints
1 15 N1 000,K,Q500,0t1t210N \leq 1 \ 000, K, Q \leq 500, 0 \leq t_1 \leq t_2 \leq 10
2 45 N10 000,K,Q5 000N \leq 10 \ 000, K, Q \leq 5 \ 000
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 11 delivers 22 units of merchandise on the path 32153 → 2 → 1 → 5 between times 00 and 33:

  • at city 22 at time 11;
  • at city 11 at time 22.

Log in or sign up to be able to send submissions!