#include <bits/stdc++.h>
using namespace std;
map<pair<long long, int>, int> mp;
int grundy(long long n, int x, int y, int z, int p) {
  if (n == 0) return 0;
  int key = x * 10 + y * 100 + z * 1000 + p;
  if (mp.find(make_pair(n, key)) != mp.end()) return mp[make_pair(n, key)];
  int g0 = grundy(max(0LL, n - x), x, y, z, 0);
  int g1 = (p == 1) ? 100 : grundy(max(0LL, n - y), x, y, z, 1);
  int g2 = (p == 2) ? 100 : grundy(max(0LL, n - z), x, y, z, 2);
  int res = 0;
  while (res == g0 || res == g1 || res == g2) res++;
  mp[make_pair(n, key)] = res;
  return res;
}
template <typename T>
vector<int> kmp(T &str) {
  int n = str.size();
  vector<int> res(n + 1, -1);
  for (int i = 0, j = -1; i < n; res[++i] = ++j) {
    while (j >= 0 && str[i] != str[j]) j = res[j];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int m = 100;
  vector<vector<vector<vector<int>>>> a0(
      6,
      vector<vector<vector<int>>>(6, vector<vector<int>>(6, vector<int>(m))));
  vector<vector<vector<vector<int>>>> a1(
      6,
      vector<vector<vector<int>>>(6, vector<vector<int>>(6, vector<int>(m))));
  vector<vector<vector<vector<int>>>> a2(
      6,
      vector<vector<vector<int>>>(6, vector<vector<int>>(6, vector<int>(m))));
  vector<vector<vector<int>>> c0(6, vector<vector<int>>(6, vector<int>(6)));
  vector<vector<vector<int>>> c1(6, vector<vector<int>>(6, vector<int>(6)));
  vector<vector<vector<int>>> c2(6, vector<vector<int>>(6, vector<int>(6)));
  for (int x = 1; x <= 5; x++) {
    for (int y = 1; y <= 5; y++) {
      for (int z = 1; z <= 5; z++) {
        for (int i = 0; i < m; i++) {
          a0[x][y][z][i] = grundy(i, x, y, z, 0);
          a1[x][y][z][i] = grundy(i, x, y, z, 1);
          a2[x][y][z][i] = grundy(i, x, y, z, 2);
        }
        vector<int> b0(m / 2), b1(m / 2), b2(m / 2);
        for (int i = m / 2; i < m; i++) {
          b0[i - m / 2] = a0[x][y][z][i];
          b1[i - m / 2] = a1[x][y][z][i];
          b2[i - m / 2] = a2[x][y][z][i];
        }
        vector<int> k0 = kmp(b0), k1 = kmp(b1), k2 = kmp(b2);
        c0[x][y][z] = m / 2 - k0[m / 2];
        c1[x][y][z] = m / 2 - k1[m / 2];
        c2[x][y][z] = m / 2 - k2[m / 2];
      }
    }
  }
  function<int(long long, int, int, int, int)> gr = [&](long long n, int x,
                                                        int y, int z, int p) {
    if (n < m) {
      if (p == 0) return a0[x][y][z][n];
      if (p == 1) return a1[x][y][z][n];
      if (p == 2) return a2[x][y][z][n];
    }
    long long dif = n - m;
    if (p == 0) {
      dif %= c0[x][y][z];
      int v = m + dif - c0[x][y][z];
      return a0[x][y][z][v];
    } else if (p == 1) {
      dif %= c1[x][y][z];
      int v = m + dif - c1[x][y][z];
      return a1[x][y][z][v];
    } else {
      dif %= c2[x][y][z];
      int v = m + dif - c2[x][y][z];
      return a2[x][y][z][v];
    }
    return 0;
  };
  int tt;
  cin >> tt;
  while (tt--) {
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> gs(n);
    int xo = 0;
    for (int i = 0; i < n; i++) {
      gs[i] = gr(a[i], x, y, z, 0);
      xo ^= gs[i];
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
      xo ^= gs[i];
      int g0 = gr(max(0LL, a[i] - x), x, y, z, 0);
      if (g0 == xo) res++;
      int g1 = gr(max(0LL, a[i] - y), x, y, z, 1);
      if (g1 == xo) res++;
      int g2 = gr(max(0LL, a[i] - z), x, y, z, 2);
      if (g2 == xo) res++;
      xo ^= gs[i];
    }
    cout << res << "\n";
  }
  return 0;
}
