#P1787I. Treasure Hunt

    ID: 292 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>data structuresdivide and conquertwo pointers*3400

Treasure Hunt

Description

Define the beauty value of a sequence b1,b2,,bcb_1,b_2,\ldots,b_c as the maximum value of i=1qbi+i=stbi\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i, where qq, ss, tt are all integers and s>qs > q or tqt\leq q. Note that bi=0b_i = 0 when i<1i<1 or i>ci>c, i=stbi=0\sum\limits_{i=s}^{t}b_i = 0 when s>ts>t.

For example, when b=[1,2,3]b = [-1,-2,-3], we may have q=0q = 0, s=3s = 3, t=2t = 2 so the beauty value is 0+0=00 + 0 = 0. And when b=[1,2,3]b = [-1,2,-3], we have q=s=t=2q = s = t = 2 so the beauty value is 1+2=31 + 2 = 3.

You are given a sequence aa of length nn, determine the sum of the beauty value of all non-empty subsegments al,al+1,,ara_l,a_{l+1},\ldots,a_r (1lrn1\leq l\leq r\leq n) of the sequence aa.

Print the answer modulo 998244353998\,244\,353.

Each test contains multiple test cases. The first line contains an integer TT (1T1041 \le T \le 10^4) — the number of test cases.

The first line contains an integer nn (1n1061\le n\le 10^6) — the length of aa.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (106ai106-10^6 \leq a_i \leq 10^6) — the given sequence.

It's guaranteed that the sum of nn does not exceed 10610^6.

For each test case, print a line containing a single integer — the answer modulo 998244353998\,244\,353.

Input

Each test contains multiple test cases. The first line contains an integer TT (1T1041 \le T \le 10^4) — the number of test cases.

The first line contains an integer nn (1n1061\le n\le 10^6) — the length of aa.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (106ai106-10^6 \leq a_i \leq 10^6) — the given sequence.

It's guaranteed that the sum of nn does not exceed 10610^6.

Output

For each test case, print a line containing a single integer — the answer modulo 998244353998\,244\,353.

Sample Input 1

4
7
80 59 100 -52 -86 -62 75
8
-48 -14 -26 43 -41 34 13 55
1
74
20
56 -60 62 13 88 -48 64 36 -10 19 94 25 -69 88 87 79 -70 74 -26 59

Sample Output 1

5924
2548
148
98887

Note

In the second test case, for the subsequence [26,43,41,34,13][-26,43,-41,34,13], when q=5q=5, s=2s=2, t=5t=5, i=1qbi+i=stbi=23+49=72\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i = 23 + 49 = 72.

In the third test case, there is only one non-empty consecutive subsequence [74][74]. When q=1q=1, s=1s=1, t=1t=1, i=1qbi+i=stbi=148\sum\limits_{i=1}^{q}b_i + \sum\limits_{i=s}^{t}b_i = 148.