#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX;
const long long INF = LLONG_MAX;
template <typename T>
inline T read() {
  T sum = 0, fl = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
  return sum * fl;
}
const int maxn = 3e5 + 5;
int N, X, Y, Z;
long long A[maxn];
int len;
int SG[100][4];
int search(long long lef, int use) {
  if (len && lef > 30) return SG[(lef - 30) % len + 30][use];
  if (SG[lef][use] != -1) return SG[lef][use];
  if (lef == 0) return SG[lef][use] = 0;
  int sg1 = search(max(0ll, lef - X), 0);
  int sg2 = (use == 1) ? -1 : search(max(0ll, lef - Y), 1);
  int sg3 = (use == 2) ? -1 : search(max(0ll, lef - Z), 2);
  if (sg1 != 0 && sg2 != 0 && sg3 != 0)
    SG[lef][use] = 0;
  else if (sg1 != 1 && sg2 != 1 && sg3 != 1)
    SG[lef][use] = 1;
  else if (sg1 != 2 && sg2 != 2 && sg3 != 2)
    SG[lef][use] = 2;
  else
    SG[lef][use] = 3;
  return SG[lef][use];
}
inline void init() {
  memset(SG, -1, sizeof SG);
  len = 0;
  for (int i = 1; i <= 60; ++i) search(i, 0), search(i, 1), search(i, 2);
  for (len = 1; len <= 15; ++len) {
    for (int i = 30 + len; i + len <= 60; i += len) {
      for (int j = 0; j < len; ++j)
        for (int k = 0; k <= 2; ++k)
          if (SG[i + j][k] != SG[30 + j][k]) goto loop;
    }
    break;
  loop:;
  }
}
int suf[maxn], pre[maxn], sg[maxn];
inline void solve() {
  init();
  suf[N + 1] = 0;
  for (int i = 1; i <= N; ++i) sg[i] = search(A[i], 0);
  for (int i = 1; i <= N; ++i) pre[i] = pre[i - 1] ^ sg[i];
  for (int i = N; i >= 1; --i) suf[i] = suf[i + 1] ^ sg[i];
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    int val = pre[i - 1] ^ suf[i + 1];
    if ((search(max(0ll, A[i] - X), 0) ^ val) <= 0) ++ans;
    if ((search(max(0ll, A[i] - Y), 1) ^ val) <= 0) ++ans;
    if ((search(max(0ll, A[i] - Z), 2) ^ val) <= 0) ++ans;
  }
  printf("%d\n", ans);
}
inline void input() {
  N = read<int>();
  X = read<int>(), Y = read<int>(), Z = read<int>();
  for (int i = 1; i <= N; ++i) A[i] = read<long long>();
}
int main() {
  int T = read<int>();
  while (T--) {
    input();
    solve();
  }
  return 0;
}
