#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
const int MAX = 300300;
int memo[100100][3];
bool visited[100100][3];
int grundy(int sz, int last) {
  sz = max(sz, 0);
  if (true) {
    visited[sz][last] = true;
    if (sz == 0)
      memo[sz][last] = 0;
    else {
      set<int> grundies;
      grundies.insert(grundy(sz - x, 0));
      if (last != 1) grundies.insert(grundy(sz - y, 1));
      if (last != 2) grundies.insert(grundy(sz - z, 2));
      int mine = 0;
      for (__typeof((grundies).begin()) v = (grundies).begin();
           v != (grundies).end(); v++) {
        if (*v != mine) {
          break;
        }
        mine++;
      }
      memo[sz][last] = mine;
    }
  }
  return memo[sz][last];
}
map<int, int> dic;
void T1(int& M, vector<vector<int> >& D) {
  D.clear();
  for (int i = 0; i < int(5); i++) {
    vector<int> tmp;
    for (int j = 0; j < int(3); j++) {
      tmp.push_back(M % 4);
      M /= 4;
    }
    D.push_back(tmp);
  }
}
void T2(int& M, vector<vector<int> >& D) {
  M = 0;
  int pot = 1;
  for (int i = 0; i < int(5); i++) {
    for (int j = 0; j < int(3); j++) {
      M += pot * D[i][j];
      pot *= 4;
    }
  }
}
int f(int M) {
  vector<vector<int> > D;
  T1(M, D);
  vector<int> d(3, -1);
  for (int i = 0; i < int(3); i++) {
    set<int> grundies;
    grundies.insert(D[5 - x][0]);
    if (i != 1) grundies.insert(D[5 - y][1]);
    if (i != 2) grundies.insert(D[5 - z][2]);
    int mine = 0;
    for (__typeof((grundies).begin()) v = (grundies).begin();
         v != (grundies).end(); v++) {
      if (*v != mine) {
        break;
      }
      mine++;
    }
    d[i] = mine;
  }
  for (int i = 0; i < int(4); i++) D[i] = D[i + 1];
  D[4] = d;
  T2(M, D);
  return M;
}
int f(int M, vector<vector<int> >& D) {
  T1(M, D);
  vector<int> d(3, -1);
  for (int i = 0; i < int(3); i++) {
    set<int> grundies;
    grundies.insert(D[5 - x][0]);
    if (i != 1) grundies.insert(D[5 - y][1]);
    if (i != 2) grundies.insert(D[5 - z][2]);
    int mine = 0;
    for (__typeof((grundies).begin()) v = (grundies).begin();
         v != (grundies).end(); v++) {
      if (*v != mine) {
        break;
      }
      mine++;
    }
    d[i] = mine;
  }
  for (int i = 0; i < int(4); i++) D[i] = D[i + 1];
  D[4] = d;
  T2(M, D);
  return M;
}
void init(int& M, vector<vector<int> >& D) {
  D.resize(5);
  for (int i = 0; i < int(5); i++) {
    D[i].resize(3);
    for (int j = 0; j < int(3); j++) {
      set<int> grundies;
      grundies.insert(i - x > 0 ? D[i - x][0] : 0);
      if (j != 1) grundies.insert(i - y > 0 ? D[i - y][0] : 0);
      if (j != 2) grundies.insert(i - z > 0 ? D[i - z][0] : 0);
      int mine = 0;
      for (__typeof((grundies).begin()) v = (grundies).begin();
           v != (grundies).end(); v++) {
        if (*v != mine) {
          break;
        }
        mine++;
      }
      D[i][j] = (i == 0 ? 0 : mine);
    }
  }
  T2(M, D);
}
int FS[3 * MAX][3];
pair<int, int> Floyd(int x0) {
  int t = f(x0), h = f(f(x0));
  while (t != h) {
    t = f(t);
    h = (f(f(h)));
  }
  int mu = 0;
  h = x0;
  while (t != h) {
    t = f(t);
    h = f(h);
    mu++;
  }
  int lambda = 1;
  h = f(t);
  while (t != h) {
    h = f(h);
    lambda++;
  }
  return make_pair(mu, lambda);
}
long long a[MAX];
int main() {
  int T;
  scanf("%d", &T);
  for (int t = 0; t < int(T); t++) {
    scanf("%d %d %d %d", &n, &x, &y, &z);
    int M;
    vector<vector<int> > D;
    init(M, D);
    pair<int, int> ml = Floyd(M);
    for (int i = 0; i < int(10 * (ml.first + ml.second) + 10); i++) {
      for (int j = 0; j < int(3); j++) {
        set<int> grundies;
        grundies.insert(i - x > 0 ? FS[i - x][0] : 0);
        if (j != 1) grundies.insert(i - y > 0 ? FS[i - y][1] : 0);
        if (j != 2) grundies.insert(i - z > 0 ? FS[i - z][2] : 0);
        int mine = 0;
        for (__typeof((grundies).begin()) v = (grundies).begin();
             v != (grundies).end(); v++) {
          if (*v != mine) {
            break;
          }
          mine++;
        }
        FS[i][j] = (i == 0 ? 0 : mine);
      }
    }
    for (int i = 0; i < int(n); i++) scanf("%lld", a + i);
    int totalGrundy = 0, tmpGrundy = 0;
    for (int i = 0; i < int(n); i++) {
      if (a[i] >= ml.first + 5 * ml.second) {
        a[i] -= ml.first;
        a[i] %= ml.second;
        a[i] += ml.first;
        a[i] += 5 * ml.second;
      }
      totalGrundy ^= FS[a[i]][0];
    }
    int ans = 0;
    if (totalGrundy == 0)
      printf("0\n");
    else {
      for (int i = 0; i < int(n); i++) {
        int tmp = totalGrundy;
        tmp ^= FS[a[i]][0];
        if ((tmp ^ (a[i] >= x ? FS[a[i] - x][0] : 0)) == 0) ans++;
        if ((tmp ^ (a[i] >= y ? FS[a[i] - y][1] : 0)) == 0) ans++;
        if ((tmp ^ (a[i] >= z ? FS[a[i] - z][2] : 0)) == 0) ans++;
      }
      printf("%d\n", ans);
    }
  }
}
