#include <bits/stdc++.h>
static char ibuf[1 << 20 | 1], *p1 = ibuf, *p2 = ibuf;
struct IO {
  char gc() {
    return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20 | 1, stdin),
                        p1 == p2)
               ? EOF
               : *p1++;
  }
  template <typename T>
  IO operator>>(T &n) {
    n = 0;
    char c = gc();
    while (c < '0') c = gc();
    while (c >= '0') n = n * 10 + (c & 15), c = gc();
    return *this;
  }
} cin;
using ll = long long;
int len, f[3][1303];
ll a[300003];
inline ll v(ll x) { return std::max(x, 0ll); }
inline int mex(int x, int y, int z = 3) {
  std::bitset<5> v;
  v.set(x), v.set(y), v.set(z);
  for (int i = 0; i < 3; ++i)
    if (!v[i]) return i;
  return 3;
}
inline int calc(int x, ll y) {
  if (y <= 1296) return f[x][y];
  return f[x][y % len + 35 * len];
}
int main() {
  int T, N, x, y, z;
  for (cin >> T; T; --T) {
    len = 1;
    cin >> N >> x >> y >> z;
    for (int i = 1; i <= 1296; ++i) {
      f[0][i] = mex(f[0][v(i - x)], f[1][v(i - y)], f[2][v(i - z)]);
      f[1][i] = mex(f[0][v(i - x)], f[2][v(i - z)]);
      f[2][i] = mex(f[0][v(i - x)], f[1][v(i - y)]);
    }
    for (int i = 1, v, mx = 0; i <= 36; ++i) {
      v = 0;
      for (int j = i + 1; j <= 1296; ++j)
        for (int k = 0; k < 3; ++k) v += f[k][j] == f[k][j - i];
      if (v > mx) mx = v, len = i;
    }
    int sg = 0, ans = 0;
    for (int i = 1; i <= N; ++i) {
      cin >> a[i];
      sg ^= calc(0, a[i]);
    }
    for (int i = 1, t; i <= N; ++i) {
      t = sg ^ calc(0, a[i]);
      ans += t == calc(0, v(a[i] - x));
      ans += t == calc(1, v(a[i] - y));
      ans += t == calc(2, v(a[i] - z));
    }
    std::cout << ans << '\n';
  }
  return 0;
}
