#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int mod = 998244353;
long long k = 5;
long long n, x, y, z;
long long a[N];
long long cnt, period;
vector<vector<long long> > stateLog;
map<vector<vector<long long> >, long long> h;
long long mex(const vector<long long> v) {
  unordered_set<long long> hh;
  for (int i = v.size(); i--;) hh.insert(v[i]);
  for (int i = 0; i < v.size(); ++i) {
    if (!hh.count(i)) return i;
  }
  return v.size();
}
vector<vector<long long> > getNext(vector<vector<long long> > cur) {
  long long s0 = mex({cur[0][k - x], cur[1][k - y], cur[2][k - z]});
  long long s1 = mex({cur[0][k - x], cur[2][k - z]});
  long long s2 = mex({cur[0][k - x], cur[1][k - y]});
  cur[0].push_back(s0);
  cur[1].push_back(s1);
  cur[2].push_back(s2);
  cur[0].erase(cur[0].begin());
  cur[1].erase(cur[1].begin());
  cur[2].erase(cur[2].begin());
  return cur;
}
void prep() {
  cnt = 0;
  vector<vector<long long> > cur(3, vector<long long>(k, 0));
  h.clear();
  stateLog.clear();
  while (!h.count(cur)) {
    h[cur] = cnt;
    stateLog.push_back({cur[0].back(), cur[1].back(), cur[2].back()});
    cur = getNext(cur);
    ++cnt;
  }
  period = cnt - h[cur];
}
long long getGrundy(long long idx, long long t) {
  if (idx < cnt) return stateLog[idx][t];
  return stateLog[cnt - period + (idx - cnt) % period][t];
}
long long solve() {
  long long res = 0;
  prep();
  long long nimSum = 0;
  for (int i = 0; i < n; ++i) {
    nimSum ^= getGrundy(a[i], 0);
  }
  for (int i = 0; i < n; ++i) {
    nimSum ^= getGrundy(a[i], 0);
    res += (nimSum == getGrundy(max(0ll, a[i] - x), 0));
    res += (nimSum == getGrundy(max(0ll, a[i] - y), 1));
    res += (nimSum == getGrundy(max(0ll, a[i] - z), 2));
    nimSum ^= getGrundy(a[i], 0);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> x >> y >> z;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    cout << solve() << endl;
  }
  return 0;
}
