#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
int init;
long long int dp[3][105], arr[300005], period;
long long int getGrundy(int p, int s) {
  if (s == 0) return dp[p][s] = 0;
  if (dp[p][s] != -1) return dp[p][s];
  set<long long int> st;
  st.insert(-1);
  if (p == 0) {
    st.insert(getGrundy(0, max(0, s - x)));
    st.insert(getGrundy(1, max(0, s - y)));
    st.insert(getGrundy(2, max(0, s - z)));
  } else if (p == 1) {
    st.insert(getGrundy(0, max(0, s - x)));
    st.insert(getGrundy(2, max(0, s - z)));
  } else if (p == 2) {
    st.insert(getGrundy(0, max(0, s - x)));
    st.insert(getGrundy(1, max(0, s - y)));
  }
  vector<long long int> ans;
  for (long long int e : st) ans.push_back(e);
  for (int i = 0, colchin = ans.size(); i < colchin; ++i)
    if (i == ans.size() - 1 || ans[i] + 1 != ans[i + 1])
      return dp[p][s] = ans[i] + 1;
}
long long int gg(int p, long long int s) {
  if (s < 100) return dp[p][(int)s];
  long long int k = (s - 100) / period;
  k++;
  int news = s - k * period;
  assert(news >= init);
  return dp[p][news];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> x >> y >> z;
    memset(dp, -1, sizeof dp);
    for (int i = 0, colchin = 100; i < colchin; ++i)
      getGrundy(0, i), getGrundy(1, i), getGrundy(2, i);
    vector<pair<long long int, pair<long long int, long long int> > > base;
    for (int l = 0, colchin = 5; l < colchin; ++l) {
      pair<long long int, pair<long long int, long long int> > tuple =
          pair<long long int, pair<long long int, long long int> >(
              getGrundy(0, l), pair<long long int, long long int>(
                                   getGrundy(1, l), getGrundy(2, l)));
      base.push_back(tuple);
    }
    map<vector<pair<long long int, pair<long long int, long long int> > >, int>
        mp;
    mp[base] = 4;
    int index = -1e8;
    for (int l = 5, colchin = 100; l < colchin; ++l) {
      pair<long long int, pair<long long int, long long int> > tuple =
          pair<long long int, pair<long long int, long long int> >(
              getGrundy(0, l), pair<long long int, long long int>(
                                   getGrundy(1, l), getGrundy(2, l)));
      vector<pair<long long int, pair<long long int, long long int> > > nwbase =
          base;
      nwbase.erase(nwbase.begin());
      nwbase.push_back(tuple);
      if (mp.count(nwbase) != 0) {
        index = l;
        base = nwbase;
        break;
      } else {
        mp[nwbase] = l;
        base = nwbase;
      }
    }
    period = index - mp[base];
    init = mp[base] - 4;
    long long int xorsum = 0;
    for (int i = 0, colchin = n; i < colchin; ++i)
      cin >> arr[i], xorsum ^= gg(0, arr[i]);
    int cnt = 0;
    long long int attack[3];
    attack[0] = x, attack[1] = y, attack[2] = z;
    for (int i = 0, colchin = n; i < colchin; ++i) {
      for (int j = 0, colchin = 3; j < colchin; ++j) {
        long long int newval = max((long long int)0, arr[i] - attack[j]);
        if ((gg(j, newval) ^ gg(0, arr[i]) ^ xorsum) == 0) cnt++;
      }
    }
    cout << cnt << "\n";
  }
  return 0;
}
