#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
template <class T = int>
T __rand(T range = numeric_limits<T>::max()) {
  return (T)(rng() % range);
}
template <class T>
ostream& operator,(ostream& out, const T& thing) {
  return out << ", " << thing;
}
template <class U, class V>
ostream& operator<<(ostream& out, const pair<U, V>& p) {
  return (out << "(" << p.first, p.second) << ")";
}
template <class A, class B>
ostream& operator<<(ostream& out, const tuple<A, B>& t) {
  return (out << "(" << get<0>(t), get<1>(t)) << ")";
}
template <class A, class B, class C>
ostream& operator<<(ostream& out, const tuple<A, B, C>& t) {
  return (out << "(" << get<0>(t), get<1>(t), get<2>(t)) << ")";
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& container) {
  out << "{";
  if (((int)container.size())) out << container[0];
  for (int i = 0; i++ < ((int)container.size()) - 1;) out, container[i];
  return out << "}";
}
template <class x>
vector<typename x::value_type> $v(const x& a) {
  return vector<typename x::value_type>(a.begin(), a.end());
}
template <class u>
vector<typename iterator_traits<u>::value_type> $v(u a, u b) {
  return vector<typename iterator_traits<u>::value_type>(a, b);
}
int mex(const set<int>& u) {
  int ans = 0;
  while (u.count(ans)) ++ans;
  return ans;
}
vector<vector<int>> gen_nim(int n, int x, int y, int z) {
  vector<int> nim[3];
  for (int i = -1; ++i < 3;) nim[i].resize(n);
  auto get_nim = [&](int i, int s) {
    if (i < 0) return 0;
    return nim[s][i];
  };
  for (int i = 1; i < n; ++i) {
    nim[0][i] = mex({get_nim(i - x, 0), get_nim(i - y, 1), get_nim(i - z, 2)});
    nim[1][i] = mex({get_nim(i - x, 0), get_nim(i - z, 2)});
    nim[2][i] = mex({get_nim(i - x, 0), get_nim(i - y, 1)});
  }
  return {nim[0], nim[1], nim[2]};
}
int find_suff_period(const vector<int>& u) {
  for (int p = 1; p < ((int)u.size()) / 2; ++p) {
    int correct_time = 0;
    for (int i = ((int)u.size()) - 1; i - p >= 0; --i) {
      if (u[i] != u[i - p]) break;
      ++correct_time;
    }
    if (correct_time > 50) return p;
  }
  assert(false);
  return -1;
}
vector<int> nims[3][6][6][6];
int period[3][6][6][6];
int get_nim(long long num, int s, int x, int y, int z) {
  if (num < 0) return 0;
  if (nims[s][x][y][z].empty()) {
    auto cur_nims = gen_nim(100, x, y, z);
    for (int i = -1; ++i < 3;) {
      nims[i][x][y][z] = cur_nims[i];
      period[i][x][y][z] = find_suff_period(nims[i][x][y][z]);
    }
  }
  int nim_len = ((int)nims[s][x][y][z].size());
  int per = period[s][x][y][z];
  if (num < nim_len) return nims[s][x][y][z][num];
  num -= ((int)nims[s][x][y][z].size());
  num %= per;
  return nims[s][x][y][z][nim_len - per + num];
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int ntest;
  cin >> ntest;
  for (int testcase = 0; testcase++ < ntest;) {
    int n, x, y, z;
    cin >> n >> x >> y >> z;
    vector<long long> num(n);
    vector<int> cur_nims(n);
    for (int i = -1; ++i < n;) {
      cin >> num[i];
      cur_nims[i] = get_nim(num[i], 0, x, y, z);
    }
    int nim_sum = 0;
    int ans = 0;
    for (auto i : cur_nims) nim_sum ^= i;
    for (int i = -1; ++i < n;) {
      int cur_nim_sum = nim_sum ^ cur_nims[i];
      ans += cur_nim_sum == get_nim(num[i] - x, 0, x, y, z);
      ans += cur_nim_sum == get_nim(num[i] - y, 1, x, y, z);
      ans += cur_nim_sum == get_nim(num[i] - z, 2, x, y, z);
    }
    cout << ans << '\n';
  }
  return 0;
}
