#abc240f. [abc240_f]Sum Sum Max

[abc240_f]Sum Sum Max

Problem Statement

There are integer sequences A,B,CA, B, C of length MM each.

CC is represented by integers x1,dots,xN,y1,dots,yNx_1, \\dots, x_N, y_1, \\dots, y_N. The first y1y_1 terms of CC are x1x_1, the subsequent y2y_2 terms are x2x_2, ldots\\ldots, the last yNy_N terms are xNx_N.

BB is defined by Bi=sumk=1iCk,(1leqileqM)B_i = \\sum_{k = 1}^i C_k \\, (1 \\leq i \\leq M).

AA is defined by Ai=sumk=1iBk,(1leqileqM)A_i = \\sum_{k = 1}^i B_k \\, (1 \\leq i \\leq M).

Find the maximum value among A1,dots,AMA_1, \\dots, A_M.

You will be given TT test cases to solve.

Constraints

  • 1leqTleq2times1051 \\leq T \\leq 2 \\times 10^5
  • 1leqNleq2times1051 \\leq N \\leq 2 \\times 10^5
  • The sum of NN in a single file is at most 2times1052 \\times 10^5.
  • 1leqMleq1091 \\leq M \\leq 10^9
  • xileq4,(1leqileqN)|x_i| \\leq 4 \\, (1 \\leq i \\leq N)
  • yigt0,(1leqileqN)y_i \\gt 0 \\, (1 \\leq i \\leq N)
  • sumk=1Nyk=M\\sum_{k = 1}^N y_k = M
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

TT mathrmcase1\\mathrm{case}_1 vdots\\vdots mathrmcaseT\\mathrm{case}_T

Each case is in the following format:

NN MM x1x_1 y1y_1 vdots\\vdots xNx_N yNy_N

Output

Print TT lines. The ii-th line (1leqileqT)(1 \\leq i \\leq T) should contain the answer to the ii-th test case.


Sample Input 1

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)C = (-1, -1, 2, 2, 2, -3, -3)
  • B=(1,2,0,2,4,1,2)B = (-1, -2, 0, 2, 4, 1, -2)
  • A=(1,3,3,1,3,4,2)A = (-1, -3, -3, -1, 3, 4, 2)

Thus, the maximum value among A1,dots,AMA_1, \\dots, A_M is 44.