#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
const int K = 1500;
int n, x[3];
long long a[N];
int dp[K][3];
void build_dp() {
  for (int i = 1; i < K; ++i) {
    for (int j = 0; j < 3; ++j) {
      set<int> arr;
      for (int k = 0; k < 3; ++k) {
        if (j != k || j == 0) {
          if (i <= x[k]) {
            arr.insert(0);
          } else {
            arr.insert(dp[i - x[k]][k]);
          }
        }
      }
      dp[i][j] = 0;
      while (arr.find(dp[i][j]) != arr.end()) {
        ++dp[i][j];
      }
    }
  }
}
int s, mod;
int ff(long long x, int j) {
  if (x <= 0) {
    return 0;
  } else if (x < K) {
    return dp[x][j];
  } else {
    return dp[(x - s) % mod + s][j];
  }
}
int state[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> x[0] >> x[1] >> x[2];
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    build_dp();
    map<vector<int>, int> f;
    s = -1, mod = -1;
    for (int i = 0; i < K; ++i) {
      vector<int> arr;
      for (int d = 0; d <= 11; ++d) {
        for (int j = 0; j < 3; ++j) {
          arr.push_back(dp[i + d][j]);
        }
      }
      if (f.find(arr) != f.end()) {
        s = f[arr];
        mod = i - f[arr];
        break;
      } else {
        f[arr] = i;
      }
    }
    assert(s != -1);
    int res = 0;
    for (int i = 0; i < n; ++i) {
      res ^= ff(a[i], 0);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 3; ++j) {
        ans += !(res ^ ff(a[i], 0) ^ ff(a[i] - x[j], j));
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
