#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int grundy[3][N];
int p[3], T[3];
int x[3];
void setT(int kk) {
  for (int pos = 0; pos < N; ++pos) {
    for (int t = 1; t < 20; ++t) {
      bool ok = true;
      for (int i = pos; i + t < N; ++i)
        if (grundy[kk][i] != grundy[kk][i + t]) {
          ok = false;
          break;
        }
      if (ok) {
        p[kk] = pos;
        T[kk] = t;
        return;
      }
    }
  }
}
int get_grundy(long long v, int prev = 2) {
  if (v < 0) v = 0;
  if (v > p[prev]) v = p[prev] + (v - p[prev]) % T[prev];
  return grundy[prev][v];
}
int mex(vector<int> v) {
  set<int> s = set<int>((v).begin(), (v).end());
  int res = 0;
  while (s.count(res)) ++res;
  return res;
}
void solve() {
  int n;
  scanf("%d", &n);
  for (int t = 0; t < 3; ++t) scanf("%d", &x[2 - t]);
  for (int t = 0; t < 3; ++t) grundy[0][t] = 0;
  for (int i = 1; i < N; ++i) {
    vector<int> tmp;
    for (int t = 0; t < 3; ++t) {
      tmp.clear();
      for (int tt = 0; tt < 3; ++tt) {
        if (t < 2 && t == tt) continue;
        tmp.push_back(grundy[tt][max(0, i - x[tt])]);
      }
      grundy[t][i] = mex(tmp);
    }
  }
  for (int t = 0; t < 3; ++t) setT(t);
  vector<long long> a(n);
  int xr = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    xr ^= get_grundy(a[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int t = 0; t < 3; ++t)
      if ((xr ^ get_grundy(a[i]) ^ get_grundy(a[i] - x[t], t)) == 0) ans++;
  }
  printf("%d\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
