#include <bits/stdc++.h>
using namespace std;
const long long sz = 3e5 + 10;
long long ara[sz], n, x, y, z;
int mex[(long long)2e7][3];
map<vector<int>, int> vis;
map<vector<int>, int>::iterator it;
long long calc_mex(const set<int> &lst) {
  long long m = 0;
  for (auto &v : lst) {
    if (m == v)
      m++;
    else
      break;
  }
  return m;
}
pair<long long, long long> cycle_grundy() {
  vis.clear();
  vector<int> num;
  mex[0][0] = mex[0][1] = mex[0][2] = 0;
  for (long long i = 1;; i++) {
    long long prv0 = max(0LL, i - x), prv1 = max(0LL, i - y),
              prv2 = max(0LL, i - z);
    mex[i][0] = calc_mex({mex[prv0][0], mex[prv1][1], mex[prv2][2]});
    mex[i][1] = calc_mex({mex[prv0][0], mex[prv2][2]});
    mex[i][2] = calc_mex({mex[prv0][0], mex[prv1][1]});
    num.push_back(mex[i][0]), num.push_back(mex[i][1]),
        num.push_back(mex[i][2]);
    if (i == 5) vis[num] = i;
    if (i > 5) {
      num.erase(num.begin()), num.erase(num.begin()), num.erase(num.begin());
      it = vis.find(num);
      if (it != vis.end()) {
        long long id = it->second;
        long long cycle_len = i - id, cycle_start = id;
        return make_pair(cycle_start, cycle_len);
      }
      vis[num] = i;
    }
  }
}
long long grundy(long long n, long long last, pair<long long, long long> &cyc) {
  if (n <= 0) return 0;
  if (n < cyc.first) return mex[n][last];
  long long d = (n - cyc.first) % cyc.second;
  return mex[cyc.first + d][last];
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    scanf("%lld %lld %lld %lld", &n, &x, &y, &z);
    for (long long i = 1; i <= n; i++) scanf("%lld", &ara[i]);
    pair<long long, long long> cyc = cycle_grundy();
    long long xr = 0;
    for (long long i = 1; i <= n; i++) xr ^= grundy(ara[i], 0, cyc);
    if (xr == 0) {
      printf("0\n");
      continue;
    }
    long long ans = 0;
    for (long long i = 1; i <= n; i++) {
      xr ^= grundy(ara[i], 0, cyc);
      long long g = grundy(ara[i] - x, 0, cyc);
      if ((xr ^ g) == 0) ans++;
      g = grundy(ara[i] - y, 1, cyc);
      if ((xr ^ g) == 0) ans++;
      g = grundy(ara[i] - z, 2, cyc);
      if ((xr ^ g) == 0) ans++;
      xr ^= grundy(ara[i], 0, cyc);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
