#include <bits/stdc++.h>
using namespace std;
const int maxn = 300100;
inline int Mex(int a) { return a == 0; }
inline int Mex(int a, int b) {
  int ans = 0;
  while (ans == a || ans == b) ans++;
  return ans;
}
inline int Mex(int a, int b, int c) {
  int ans = 0;
  while (ans == a || ans == b || ans == c) ans++;
  return ans;
}
int n, x, y, z;
long long a[maxn];
struct State {
  int sg[6][3];
  inline void extend() {
    for (int i = 0; i < 5; i++)
      for (int j = 0; j < 3; j++) sg[i][j] = sg[i + 1][j];
    sg[5][0] = Mex(sg[5 - x][0], sg[5 - y][1], sg[5 - z][2]);
    sg[5][1] = Mex(sg[5 - x][0], sg[5 - z][2]);
    sg[5][2] = Mex(sg[5 - x][0], sg[5 - y][1]);
  }
  inline void init0() {
    for (int i = 0; i <= 5; i++)
      for (int j = 0; j < 3; j++) sg[i][j] = 0;
  }
  bool operator<(const State &T) const {
    for (int i = 1; i <= 5; i++)
      for (int j = 0; j < 3; j++)
        if (sg[i][j] != T.sg[i][j]) return sg[i][j] < T.sg[i][j];
    return 0;
  }
} st[1000];
map<State, int> id;
int Rpos, Lpos, sgv;
inline int query(long long a, int lstopt) {
  if (a >= Lpos) a = (a - Lpos) % (Rpos - Lpos + 1) + Lpos;
  return st[a].sg[5][lstopt];
}
inline void solve() {
  scanf("%d%d%d%d", &n, &x, &y, &z);
  Lpos = Rpos = 0;
  id.clear();
  st[0].init0();
  id[st[0]] = 0;
  for (int i = 1;; i++) {
    st[i] = st[i - 1];
    st[i].extend();
    if (id.count(st[i])) {
      Rpos = i - 1;
      Lpos = id[st[i]];
      break;
    } else
      id[st[i]] = i;
  }
  sgv = 0;
  for (int i = 1; i <= n; i++) scanf("%lld", a + i), sgv ^= query(a[i], 0);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if ((sgv ^ query(a[i], 0) ^ query(max(a[i] - x, 0ll), 0)) == 0) ans++;
    if ((sgv ^ query(a[i], 0) ^ query(max(a[i] - y, 0ll), 1)) == 0) ans++;
    if ((sgv ^ query(a[i], 0) ^ query(max(a[i] - z, 0ll), 2)) == 0) ans++;
  }
  printf("%d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
