#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int pwr(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * 1LL * a) % mod;
    a = (a * 1LL * a) % mod;
    b >>= 1;
  }
  return ans;
}
const int N = 3e5 + 5;
int G[N], G1[N], G2[N];
int x, y, z;
int g(int n);
int g1(int n);
int g2(int n);
int g(int n) {
  if (n <= 0) return 0;
  if (G[n] != -1) return G[n];
  vector<int> v = {g(n - x), g1(n - y), g2(n - z)};
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  int ans = v.size();
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != i) {
      ans = i;
      break;
    }
  }
  return G[n] = ans;
}
int g1(int n) {
  if (n <= 0) return 0;
  if (G1[n] != -1) return G1[n];
  vector<int> v = {g(n - x), g2(n - z)};
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  int ans = v.size();
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != i) {
      ans = i;
      break;
    }
  }
  return G1[n] = ans;
}
int g2(int n) {
  if (n <= 0) return 0;
  if (G2[n] != -1) return G2[n];
  vector<int> v = {g(n - x), g1(n - y)};
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
  int ans = v.size();
  for (int i = 0; i < v.size(); i++) {
    if (v[i] != i) {
      ans = i;
      break;
    }
  }
  return G2[n] = ans;
}
string lol[6][6][6][3];
int idx[6][6][6][3], len[6][6][6][3];
void train(int x, int y, int z, int p) {
  bool found = 0;
  int id, le;
  for (int l = 1; l < 25; l++) {
    if (!found)
      for (int i = 0; i + l - 1 < 100; i++) {
        int c = 0;
        string ss = lol[x][y][z][p].substr(i, l);
        int c1 = 0;
        for (int j = i; j + l - 1 < 100; j += l) {
          string t = lol[x][y][z][p].substr(j, l);
          if (t == ss) {
            c++;
          }
          c1++;
        }
        if (c == c1 && c > 5) {
          found = 1;
          id = i;
          le = l;
          break;
        }
      }
  }
  if (!found) {
    cout << x << " " << y << " " << z << " " << p << '\n';
  }
  idx[x][y][z][p] = id;
  len[x][y][z][p] = le;
}
int fast_g(int x, int y, int z, int p, long long n) {
  if (n < 0) return 0;
  if (n < idx[x][y][z][p]) return lol[x][y][z][p][n] - '0';
  n = (n - idx[x][y][z][p]) % len[x][y][z][p] + idx[x][y][z][p];
  return lol[x][y][z][p][n] - '0';
}
long long a[N];
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int xx = 1; xx <= 5; xx++) {
    for (int yy = 1; yy <= 5; yy++) {
      for (int zz = 1; zz <= 5; zz++) {
        memset(G, -1, sizeof G);
        memset(G1, -1, sizeof G1);
        memset(G2, -1, sizeof G2);
        x = xx, y = yy, z = zz;
        for (int i = 0; i < 100; i++) {
          lol[x][y][z][0] += '0' + g(i);
        }
        for (int i = 0; i < 100; i++) {
          lol[x][y][z][1] += '0' + g1(i);
        }
        for (int i = 0; i < 100; i++) {
          lol[x][y][z][2] += '0' + g2(i);
        }
        for (int i = 0; i < 3; i++) {
          train(x, y, z, i);
        }
      }
    }
  }
  int t;
  cin >> t;
  while (t--) {
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    int gr = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      gr ^= fast_g(x, y, z, 0, a[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int gr1 = gr ^ fast_g(x, y, z, 0, a[i]);
      if (gr1 == fast_g(x, y, z, 0, a[i] - x)) ans++;
      if (gr1 == fast_g(x, y, z, 1, a[i] - y)) ans++;
      if (gr1 == fast_g(x, y, z, 2, a[i] - z)) ans++;
    }
    cout << ans << '\n';
  }
  return 0;
}
