#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int T, n, x, y, z, sg[2][2][maxn], s[maxn], ans, t = 40, li;
long long a[maxn];
bool f[10];
void init_sg(int up) {
  for (int i = 1; i <= up; ++i)
    for (int j = 0; j <= 1; ++j)
      for (int k = 0; k <= 1; ++k)
        if (!(i == 0 && j == 0)) {
          for (int l = 0; l <= 4; ++l) f[l] = 0;
          f[sg[1][1][max(0, i - x)]] = 1;
          if (j) f[sg[0][1][max(0, i - y)]] = 1;
          if (k) f[sg[1][0][max(0, i - z)]] = 1;
          int p = 0;
          while (f[p]) p++;
          sg[j][k][i] = p;
        }
}
int get(int up) {
  for (int i = 1; i <= up; ++i) {
    bool ff = 1;
    for (int j = t + i; j <= up && ff; ++j)
      for (int k = 0; k <= 1 && ff; ++k)
        for (int l = 0; l <= 1 && ff; ++l)
          if (sg[k][l][j] != sg[k][l][j - i]) {
            ff = 0;
            break;
          }
    if (ff) return i;
  }
  assert(0);
  return 0;
}
inline int id(long long x) {
  if (x <= t) return x;
  return (x - t) % li + t;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d%d", &n, &x, &y, &z);
    init_sg(200);
    li = get(200);
    int sum = 0;
    ans = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      s[i] = sg[1][1][id(a[i])];
      sum ^= s[i];
    }
    for (int i = 1; i <= n; i++) {
      sum ^= s[i];
      ans += (sum == sg[1][1][id(a[i]) - x]);
      ans += (sum == sg[0][1][id(a[i]) - y]);
      ans += (sum == sg[1][0][id(a[i]) - z]);
      sum ^= s[i];
    }
    printf("%d\n", ans);
  }
  return 0;
}
