#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int M = 1000;
int sg[M][3], n, x, y, z, p, len, ans;
long long a[N];
bool vis[4];
int getsg(long long x, int s) {
  if (x < 0) return 0;
  if (x >= M) x = p + (x - p) % len;
  return sg[x][s];
}
bool check(int i, int j) {
  for (int k = 0; k < 5; ++k) {
    if (sg[i + k][0] != sg[j + k][0]) return false;
    if (sg[i + k][1] != sg[j + k][1]) return false;
    if (sg[i + k][2] != sg[j + k][2]) return false;
  }
  return true;
}
void findloop() {
  for (int i = 5; i < 900; ++i) {
    for (int j = 5; j < 40; ++j) {
      if (check(i, i + j)) {
        p = i;
        len = j;
        return;
      }
    }
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d %d", &n, &x, &y, &z);
    ans = 0;
    for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
    for (int i = 1; i < M; ++i) {
      memset(vis, false, sizeof(vis));
      x > i ? vis[0] = true : vis[sg[i - x][0]] = true;
      y > i ? vis[0] = true : vis[sg[i - y][1]] = true;
      z > i ? vis[0] = true : vis[sg[i - z][2]] = true;
      for (int j = 0; j < 4; ++j)
        if (!vis[j]) {
          sg[i][0] = j;
          break;
        }
      memset(vis, false, sizeof(vis));
      x > i ? vis[0] = true : vis[sg[i - x][0]] = true;
      z > i ? vis[0] = true : vis[sg[i - z][2]] = true;
      for (int j = 0; j < 4; ++j)
        if (!vis[j]) {
          sg[i][1] = j;
          break;
        }
      memset(vis, false, sizeof(vis));
      x > i ? vis[0] = true : vis[sg[i - x][0]] = true;
      y > i ? vis[0] = true : vis[sg[i - y][1]] = true;
      for (int j = 0; j < 4; ++j)
        if (!vis[j]) {
          sg[i][2] = j;
          break;
        }
    }
    findloop();
    int s = 0;
    for (int i = 1; i <= n; ++i) s ^= getsg(a[i], 0);
    for (int i = 1; i <= n; ++i) {
      s ^= getsg(a[i], 0);
      s ^= getsg(a[i] - x, 0);
      if (!s) ans++;
      s ^= getsg(a[i] - x, 0);
      s ^= getsg(a[i] - y, 1);
      if (!s) ans++;
      s ^= getsg(a[i] - y, 1);
      s ^= getsg(a[i] - z, 2);
      if (!s) ans++;
      s ^= getsg(a[i] - z, 2);
      s ^= getsg(a[i], 0);
    }
    printf("%d\n", ans);
  }
}
