#P7865. Jump

Jump

Jump

Problem Description

You are given a rooted tree with nn nodes, each edge of the tree has a weight, the nodes of the tree are numbered from 11 to nn, the root of the tree is rtrt. You are also given an array aa with nn elements. Define dep(x)dep(x) as the sum of weight of edges on the simple path between rtrt and xx. Define fa(x)fa(x) as the father of node xx, especially, we define fa(rt)=rtfa(rt)=rt. There are mm operations of two types: 1 l r: for each ii that satisfies lirl \le i \le r, ai:=fa(ai)a_i := fa(a_i). 2 l r: for each ii that satisfies lirl \le i \le r, output the minimum dep(ai)dep(a_i).

Input

The input contains several test cases, and the first line contains a single integer TT, the number of test cases. For each test case: The first line contains three integers n,m,rtn,m,rt. For the following n1n-1 lines, each line contains three integers u,v,du,v,d, which means that there is an edge between u,vu,v, the weight of which is dd. The next line contains nn integers, the ith integer is aia_i. For the following mm lines, each line contains three integers opt,l,ropt,l,r, which means that there is a operation of type optopt for l,rl,r. 1T41\le T \le 4, 1n,m21051\le n,m\le 2\cdot 10^5, the weight of edge is an integer in range [0,109][0,10^9].

Output

For each operation that opt=2opt=2, output one line representing the answer.

Sample Input

4
5 1 5
2 5 4
1 5 4
3 2 1
4 2 3
3 4 3 2 5
2 3 3
6 2 1
6 1 1
2 1 1
4 2 3
5 4 2
3 2 1
2 3 6 1 2 6
2 4 6
2 3 3
5 1 5
4 5 3
2 4 2
1 4 2
3 5 3
1 1 5 2 5
2 2 2
5 4 3
2 3 1
1 2 4
5 2 2
4 5 4
1 4 1 1 4
2 2 5
1 1 5
2 2 2
1 1 4

Sample Output

5
0
1
5
5
3

Source

2020 Multi-University Training Contest 9