#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i2 = pair<int, int>;
using box = vector<vector<int> >;
const int N = 3e5 + 9;
int dp[3][50];
int cnt[4];
ll A[N];
int mex() {
  int i = 0;
  while (cnt[i]) i++;
  return i;
}
int f(int i, ll n, int a, int b) {
  if (n < a) return dp[i][n];
  n -= a;
  n %= b - a;
  n += a;
  return dp[i][n];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    int x, y, z;
    cin >> x >> y >> z;
    for (int i = 1; i <= n; ++i) cin >> A[i];
    for (int i = 1; i <= 40; i++) {
      int ix = max(i - x, 0);
      int iy = max(i - y, 0);
      int iz = max(i - z, 0);
      cnt[dp[0][ix]]++;
      cnt[dp[1][iy]]++;
      cnt[dp[2][iz]]++;
      dp[0][i] = mex();
      cnt[dp[1][iy]]--;
      dp[1][i] = mex();
      cnt[dp[2][iz]]--;
      cnt[dp[1][iy]]++;
      dp[2][i] = mex();
      cnt[dp[0][ix]]--;
      cnt[dp[1][iy]]--;
    }
    map<box, int> M;
    int a = -1, b = -1;
    for (int i = 0;; ++i) {
      box bx(3, vector<int>(5));
      for (int j = 0; j <= 2; j++) {
        for (int k = 0; k < 5; k++) bx[j][k] = dp[j][i + k];
      }
      if (M.count(bx)) {
        a = M[bx];
        b = i;
        break;
      }
      M[bx] = i;
    }
    ll X = 0;
    int res = 0;
    for (int i = 1; i <= n; ++i) X ^= f(0, A[i], a, b);
    for (int i = 1; i <= n; ++i) {
      X ^= f(0, A[i], a, b);
      ll ix = max(A[i] - x, 0LL);
      ll iy = max(A[i] - y, 0LL);
      ll iz = max(A[i] - z, 0LL);
      if ((X ^ f(0, ix, a, b)) == 0) res++;
      if ((X ^ f(1, iy, a, b)) == 0) res++;
      if ((X ^ f(2, iz, a, b)) == 0) res++;
      X ^= f(0, A[i], a, b);
    }
    cout << res << "\n";
  }
  return 0;
}
