#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int SG[MAXN][3];
int n, x, y, z;
int P, cnt;
long long A[MAXN];
void findP() {
  int t[4];
  for (int i = 1; i <= 1000; ++i) {
    for (int j = 0; j < 3; ++j) {
      memset(t, 0, sizeof t);
      t[SG[max(0, i - x)][0]] = 1;
      if (j != 1) t[SG[max(0, i - y)][1]] = 1;
      if (j != 2) t[SG[max(0, i - z)][2]] = 1;
      int val;
      for (int k = 0; k < 4; ++k) {
        if (!t[k]) {
          val = k;
          break;
        }
      }
      SG[i][j] = val;
    }
  }
  for (P = 1;; ++P) {
    int ok = 1;
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < P; ++j) {
        for (int k = 0; k <= 10; ++k) {
          if (SG[1000 - j - k * P][i] != SG[1000 - j - (k + 1) * P][i]) {
            ok = 0;
            break;
          }
        }
      }
    }
    if (ok) break;
  }
  for (int i = 0;; ++i) {
    int ok = 1;
    for (int j = 1; j <= 3; ++j) {
      for (int k = 1; k <= P; ++k) {
        for (int ii = 0; ii < 3; ++ii) {
          if (SG[i + (j - 1) * P + k][ii] != SG[i + j * P + k][ii]) {
            ok = 0;
            break;
          }
        }
      }
    }
    if (ok) {
      cnt = i;
      break;
    }
  }
}
int getSG(long long x, int op) {
  if (x <= 1000) {
    return SG[x][op];
  } else {
    x -= cnt;
    x %= P;
    return SG[cnt + x + P][op];
  }
}
inline bool check(int x, int y) { return (x ^ y) == 0 ? 1 : 0; }
void solve() {
  cin >> n >> x >> y >> z;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  findP();
  int res = 0;
  int xsum = 0;
  for (int i = 1; i <= n; ++i) xsum ^= getSG(A[i], 0);
  for (int i = 1; i <= n; ++i) {
    int t = getSG(A[i], 0);
    xsum ^= t;
    int f1 = getSG(max(0ll, A[i] - x), 0);
    int f2 = getSG(max(0ll, A[i] - y), 1);
    int f3 = getSG(max(0ll, A[i] - z), 2);
    if (check(f1, xsum)) ++res;
    if (check(f2, xsum)) ++res;
    if (check(f3, xsum)) ++res;
    xsum ^= t;
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int cases;
  cin >> cases;
  while (cases--) {
    solve();
  }
  return 0;
}
