#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
  out << "( " << rhs.first << " , " << rhs.second << " )";
  return out;
}
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A>
string to_string(vector<vector<A>> v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
    res += "\n";
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
bool debug = 0;
const int MAXN = 1e6 + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e7 + 100);
map<pair<int, char>, int> used;
int x, y, z;
map<pair<int, char>, int> make_pair;
int get(int val, char last) {
  if (val == 0) return 0;
  if (used.count({val, last})) return used[{val, last}];
  int res = 0;
  res |= 1 << get(max(val - x, 0), 'x');
  if (last != 'y') res |= 1 << get(max(val - y, 0), 'y');
  if (last != 'z') res |= 1 << get(max(val - z, 0), 'z');
  for (int i = 0;; ++i) {
    if (res & (1 << i)) {
    } else {
      return used[{val, last}] = i;
    }
  }
}
int ST, VAL;
void find_cycle() {
  for (int st = 100; st <= 100; ++st) {
    for (int val = 2; val <= 20; ++val) {
      bool flag = true;
      for (int i = st + 1; i <= 300; ++i) {
        for (char c : {'x', 'y', 'z'}) {
          if (get(i, c) != get(st + (i - st) % val, c)) {
            flag = false;
            break;
          }
        }
        if (!flag) break;
      }
      if (flag) {
        ST = st;
        VAL = val;
        return;
        ;
      }
    }
  }
}
long long a[MAXN];
int calc(long long x, int c) {
  if (x <= 0) return 0;
  if (x < ST) return get(x, c);
  long long val = ST + (x - ST) % VAL;
  return get(val, c);
}
void solve() {
  int n;
  cin >> n >> x >> y >> z;
  used.clear();
  42;
  ST = VAL = -1;
  find_cycle();
  42;
  int ans = 0;
  int all = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    all ^= calc(a[i], 'x');
  }
  for (int i = 1; i <= n; ++i) {
    int cur = calc(a[i], 'x');
    for (char c : {'x', 'y', 'z'}) {
      if (c == 'x') {
        int val = calc(a[i] - x, 'x');
        if ((val ^ cur ^ all) == 0) {
          ans++;
        }
      }
      if (c == 'y') {
        int val = calc(a[i] - y, 'y');
        if ((val ^ cur ^ all) == 0) {
          ans++;
        }
      }
      if (c == 'z') {
        int val = calc(a[i] - z, 'z');
        if ((val ^ cur ^ all) == 0) {
          ans++;
        }
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(15);
  int t = 1;
  cin >> t;
  while (t--) solve();
  42;
}
