#include <bits/stdc++.h>
using namespace std;
long long a[300005];
int grundy[505][3], x, y, z;
int get_grundy(int i, int last) {
  if (~grundy[i][last]) return grundy[i][last];
  bool seen[4] = {0};
  seen[get_grundy(max(0, i - x), 0)] = 1;
  if (last != 1) seen[get_grundy(max(0, i - y), 1)] = 1;
  if (last != 2) seen[get_grundy(max(0, i - z), 2)] = 1;
  int g = 0;
  while (seen[g]) ++g;
  return grundy[i][last] = g;
}
int magic[6][6][6][64][3], periods[6][6][6];
int get_grundy_cached(long long k, int lst) {
  int p = periods[x][y][z];
  return magic[x][y][z][(k < p ? 0 : p) + k % p][lst];
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (x = 1; x <= 5; ++x)
    for (y = 1; y <= 5; ++y)
      for (z = 1; z <= 5; ++z) {
        memset(grundy, -1, sizeof(grundy));
        fill_n(grundy[0], 3, 0);
        for (int period = 1; period < 32; ++period) {
          int ok = 1;
          for (int i = 2 * period; i <= 80; ++i) {
            ok &= get_grundy(i, 0) == get_grundy(i - period, 0) &&
                  get_grundy(i, 1) == get_grundy(i - period, 1) &&
                  get_grundy(i, 2) == get_grundy(i - period, 2);
          }
          if (ok) {
            periods[x][y][z] = period;
            break;
          }
        }
        memcpy(magic[x][y][z], grundy, 2 * periods[x][y][z] * sizeof grundy[0]);
      }
  int T, n;
  for (cin >> T; T--;) {
    int xr = 0, ans = 0;
    cin >> n >> x >> y >> z;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      xr ^= get_grundy_cached(a[i], 0);
    }
    for (int i = 1; i <= n; ++i) {
      int now = xr ^ get_grundy_cached(a[i], 0);
      ans += (now == get_grundy_cached(max(a[i] - x, 0ll), 0)) +
             (now == get_grundy_cached(max(a[i] - y, 0ll), 1)) +
             (now == get_grundy_cached(max(a[i] - z, 0ll), 2));
    }
    cout << ans << '\n';
  }
}
