#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> sg_state;
map<vector<vector<int>>, int> m;
int period;
int cnt;
const int K = 5;
int t, n, x, y, z;
int sg(long long x, int t) {
  if (x < cnt)
    return sg_state[x][t];
  else {
    int first = cnt - period;
    x -= first;
    return sg_state[first + (x % period)][t];
  }
}
int mex(const vector<int> &a) {
  for (int i = 0; i < a.size(); ++i) {
    bool find = false;
    for (auto x : a) {
      if (x == i) {
        find = true;
        break;
      }
    }
    if (!find) return i;
  }
  return a.size();
}
vector<vector<int>> next_state(vector<vector<int>> cur) {
  vector<vector<int>> ns = cur;
  int next_s0 = mex({cur[0][K - x], cur[1][K - y], cur[2][K - z]});
  int next_s1 = mex({cur[0][K - x], cur[2][K - z]});
  int next_s2 = mex({cur[0][K - x], cur[1][K - y]});
  ns[0].push_back(next_s0);
  ns[1].push_back(next_s1);
  ns[2].push_back(next_s2);
  ns[0].erase(ns[0].begin());
  ns[1].erase(ns[1].begin());
  ns[2].erase(ns[2].begin());
  return ns;
}
void init() {
  m.clear();
  sg_state.clear();
  vector<vector<int>> cur(3, vector<int>(K, 0));
  cnt = 0;
  while (!m.count(cur)) {
    m[cur] = cnt;
    sg_state.push_back({cur[0].back(), cur[1].back(), cur[2].back()});
    cur = next_state(cur);
    cnt++;
  }
  period = cnt - m[cur];
}
void solve(vector<long long> a, int n, int x, int y, int z) {
  init();
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res ^= sg(a[i], 0);
  }
  int c = 0;
  for (int i = 0; i < n; ++i) {
    res ^= sg(a[i], 0);
    c += (res == sg(max(0ll, a[i] - x), 0)) ? 1 : 0;
    c += (res == sg(max(0ll, a[i] - y), 1)) ? 1 : 0;
    c += (res == sg(max(0ll, a[i] - z), 2)) ? 1 : 0;
    res ^= sg(a[i], 0);
  }
  cout << c << endl;
}
int main() {
  cin >> t;
  long long a;
  for (int i = 0; i < t; ++i) {
    cin >> n >> x >> y >> z;
    vector<long long> temp;
    for (int j = 0; j < n; ++j) {
      cin >> a;
      temp.push_back(a);
    }
    solve(temp, n, x, y, z);
  }
  return 0;
}
