#include <bits/stdc++.h>
using namespace std;
const int mxN = 250;
inline int mex(int a, int b) { return a && b ? 0 : (a != 1 && b != 1 ? 1 : 2); }
inline int mex(int p, int q, int r) {
  int m[4] = {0, 0, 0, 0};
  m[p] = 1;
  m[q] = 1;
  m[r] = 1;
  for (int i = 0; i < 4; i++)
    if (!m[i]) return i;
}
int get(long long int a, int p) {
  if (a > 100)
    return (a - 100) % p + 100;
  else
    return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n, x, y, z;
  cin >> t;
  while (t--) {
    cin >> n >> x >> y >> z;
    int g[mxN][3];
    g[0][0] = g[0][1] = g[0][2] = 0;
    int period = -1;
    int flag = 1;
    for (int i = 1; i <= 200; i++) {
      int p = g[max(i - x, 0)][0], q = g[max(i - y, 0)][1],
          r = g[max(i - z, 0)][2];
      g[i][0] = mex(p, q, r);
      g[i][1] = mex(p, r);
      g[i][2] = mex(p, q);
      if (i > 100 && flag) {
        int cnt = 0;
        for (int j = 1; j <= 5; j++) {
          if (g[i - j][0] == g[100 - j][0] && g[i - j][1] == g[100 - j][1] &&
              g[i - j][2] == g[100 - j][2])
            cnt++;
        }
        if (cnt == 5 && flag) {
          period = i;
          flag = 0;
        }
      }
    }
    period = period - 100;
    long long int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long int xo = 0;
    for (int i = 0; i < n; i++) {
      xo = xo ^ g[get(arr[i], period)][0];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      xo = xo ^ g[get(arr[i], period)][0];
      if (!(xo ^ g[get(max(arr[i] - x, 0ll), period)][0])) ++ans;
      if (!(xo ^ g[get(max(arr[i] - y, 0ll), period)][1])) ++ans;
      if (!(xo ^ g[get(max(arr[i] - z, 0ll), period)][2])) ++ans;
      xo = xo ^ g[get(arr[i], period)][0];
    }
    cout << ans << "\n";
  }
  return 0;
}
