#include <bits/stdc++.h>
using namespace std;
const int MaxN = 300001;
long long v[MaxN];
int a[3001][3];
int mex(int x, int y, int z) {
  int buf[5] = {0, 0, 0, 0, 0};
  buf[x] = 1;
  buf[y] = 1;
  buf[z] = 1;
  for (int i = 0; i < 4; ++i) {
    if (buf[i] == 0) {
      return i;
    }
  }
  return -1;
}
int max(int x, int y) {
  if (x > y) {
    return x;
  }
  return y;
}
int loop = 0;
void PrepareSg(int x, int y, int z) {
  a[0][0] = 0;
  a[0][1] = 0;
  a[0][2] = 0;
  loop = (x + y) * (y + z) * (x + z);
  for (int i = 1; i < loop + loop + loop; ++i) {
    int tx = max(i - x, 0);
    int ty = max(i - y, 0);
    int tz = max(i - z, 0);
    a[i][0] = mex(a[tx][0], a[ty][1], a[tz][2]);
    a[i][1] = mex(a[tx][0], 4, a[tz][2]);
    a[i][2] = mex(a[tx][0], a[ty][1], 4);
  }
}
int GetSg(long long v, int i) {
  if (v < 0) {
    return 0;
  }
  if (v < loop + loop + loop) {
    return a[v][i];
  }
  return a[v % (loop + loop) + loop][i];
}
void solve() {
  int n, x, y, z;
  scanf("%d %d %d %d", &n, &x, &y, &z);
  PrepareSg(x, y, z);
  int sg = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &v[i]);
    sg ^= GetSg(v[i], 0);
  }
  if (sg == 0) {
    printf("0\n");
    return;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int tmp = sg ^ GetSg(v[i], 0);
    if ((tmp ^ GetSg(v[i] - x, 0)) == 0) {
      ans += 1;
    }
    if ((tmp ^ GetSg(v[i] - y, 1)) == 0) {
      ans += 1;
    }
    if ((tmp ^ GetSg(v[i] - z, 2)) == 0) {
      ans += 1;
    }
  }
  printf("%d\n", ans);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    solve();
  }
}
