#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  register T sum = 0;
  register char cc = getchar();
  int sym = 1;
  while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar();
  if (cc == '-') sym = -1, cc = getchar();
  sum = sum * 10 + cc - '0';
  cc = getchar();
  while (cc >= '0' && cc <= '9') sum = sum * 10 + cc - '0', cc = getchar();
  return sym * sum;
}
template <typename T>
inline T read(T& a) {
  a = read<T>();
  return a;
}
template <typename T, typename... Others>
inline void read(T& a, Others&... b) {
  a = read(a);
  read(b...);
}
int T, n, x, y, z, pre, len;
long long a[300010];
vector<vector<int>> sg;
map<vector<vector<int>>, int> mp;
int mex(int a, int b, int c = 4) {
  static int vis[5];
  memset(vis, 0, sizeof(vis));
  vis[a] = vis[b] = vis[c] = true;
  for (int i = 0;; i++)
    if (!vis[i]) return i;
}
void Add() {
  vector<int> t(3, 0);
  int tot = sg.size();
  t[0] = mex(sg[max(tot - x, 0)][0], sg[max(tot - y, 0)][1],
             sg[max(tot - z, 0)][2]);
  t[1] = mex(sg[max(tot - x, 0)][0], sg[max(tot - z, 0)][2]);
  t[2] = mex(sg[max(tot - x, 0)][0], sg[max(tot - y, 0)][1]);
  sg.push_back(t);
}
int Get(long long x) { return x < pre ? x : (x - pre) % len + pre; }
int main() {
  read(T);
  for (int cas = 1; cas <= T; cas++) {
    read(n, x, y, z);
    for (int i = 1; i <= n; i++) read(a[i]);
    sg.clear();
    mp.clear();
    sg.push_back({0, 0, 0});
    for (int i = 1; i < 5; i++) Add();
    while (true) {
      vector<vector<int>> t(sg.end() - 5, sg.end());
      if (mp.count(t)) {
        pre = mp[t];
        len = sg.size() - 5 - pre;
        break;
      }
      mp[t] = sg.size() - 5;
      Add();
    }
    int sum = 0, s[4] = {0, 0, 0, 0};
    for (int i = 1; i <= n; i++) {
      long long v0 = max(a[i] - x, 0ll);
      long long v1 = max(a[i] - y, 0ll);
      long long v2 = max(a[i] - z, 0ll);
      int nw = sg[Get(a[i])][0];
      sum ^= nw;
      s[nw ^ sg[Get(v0)][0]] += 1;
      s[nw ^ sg[Get(v1)][1]] += 1;
      s[nw ^ sg[Get(v2)][2]] += 1;
    }
    printf("%d\n", s[sum]);
  }
  return 0;
}
