#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5, MAXM = 3e2 + 5;
const int BEG = 30;
int n, x, y, z;
long long A[MAXN];
int f[MAXM][3], lop;
int pre[MAXN], suf[MAXN], S[MAXN];
inline int mex(vector<int>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int ret = (int)v.size();
  for (int i = 0; i < (int)v.size(); ++i)
    if (v[i] != i) return i;
  return ret;
}
int SG(const long long& k, const int& c) {
  if (k <= 0) return 0;
  if (k > BEG && lop != -1) return f[(k - BEG) % lop + BEG][c];
  if (f[k][c] != -1) return f[k][c];
  vector<int> vis;
  vis.clear(), vis.push_back(SG(k - x, 0));
  if (c != 1) vis.push_back(SG(k - y, 1));
  if (c != 2) vis.push_back(SG(k - z, 2));
  return f[k][c] = mex(vis);
}
inline bool check() {
  for (int i = BEG + lop; i + lop <= 60; i += lop)
    for (int j = 0; j < lop; ++j)
      for (int c = 0; c < 3; ++c)
        if (f[i + j][c] != f[BEG + j][c]) return false;
  return true;
}
int main() {
  int Ti;
  scanf("%d", &Ti);
  while (Ti--) {
    memset(f, -1, sizeof f);
    scanf("%d%d%d%d", &n, &x, &y, &z);
    for (int i = 1; i <= n; ++i) scanf("%lld", A + i);
    lop = -1;
    for (int k = 1; k <= 60; ++k)
      for (int c = 0; c < 3; ++c) SG(k, c);
    for (lop = 1; lop; ++lop)
      if (check()) break;
    for (int i = 1; i <= n; ++i) S[i] = SG(A[i], 0);
    pre[0] = suf[n + 1] = 0;
    for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] ^ S[i];
    for (int i = n; i >= 1; --i) suf[i] = suf[i + 1] ^ S[i];
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
      int s = pre[i - 1] ^ suf[i + 1];
      if ((s ^ SG(A[i] - x, 0)) == 0) ++ans;
      if ((s ^ SG(A[i] - y, 1)) == 0) ++ans;
      if ((s ^ SG(A[i] - z, 2)) == 0) ++ans;
    }
    printf("%d\n", ans);
  }
  return 0;
}
