#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long inf = 1e18, MOD = 1e9 + 7;
long long n, m, k, ar[1000005], grundy[500][3], x, y, z, period, start;
string s, s1;
map<vector<vector<long long> >, long long> ma;
long long mex(vector<long long> vec) {
  set<long long> se;
  for (long long i = 0; i < vec.size(); i++) se.insert(vec[i]);
  long long ret = 0;
  for (auto i : se)
    if (i != ret)
      break;
    else
      ret++;
  return ret;
}
void calc_grundy() {
  grundy[0][0] = grundy[0][1] = grundy[0][2] = 0;
  for (long long i = 1; i < 500; i++) {
    grundy[i][0] = mex({grundy[max(0LL, i - x)][0], grundy[max(0ll, i - y)][1],
                        grundy[max(0ll, i - z)][2]});
    grundy[i][1] =
        mex({grundy[max(0LL, i - x)][0], grundy[max(0ll, i - z)][2]});
    grundy[i][2] =
        mex({grundy[max(0LL, i - x)][0], grundy[max(0ll, i - y)][1]});
  }
}
void calc_period() {
  vector<vector<long long> > vec;
  for (long long i = 0; i < 5; i++)
    vec.push_back({grundy[i][0], grundy[i][1], grundy[i][2]});
  long long pos = 0;
  while (ma[vec] == 0) {
    ma[vec] = pos + 1;
    vec.push_back({grundy[pos + 5][0], grundy[pos + 5][1], grundy[pos + 5][2]});
    vec.erase(vec.begin());
    pos++;
  }
  period = pos - ma[vec] + 1;
  start = ma[vec] - 1;
}
long long calc_index(long long idx) {
  if (idx <= start) return idx;
  idx -= start;
  idx %= period;
  idx += start;
  return idx;
}
void ini() {
  start = 0, period = 0;
  ma.clear();
  for (long long i = 0; i < 500; i++) {
    grundy[i][0] = 0;
    grundy[i][1] = 0;
    grundy[i][2] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  cin >> ti;
  while (ti--) {
    ini();
    cin >> n >> x >> y >> z;
    calc_grundy();
    calc_period();
    vector<long long> val(n, 0);
    long long tot = 0;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> val[i];
      tot ^= grundy[calc_index(val[i])][0];
    }
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      long long temp = tot ^ grundy[calc_index(val[i])][0];
      if ((temp ^ grundy[calc_index(max(0ll, val[i] - x))][0]) == 0) ans++;
      if ((temp ^ grundy[calc_index(max(0ll, val[i] - y))][1]) == 0) ans++;
      if ((temp ^ grundy[calc_index(max(0ll, val[i] - z))][2]) == 0) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
