Problem Statement
There are integer sequences A,B,C of length M each.
C is represented by integers x1,dots,xN,y1,dots,yN. The first y1 terms of C are x1, the subsequent y2 terms are x2, ldots, the last yN terms are xN.
B is defined by Bi=sumk=1iCk,(1leqileqM).
A is defined by Ai=sumk=1iBk,(1leqileqM).
Find the maximum value among A1,dots,AM.
You will be given T test cases to solve.
Constraints
- 1leqTleq2times105
- 1leqNleq2times105
- The sum of N in a single file is at most 2times105.
- 1leqMleq109
- ∣xi∣leq4,(1leqileqN)
- yigt0,(1leqileqN)
- sumk=1Nyk=M
- All values in input are integers.
Input is given from Standard Input in the following format:
T
mathrmcase1
vdots
mathrmcaseT
Each case is in the following format:
N M
x1 y1
vdots
xN yN
Output
Print T lines. The i-th line (1leqileqT) should contain the answer to the i-th test case.
3
3 7
-1 2
2 3
-3 2
10 472
-4 12
1 29
2 77
-1 86
0 51
3 81
3 17
-2 31
-4 65
4 23
1 1000000000
4 1000000000
Sample Output 1
4
53910
2000000002000000000
In the first test case, we have:
- C=(−1,−1,2,2,2,−3,−3)
- B=(−1,−2,0,2,4,1,−2)
- A=(−1,−3,−3,−1,3,4,2)
Thus, the maximum value among A1,dots,AM is 4.