#P1984C2. Magnitude (Hard Version)

    ID: 9351 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>combinatoricsdpgreedymath*1700

Magnitude (Hard Version)

No submission language available for this problem.

Description

The two versions of the problem are different. You may want to read both versions. You can make hacks only if both versions are solved.

You are given an array aa of length nn. Start with c=0c = 0. Then, for each ii from 11 to nn (in increasing order) do exactly one of the following:

  • Option 11: set cc to c+aic + a_i.
  • Option 22: set cc to c+ai|c + a_i|, where x|x| is the absolute value of xx.

Let the maximum final value of cc after the procedure described above be equal to kk. Find the number of unique procedures that result in c=kc = k. Two procedures are different if at any index ii, one procedure chose option 11 and another chose option 22, even if the value of cc is equal for both procedures after that turn.

Since the answer may be large, output it modulo 998244353998\,244\,353.

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (2n21052 \leq n \leq 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (109ai109-10^9 \leq a_i \leq 10^9).

The sum of nn over all test cases does not exceed 31053 \cdot 10^5.

For each test case, output a single integer — the number of unique procedures that result in c=kc = k, modulo 998244353998\,244\,353.

Input

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (2n21052 \leq n \leq 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (109ai109-10^9 \leq a_i \leq 10^9).

The sum of nn over all test cases does not exceed 31053 \cdot 10^5.

Output

For each test case, output a single integer — the number of unique procedures that result in c=kc = k, modulo 998244353998\,244\,353.

Sample Input 1

5
4
2 -5 3 -3
8
1 4 3 4 1 4 3 4
3
-1 -2 -3
4
-1000000000 1000000000 1000000000 1000000000
4
1 9 8 4

Sample Output 1

12
256
1
8
16

Note

In the first test case, it can be shown that our maximal final value of cc is 33. There are 1212 ways to achieve this because in order to get 33, we have to take absolute value at indices 22 or 44, or both, resulting in 33 ways. For the other two indices, it doesn't change the value whether we take absolute value or not, so we have 22=42 \cdot 2 = 4 ways for them. In total, we have 34=123 \cdot 4 = 12 ways.

In the second test case, taking the absolute value will never change anything, so we can either take absolute value or not, for every index. This gives us 28=2562^8 = 256 possible ways.