#include <bits/stdc++.h>
using namespace std;
const int nax = 20;
int n, x, y, z, cnt, p;
map<vector<vector<int>>, int> id;
vector<vector<int>> state_log;
int mex(const vector<int>& v) {
  for (int i = 0; 1; ++i) {
    int dis = 1;
    for (auto& x : v) {
      if (x == i) {
        dis = 0;
        break;
      }
    }
    if (dis) return i;
  }
}
void precalc() {
  id.clear();
  vector<vector<int>> state(5, vector<int>(3, 0));
  cnt = 0;
  state_log.clear();
  while (!id.count(state)) {
    id[state] = cnt;
    state_log.push_back({state.back()[0], state.back()[1], state.back()[2]});
    state.push_back({mex({state[5 - x][0], state[5 - y][1], state[5 - z][2]}),
                     mex({state[5 - x][0], state[5 - z][2]}),
                     mex({state[5 - x][0], state[5 - y][1]})});
    state.erase(state.begin());
    cnt++;
  }
  p = cnt - id[state];
}
int get_grundy(long long x, int t) {
  if (x < cnt) {
    return state_log[x][t];
  } else {
    int pp = cnt - p;
    x -= pp;
    return state_log[pp + (x % p)][t];
  }
}
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;
    precalc();
    long long a[n];
    int ans = 0, res = 0;
    for (auto& w : a) {
      cin >> w;
      ans ^= get_grundy(w, 0);
    }
    for (auto& w : a) {
      ans ^= get_grundy(w, 0);
      res += (ans == get_grundy(max(0ll, w - x), 0)) +
             (ans == get_grundy(max(0ll, w - y), 1)) +
             (ans == get_grundy(max(0ll, w - z), 2));
      ans ^= get_grundy(w, 0);
    }
    cout << res << "\n";
  }
}
