#include <bits/stdc++.h>
using namespace std;
int mex(const vector<int> &nimbers) {
  unordered_set<int> set;
  for (auto &nimber : nimbers) set.insert(nimber);
  for (int i = 0; i < INT_MAX; i++) {
    bool exclude = set.find(i) == set.end();
    if (!exclude) continue;
    return i;
  }
  assert(false);
}
int x, y, z;
const int STATE_M = 5;
using state = vector<vector<int>>;
state cal_nxt_state(const state &s) {
  auto res = s;
  int res0_nxt = mex({s[0][STATE_M - x], s[1][STATE_M - y], s[2][STATE_M - z]});
  int res1_nxt = mex({s[0][STATE_M - x], s[2][STATE_M - z]});
  int res2_nxt = mex({s[0][STATE_M - x], s[1][STATE_M - y]});
  res[0].push_back(res0_nxt);
  res[1].push_back(res1_nxt);
  res[2].push_back(res2_nxt);
  for (int i = 0; i < 3; i++) res[i].erase(res[i].begin());
  return res;
}
map<state, int> state2idx;
vector<state> states;
int circle_start;
int circle_length;
void pre_cal() {
  state2idx.clear();
  states.clear();
  state cur(3, vector<int>(STATE_M, 0));
  while (!state2idx.count(cur)) {
    state2idx[cur] = states.size();
    states.push_back(cur);
    cur = cal_nxt_state(cur);
  }
  circle_start = state2idx[cur];
  circle_length = (int)states.size() - circle_start;
}
using ll = long long;
int get_grundy(ll n, int pre_move) {
  n = max(n, 0ll);
  state nth_state;
  if (n < circle_start) {
    nth_state = states[n];
  } else {
    n -= circle_start;
    n %= circle_length;
    nth_state = states[circle_start + n];
  }
  return nth_state[pre_move].back();
}
const int N = 3e5 + 7;
ll a[N];
int nimber[N];
void solve() {
  int n;
  cin >> n >> x >> y >> z;
  for (int i = 0; i < n; i++) cin >> a[i];
  pre_cal();
  for (int i = 0; i < n; i++) nimber[i] = get_grundy(a[i], 0);
  int nim_sum = 0;
  for (int i = 0; i < n; i++) nim_sum ^= nimber[i];
  int result = 0;
  for (int i = 0; i < n; i++) {
    int nim_sum_exc_nimi = nim_sum ^ nimber[i];
    ll ai_after_move[3] = {a[i] - x, a[i] - y, a[i] - z};
    for (int move = 0; move < 3; move++) {
      int new_nimi = get_grundy(ai_after_move[move], move);
      int new_nim_sum = nim_sum_exc_nimi ^ new_nimi;
      if (new_nim_sum == 0) result++;
    }
  }
  cout << result << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tcase;
  cin >> tcase;
  for (int icase = 0; icase < tcase; icase++) solve();
  return 0;
}
