#ARC147F. [ARC147F] Again ABC String

[ARC147F] Again ABC String

Score : 11001100 points

Problem Statement

Consider strings of length NN consisting of A, B, and C. Among them, find the number of strings that satisfy the following condition, modulo 22:

  • Let SiS_i be the string formed by the first ii characters of SS. Also let AiA_i, BiB_i, and CiC_i be the numbers of A's, B's, and C's in SiS_i, respectively. For all ii such that 1iN1 \le i \le N, the following holds:- AiBiXA_i-B_i \le X
    • BiCiYB_i-C_i \le Y
    • CiAiZC_i-A_i \le Z
  • AiBiXA_i-B_i \le X
  • BiCiYB_i-C_i \le Y
  • CiAiZC_i-A_i \le Z

You have TT test cases to solve.

Constraints

  • 1T101 \le T \le 10
  • 1N1091 \le N \le 10^9
  • 0X,Y,Z1090 \le X,Y,Z \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

TT

case1\mathrm{case}_1

case2\mathrm{case}_2

\vdots

caseT\mathrm{case}_T

Each case is in the following format:

NN XX YY ZZ

Output

For each case, print the answer.

1
3 2 1 0
0

88 strings satisfy the condition: AAB,AAC,ABA,ABC,ACA,ACB,BAA,BAC. Therefore the answer is 00.

10
1 22 9 92
14 7 74 39
23 50 8 6
93 40 9 60
68 8 47 64
11 68 18 24
3 26 54 8
46 17 90 86
86 76 45 55
80 68 79 62
1
0
0
0
1
1
1
0
1
0