# Attack on Red Kingdom

The Red Kingdom is attacked by the White King and the Black King!

The Kingdom is guarded by $n$ castles, the $i$-th castle is defended by $a_i$ soldiers. To conquer the Red Kingdom, the Kings have to eliminate all the defenders.

Each day the White King launches an attack on one of the castles. Then, at night, the forces of the Black King attack a castle (possibly the same one). Then the White King attacks a castle, then the Black King, and so on. The first attack is performed by the White King.

Each attack must target a castle with at least one alive defender in it. There are three types of attacks:

• mixed attack decreases the number of defenders in the targeted castle by $x$ (or sets it to $0$ if there are already less than $x$ defenders);
• an infantry attack decreases the number of defenders in the targeted castle by $y$ (or sets it to $0$ if there are already less than $y$ defenders);
• cavalry attack decreases the number of defenders in the targeted castle by $z$ (or sets it to $0$ if there are already less than $z$ defenders).

The mixed attack can be launched at any valid target (at any castle with at least one soldier). However, the infantry attack cannot be launched if the previous attack on the targeted castle had the same type, no matter when and by whom it was launched. The same applies to the cavalry attack. A castle that was not attacked at all can be targeted by any type of attack.

The King who launches the last attack will be glorified as the conqueror of the Red Kingdom, so both Kings want to launch the last attack (and they are wise enough to find a strategy that allows them to do it no matter what are the actions of their opponent, if such strategy exists). The White King is leading his first attack, and you are responsible for planning it. Can you calculate the number of possible options for the first attack that allow the White King to launch the last attack? Each option for the first attack is represented by the targeted castle and the type of attack, and two options are different if the targeted castles or the types of attack are different.

Input

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

Then, the test cases follow. Each test case is represented by two lines.

The first line contains four integers $n$, $x$, $y$ and $z$ ($1 \le n \le 3 \cdot 10^5$, $1 \le x, y, z \le 5$).

The second line contains $n$ integers $a_1$, $a_2$, …, $a_n$ ($1 \le a_i \le 10^{18}$).

It is guaranteed that the sum of values of $n$ over all test cases in the input does not exceed $3 \cdot 10^5$.

Output

For each test case, print the answer to it: the number of possible options for the first attack of the White King (or $0$, if the Black King can launch the last attack no matter how the White King acts).

Examples

input

3
2 1 3 4
7 6
1 1 2 3
1
1 1 2 2
3


output

2
3
0


input

10
6 5 4 5
2 3 2 3 1 3
1 5 2 3
10
4 4 2 3
8 10 8 5
2 2 1 4
8 5
3 5 3 5
9 2 10
4 5 5 5
2 10 4 2
2 3 1 4
1 10
3 1 5 3
9 8 7
2 5 4 5
8 8
3 5 1 4
5 5 10


output

0
2
1
2
5
12
5
0
0
2

Solution:

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int N=301000;
int _,n,p,wt,pp;
int dp;
ll a[N];
void solve() {
for (int i=1;i<=500;i++) {
int z=0;
for (int j=0;j<3;j++) {
set<int> sg;
rep(k,0,3) if (j==0||k==0||j!=k) {
if (i-p[k]>=0) sg.insert(dp[i-p[k]][k]);
else sg.insert(0);
}
dp[i][j]=0;
while (sg.count(dp[i][j])) dp[i][j]+=1;
z=z*4+dp[i][j];
//printf("%d ",dp[i][j]);
}
wt[i]=z;
}
for (int prd=1;prd<=30;prd++) {
bool sm=1;
for (int j=50;j<500;j++) if (j+prd<=500&&wt[j]!=wt[j+prd]) sm=0;
if (sm) {
//			printf("%d %d %d %d\n",p,p,p,prd);
pp=prd;
return;
}
}
assert(0);
}

int getsg(ll n,int way) {
int st=0;
if (n<=0) return 0;
if (n>500) {
n-=(n-500)/pp*pp;
while (n>500) n-=pp;
}
return dp[n][way];
}

int main() {
/*for (p=1;p<=5;p++) for (p=1;p<=5;p++) for (p=1;p<=5;p++)
solve();*/
for (scanf("%d",&_);_;_--) {
scanf("%d",&n);
rep(i,0,3) scanf("%d",p+i);
solve();
int s=0;
rep(i,0,n) {
scanf("%lld",a+i);
s^=getsg(a[i],0);
}
int ans=0;
rep(i,0,n) rep(j,0,3) if ((s^getsg(a[i],0)^getsg(a[i]-p[j],j))==0) ans+=1;
printf("%d\n",ans);
}
}