#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAX = 1000;
long long p;
vector<vector<int>> dp(MAX, vector<int>(3));
int get_state(const vector<int>& a) {
  set<int> s(a.begin(), a.end());
  int up = *max_element(a.begin(), a.end());
  for (int i = 0; i <= up; i++)
    if (!(s.count(i))) return i;
  return up + 1;
}
bool is_period(int x) {
  bool ok = true;
  for (int i = MAX - 1; i >= MAX / 2; i--) {
    ok &= (dp[i][0] == dp[i - x][0]);
    ok &= (dp[i][1] == dp[i - x][1]);
    ok &= (dp[i][2] == dp[i - x][2]);
  }
  return ok;
}
int get_grundy(long long x, int i) {
  if (x < MAX) return dp[x][i];
  int N = MAX - 1;
  int xx = x - (x - N + p - 1) / p * p;
  return dp[xx][i];
}
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];
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  for (int i = 1; i < MAX; i++) {
    vector<int> m;
    m.push_back(dp[max((i - x), 0)][0]);
    m.push_back(dp[max((i - y), 0)][1]);
    m.push_back(dp[max((i - z), 0)][2]);
    int temp = m[1];
    dp[i][0] = get_state(m);
    m[1] = MAX;
    dp[i][1] = get_state(m);
    m[1] = temp, m[2] = MAX;
    dp[i][2] = get_state(m);
  }
  p = -1;
  for (int i = 1; i < MAX / 2; i++) {
    if (is_period(i)) {
      p = i;
      break;
    }
  }
  int nsum = 0, res = 0;
  for (int i = 0; i < n; i++) {
    nsum ^= get_grundy(a[i], 0);
  }
  for (int i = 0; i < n; i++) {
    int temp = get_grundy(a[i], 0);
    nsum ^= temp;
    nsum ^= get_grundy(max((a[i] - x), 0ll), 0);
    res += (nsum == 0);
    nsum ^= get_grundy(max((a[i] - x), 0ll), 0);
    nsum ^= get_grundy(max((a[i] - y), 0ll), 1);
    res += (nsum == 0);
    nsum ^= get_grundy(max((a[i] - y), 0ll), 1);
    nsum ^= get_grundy(max((a[i] - z), 0ll), 2);
    res += (nsum == 0);
    nsum ^= get_grundy(max((a[i] - z), 0ll), 2);
    nsum ^= temp;
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
