#include <bits/stdc++.h>
using namespace std;
const int max_n = 300005;
int T, n, x, y, z;
long long a[max_n];
int dp[100][3];
int SG(int i, int j) {
  if (i <= 0) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  set<int> s;
  s.insert(SG(i - x, 0));
  if (j != 1) s.insert(SG(i - y, 1));
  if (j != 2) s.insert(SG(i - z, 2));
  for (int k = 0;; k++)
    if (s.count(k) == 0) return dp[i][j] = k;
}
int loop[3];
int getloop(int s) {
  if (loop[s]) return loop[s];
  for (int i = 32; i <= 60; i++) {
    bool f = true;
    for (int j = 1; j <= 30; j++) {
      if (SG(31 + j - 1, s) != SG(i + j - 1, s)) f = false;
    }
    if (f == true) {
      return loop[s] = i - 31;
    }
  }
}
int cal(long long n, int s) {
  if (n <= 30) return SG(n, s);
  n -= 31;
  int len = getloop(s);
  return SG(31 + n % len, s);
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d%d", &n, &x, &y, &z);
    for (int i = 0; i < 100; i++) {
      for (int j = 0; j < 3; j++) dp[i][j] = -1;
    }
    for (int i = 0; i < 3; i++) loop[i] = 0;
    for (int i = 1; i <= n; i++) scanf("%lld", a + i);
    int sg = 0;
    for (int i = 1; i <= n; i++) sg ^= cal(a[i], 0);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int tmp = sg ^ cal(a[i], 0);
      if ((tmp ^ cal(a[i] - x, 0)) == 0) ans++;
      if ((tmp ^ cal(a[i] - y, 1)) == 0) ans++;
      if ((tmp ^ cal(a[i] - z, 2)) == 0) ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
