#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int const maxn = 1000;
int dp[maxn][3];
int x, y, z;
int solve(const int n, const int flag = 0) {
  if (n <= 0) return 0;
  if (dp[n][flag] >= 0) return dp[n][flag];
  set<int> ne = {solve(n - x)};
  if (flag != 1) ne.insert(solve(n - y, 1));
  if (flag != 2) ne.insert(solve(n - z, 2));
  dp[n][flag] = 0;
  while (ne.find(dp[n][flag]) != ne.end()) ++dp[n][flag];
  return dp[n][flag];
}
int fndloop(vector<int> f) {
  reverse(begin(f), end(f));
  int best = 0;
  for (int i = 1; i + i < f.size(); ++i)
    if (vector<int>(f.begin(), f.begin() + i) ==
        vector<int>(f.begin() + i, f.begin() + 2 * i))
      best = i;
  return best;
}
int getidx(int sz, int cycle, long long n) {
  sz -= cycle;
  if (n > sz) {
    n -= sz;
    n %= cycle;
    n += sz;
  }
  return n;
}
void solve() {
  for (auto& vec : dp) vec[0] = vec[1] = vec[2] = -1;
  int n;
  cin >> n;
  cin >> x >> y >> z;
  vector<int> gra(maxn, -1);
  for (int i = 0; i < maxn; ++i) gra[i] = solve(i);
  int cycle = fndloop(gra);
  vector<long long> a(n);
  for (auto& x : a) cin >> x;
  int val = 0;
  for (auto& x : a) val ^= solve(getidx(maxn, cycle, x));
  if (val == 0) {
    cout << "0\n";
    return;
  }
  int ans = 0;
  for (auto& v : a) {
    int idx = getidx(maxn, cycle, v);
    int need = val ^ solve(idx);
    ans += solve(idx - x) == need;
    ans += solve(idx - y, 1) == need;
    ans += solve(idx - z, 2) == need;
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
