#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}
void solve() {
  int N, X, Y, Z;
  cin >> N >> X >> Y >> Z;
  vector<long long> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  vector<int> x(3);
  x[0] = X;
  x[1] = Y;
  x[2] = Z;
  map<vector<vector<int>>, int> mp;
  vector<vector<int>> grs(1, vector<int>(3, 0));
  int start = 0, period = 1;
  for (int times = 1;; times++) {
    vector<int> nexgr(3, -1);
    for (int i = 0; i < 3; i++) {
      vector<int> exist(4, 0);
      for (int j = 0; j < 3; j++) {
        if (i == j && i != 0) continue;
        exist[grs[max(0, times - x[j])][j]]++;
      }
      for (int j = 0; j < 4; j++) {
        if (exist[j] == 0) {
          nexgr[i] = j;
          break;
        }
      }
    }
    grs.push_back(nexgr);
    if (grs.size() >= 5) {
      vector<vector<int>> tar(5, vector<int>(3, 0));
      for (int i = 0; i < (5); ++i)
        for (int j = 0; j < (3); ++j) tar[i][j] = grs[grs.size() - 5 + i][j];
      if (mp.count(tar)) {
        start = mp[tar];
        period = times - mp[tar];
        break;
      }
      mp[tar] = times;
    }
  }
  auto grundy = [&](long long num, int last) {
    if (num <= start) return grs[num][last];
    return grs[start + (num - start) % period][last];
  };
  long long val = 0;
  for (int i = 0; i < (N); ++i) val ^= grundy(A[i], 0);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    val ^= grundy(A[i], 0);
    for (int j = 0; j < 3; j++) {
      if ((val ^ grundy(max(0ll, A[i] - x[j]), j)) == 0) ans++;
    }
    val ^= grundy(A[i], 0);
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  for (int i = 0; i < (T); ++i) solve();
  return 0;
}
