Station

아직 제출이 없습니다시간 제한4.5초메모리 제한1024 MB

문제

There are nn bus stations and nn bus lines along the main street of City A. The bus stations are labeled from 11 to nn from left to right, and the importance of station ii is a_ia\_i. The bus lines are also numbered from 11 to nn. A bus of line kk stops at stations whose importance is greater than or equal to kk. Each bus line operates in both directions.

A tourist standing at station xx can take any bus that stops at station xx, pick a direction, and go to the next station yy visited by that bus in that direction (of course, it is only possible if such station exists). The cost of such trip is l_xl\_x yuan if y<xy < x, or r_xr\_x yuan if y>xy > x. Tourists can take multiple bus trips to reach their destination.

Now there are qq tourists, and the jj-th tourist wants to travel from station s_js\_j to station t_jt\_j. Your task is to find the minimum cost of the route for each tourist.

It is guaranteed that, for each ii from 11 to n1n - 1, the following are true: l_il_i+1l\_{i} \le l\_{i + 1} and r_ir_i+1r\_{i} \ge r\_{i + 1}.

입력

The first line of input contains a single integer TT, the number of test cases (1T31041 \le T \le 3 \cdot 10^4). The descriptions of test cases follow.

The first line of each test case contains two integers nn and qq: the number of stations and the number of tourists (1n,q31051 \le n, q \le 3 \cdot 10^5).

The second line contains nn integers a_1,,a_na\_1, \ldots, a\_n, where a_ia\_i is the importance of station ii (1a_in1 \le a\_i \le n).

Then follow nn lines, the ii-th of which contains two integers l_il\_i and r_ir\_i: the costs at station ii (1l_i,r_i1091 \le l\_i, r\_i \le 10^9, l_il_i+1l\_{i} \le l\_{i + 1}, r_ir_i+1r\_{i} \ge r\_{i + 1}).

Then follow qq lines, the jj-th of which contains two integers s_js\_j and t_jt\_j: the endpoints of a route for jj-th tourist (1s_j,t_jn1 \le s\_j, t\_j \le n).

The sum of nn and the sum of qq over all test cases do not exceed 31053 \cdot 10^5.

출력

For each tourist, output a line with the answer.