#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b ? a : b); }
int t;
int n, x, y, z;
int dp[600001][3], val[600001];
long long a[600001];
int len, cycle;
void get(int p1, int p2) {
  int ext[6];
  for (int i = 0; i <= 5; i++) {
    ext[i] = 0;
  }
  ext[dp[max(p1 - x, 0)][0]] = 1;
  if (p2 != 1) {
    ext[dp[max(p1 - y, 0)][1]] = 1;
  }
  if (p2 != 2) {
    ext[dp[max(p1 - z, 0)][2]] = 1;
  }
  for (int i = 0; i <= 5; i++)
    if (!ext[i]) {
      dp[p1][p2] = i;
      return;
    }
}
void precompute() {
  len = 0;
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  for (int i = 1; i <= 600001; i++) {
    for (int j = 0; j <= 2; j++) get(i, j);
    val[i] = dp[i][0] * 20000 + dp[i][1] * 200 + dp[i][2];
    if (i >= 6) {
      for (int last = 0; last <= i - 6; last++) {
        int ok = 1;
        for (int pos = 0; pos <= 4; pos++) {
          if (val[pos + last] != val[i - 4 + pos]) {
            ok = 0;
            break;
          }
        }
        if (ok) {
          len = i;
          cycle = i - 4 - last;
          break;
        }
      }
    }
    if (len) break;
  }
}
int nim(long long val, int p1) {
  if (val <= len) {
    return dp[val][p1];
  }
  long long realValue = (val - len) % cycle + (len - cycle);
  return dp[realValue][p1];
}
void solve() {
  scanf("%d%d%d%d", &n, &x, &y, &z);
  precompute();
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  int totalNim = 0;
  for (int i = 1; i <= n; i++) totalNim ^= nim(a[i], 0);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int partialNim = totalNim ^ nim(a[i], 0);
    if ((partialNim ^ nim(max(a[i] - x, 0), 0)) == 0) res++;
    if ((partialNim ^ nim(max(a[i] - y, 0), 1)) == 0) res++;
    if ((partialNim ^ nim(max(a[i] - z, 0), 2)) == 0) res++;
  }
  printf("%d\n", res);
}
int main() {
  scanf("%d", &t);
  if (false) {
    int maxlen = 0;
    for (int i = 1; i <= 5; i++)
      for (int j = 1; j <= 5; j++)
        for (int k = 1; k <= 5; k++) {
          x = i;
          y = j;
          z = k;
          precompute();
          if (len > maxlen) maxlen = len;
        }
    printf("%d\n", maxlen);
  }
  while (t--) solve();
}
