You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The $$$i$$$-th vertex has an associated value $$$\mathrm{val}_i$$$. The $$$j$$$-th edge connects vertices $$$u_j$$$ and $$$v_j$$$ and has two properties: a capacity $$$w_j$$$ and a floor $$$\mathrm{low}_j$$$. It is guaranteed that $$$w_j \ge \mathrm{low}_j$$$ for all edges.
You want to start a walk from a vertex $$$s$$$. Before the walk begins, you must choose an arbitrary non-negative integer $$$h_{start}$$$ as your initial state parameter.
If you are currently at vertex $$$u$$$ with state $$$h$$$, you can traverse an edge $$$j$$$ connecting $$$u$$$ and $$$v$$$ if and only if $$$w_j \ge h$$$. Upon traversing this edge and arriving at vertex $$$v$$$, the state parameter $$$h$$$ updates to $$$\max(h, \mathrm{low}_j)$$$.
Let the walk end at some vertex $$$t$$$. You must traverse at least one edge. The score of such a walk is defined as $$$\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 $$$s$$$ from $$$1$$$ to $$$n$$$, calculate the maximum possible score achievable. If it is impossible to traverse any edge starting from some $$$s$$$, output $$$-1$$$ instead.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \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 $$$n$$$ integers $$$\mathrm{val}_1, \mathrm{val}_2, \ldots, \mathrm{val}_n$$$ ($$$1 \le \mathrm{val}_i \le 10^9$$$) — the values of the vertices.
The next $$$m$$$ lines describe the edges. The $$$j$$$-th line contains four integers $$$u_j, v_j, w_j, \mathrm{low}_j$$$ ($$$1 \le u_j, v_j \le n, u_j \neq v_j$$$; $$$1 \le \mathrm{low}_j \le w_j \le 10^9$$$) — the endpoints and properties of the $$$j$$$-th edge.
The graph is not guaranteed to be connected and may contain multiple edges.
It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases do not exceed $$$5\cdot 10^5$$$.
For each test case, output $$$n$$$ integers separated by spaces. The $$$i$$$-th integer should be the maximum score achievable starting from vertex $$$i$$$, or $$$-1$$$ if no edge can be traversed.
93 210 20 51 2 5 22 3 4 32 1100 101 2 10 52 050 501 01145144 11 2 3 43 4 2 13 21 4 11 3 4 11 2 2 13 210 3 22 3 4 42 1 3 23 25 2 23 2 4 41 3 5 55 9857147200 381798978 633421584 956726892 3158999002 1 883474754 7958315712 4 657281748 3754667251 3 666641114 4442189182 3 901861650 7908953133 2 613790652 968760042 5 852725279 2166010903 4 500240642 1936338922 5 210434355 1306461563 2 457018372 279005896
25 25 24110 110-1 -1-1-1 -1 6 66 6 613 13 710 9 101740621954 1740621954 1740621954 1614008640 1709872479
In the first test case, here are the optimal $$$h_{start}$$$ values and paths for each starting node:
In the third test case, since there are no edges incident to either node, the answer is $$$-1$$$ for both.