#include <bits/stdc++.h>
const int MAXN = 300100;
int Mex(bool *vis) {
  int ans = 0;
  while (vis[ans]) ++ans;
  return ans;
}
int sg[MAXN][3];
int Sg(int idx, int skip) {
  if (idx <= 0) return 0;
  bool vis[4];
  memset(vis, false, sizeof(vis));
  for (int i = 0; i < 3; ++i) {
    if (i & skip) continue;
    vis[sg[idx][i]] = true;
  }
  return Mex(vis);
}
std::pair<int, int> FindPeriod(int *val) {
  for (int i = 1;; ++i) {
    if (i > 30000) break;
    for (int j = 0; j < 3; ++j) sg[i][j] = Sg(i - val[j], j);
    if (i > 5) {
      for (int j = 5; j < i; ++j) {
        bool flag = true;
        for (int k = 0; flag && k < 5; ++k)
          for (int l = 0; l < 3; ++l)
            if (sg[i - k][l] != sg[j - k][l]) flag = false;
        if (flag) return {j, i - j};
      }
    }
  }
  return {0, 0};
}
long long a[MAXN];
int main() {
  int t, n, val[3];
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d%d%d", &n, val, val + 1, val + 2);
    std::pair<int, int> period = FindPeriod(val);
    if (!period.second) {
      puts("Error");
      return 0;
    }
    int xor_res = 0;
    for (int i = 0; i < n; ++i) {
      scanf("%lld", a + i);
      if (a[i] > period.first)
        a[i] = (a[i] - period.first) % period.second + period.first;
      int tmp = Sg(a[i], 0);
      xor_res ^= tmp;
    }
    if (xor_res) {
      int ans = 0;
      for (int i = 0; i < n; ++i) {
        int tmp = Sg(a[i], 0);
        for (int j = 0; j < 3; ++j)
          if (!(xor_res ^ tmp ^ sg[a[i]][j])) ++ans;
      }
      printf("%d\n", ans);
    } else
      puts("0");
  }
  return 0;
}
