#include <bits/stdc++.h>
inline int read() {
  char c = getchar();
  int x = 0, ft = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') ft = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * ft;
}
inline long long ll_read() {
  char c = getchar();
  long long x = 0, ft = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') ft = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  return x * ft;
}
const int N = 3e5 + 5;
int n, x, y, z, pos, cir, cnt;
long long a[N];
std::vector<std::array<int, 3>> q;
std::map<std::vector<std::array<int, 3>>, int> d;
inline int mex(std::vector<int> a) {
  std::sort(a.begin(), a.end());
  a.erase(std::unique(a.begin(), a.end()), a.end());
  if (a[0] > 0) return 0;
  for (int i = 1; i < (int)a.size(); ++i) {
    if (a[i] > a[i - 1] + 1) return a[i - 1] + 1;
  }
  return a.size();
}
inline std::vector<std::array<int, 3>> trans(
    std::vector<std::array<int, 3>> cur) {
  std::array<int, 3> f;
  f[0] = mex({cur[5 - x][0], cur[5 - y][1], cur[5 - z][2]});
  f[1] = mex({cur[5 - x][0], cur[5 - z][2]});
  f[2] = mex({cur[5 - x][0], cur[5 - y][1]});
  cur.erase(cur.begin());
  cur.push_back(f);
  return cur;
}
inline int get_sg(long long x, int op) {
  if (x < pos) return q[x][op];
  return q[(x - pos) % cir + pos][op];
}
int main() {
  int cases = read();
  while (cases--) {
    n = read();
    x = read();
    y = read();
    z = read();
    for (int i = 1; i <= n; ++i) a[i] = ll_read();
    std::vector<std::array<int, 3>> cur(5, {0, 0, 0});
    d.clear();
    q.clear();
    for (cnt = 0; !d.count(cur); cur = trans(cur)) {
      d[cur] = cnt;
      q.push_back(cur.back());
      ++cnt;
    }
    pos = d[cur];
    cir = cnt - pos;
    int sum = 0, ans = 0;
    for (int i = 1; i <= n; ++i) sum ^= get_sg(a[i], 0);
    for (int i = 1; i <= n; ++i) {
      sum ^= get_sg(a[i], 0);
      ans += (sum == get_sg(std::max(0ll, a[i] - x), 0));
      ans += (sum == get_sg(std::max(0ll, a[i] - y), 1));
      ans += (sum == get_sg(std::max(0ll, a[i] - z), 2));
      sum ^= get_sg(a[i], 0);
    }
    printf("%d\n", ans);
  }
  return 0;
}
