The first line contains three space-separated integers $n, q$ and $w (2 ≤ n ≤ 100,000,1 ≤ q ≤ 100,000, 1 ≤ w ≤ 20,000,000,000,000)$ – the number of vertices in the tree, the number of updates and the limit on the weights of edges. The vertices are numbered $1$ through $n$.
Next, $n−1$ lines describing the initial tree follow. The $i$-th of these lines contains three space-separated integers $a_i, b_i, c_i (1 ≤ a_i,b_i ≤ n, 0 ≤ c_i < w)$ meaning that initially, there is an edge between vertices $a_i$ and $b_i$ with weight $c_i$. It is guaranteed that these $n−1$ lines describe a tree.
Finally, $q$ lines describing queries follow. The $j$-th of these lines contains two space-separated integers $d_j, e_j (0 ≤ d_j < n−1,0 ≤ e_j < w)$. These two integers are then transformed according to the following scheme:
- $d'_j=(d_j+last) \bmod (n-1)$
- $e'_j=(e_j+last) \bmod w$
where last is the result of the last query (initially $last = 0$). Tuple $(d'_j,e'_j)$ represents a query which takes the $d'_j + 1$-th edge from the input and sets its weight to $e'_j$.