#CF2239E. 世界的尽头 / E. The end of this world,

世界的尽头 / E. The end of this world,

E. The end of this world,

Source: Codeforces 2239E
Contest: Codeforces Round 1105 (Div. 1)
Time limit: 5 seconds
Memory limit: 1024 megabytes

Statement

... and the girl who crossed the moon's oceans.

— Frums

You are given an undirected graph consisting of nn vertices and mm edges. The ii-th vertex has an associated value vali\mathrm{val}_i. The jj-th edge connects vertices uju_j and vjv_j and has two properties: a capacity wjw_j and a floor lowj\mathrm{low}_j. It is guaranteed that wjlowjw_j \ge \mathrm{low}_j for all edges.

You want to start a walk from a vertex ss. Before the walk begins, you must choose an arbitrary non-negative integer hstarth_{start} as your initial state parameter.

If you are currently at vertex uu with state hh, you can traverse an edge jj connecting uu and vv if and only if wjhw_j \ge h. Upon traversing this edge and arriving at vertex vv, the state parameter hh updates to max(h,lowj)\max(h, \mathrm{low}_j).

Let the walk end at some vertex tt. You must traverse at least one edge. The score of such a walk is defined as valt+hstart\mathrm{val}_t + h_{start}. Note that we are interested in the sum of the final vertex value and the initial state parameter, not the final state parameter.

For each starting vertex ss from 11 to nn, calculate the maximum possible score achievable. If it is impossible to traverse any edge starting from some ss, output 1-1 instead.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1n5105,0m51051 \le n \le 5\cdot 10^5, 0 \le m \le 5\cdot 10^5) — the number of vertices and the number of edges.

The second line of each test case contains nn integers $\mathrm{val}_1, \mathrm{val}_2, \ldots, \mathrm{val}_n$ (1vali1091 \le \mathrm{val}_i \le 10^9) — the values of the vertices.

The next mm lines describe the edges. The jj-th line contains four integers uj,vj,wj,lowju_j, v_j, w_j, \mathrm{low}_j (1uj,vjn,ujvj1 \le u_j, v_j \le n, u_j \neq v_j; 1lowjwj1091 \le \mathrm{low}_j \le w_j \le 10^9) — the endpoints and properties of the jj-th edge.

The graph is not guaranteed to be connected and may contain multiple edges.

It is guaranteed that the sum of nn and the sum of mm over all test cases do not exceed 51055\cdot 10^5.

Output

For each test case, output nn integers separated by spaces. The ii-th integer should be the maximum score achievable starting from vertex ii, or 1-1 if no edge can be traversed.

Note

In the first test case, here are the optimal hstarth_{start} values and paths for each starting node:

  • For node 11, it is optimal to use hstart=5h_{start}=5. Then, take the path from node 11 to node 22. hh is updated to max(5,2)=5\operatorname{max}(5,2)=5. The path ends, and the score is 20+5=2520+5=25.
  • For node 22, it is optimal to use hstart=5h_{start}=5. Then, take the path from node 22 to node 11, then from node 11 to node 22. The score is 20+5=2520+5=25.
  • For node 33, it is optimal to use hstart=4h_{start}=4. Then, take the path from node 33 to node 22. The score is 20+4=2420+4=24.

In the third test case, since there are no edges incident to either node, the answer is 1-1 for both.

Examples

9
3 2
10 20 5
1 2 5 2
2 3 4 3
2 1
100 10
1 2 10 5
2 0
50 50
1 0
114514
4 1
1 2 3 4
3 4 2 1
3 2
1 4 1
1 3 4 1
1 2 2 1
3 2
10 3 2
2 3 4 4
2 1 3 2
3 2
5 2 2
3 2 4 4
1 3 5 5
5 9
857147200 381798978 633421584 956726892 315899900
2 1 883474754 795831571
2 4 657281748 375466725
1 3 666641114 444218918
2 3 901861650 790895313
3 2 613790652 96876004
2 5 852725279 216601090
3 4 500240642 193633892
2 5 210434355 130646156
3 2 457018372 279005896
25 25 24
110 110
-1 -1
-1
-1 -1 6 6
6 6 6
13 13 7
10 9 10
1740621954 1740621954 1740621954 1614008640 1709872479