#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<vector<vector<vector<vector<int>>>>> grundy(
      6, vector<vector<vector<vector<int>>>>(
             6, vector<vector<vector<int>>>(
                    6, vector<vector<int>>(301, vector<int>(3)))));
  vector<vector<vector<int>>> md(6, vector<vector<int>>(6, vector<int>(6)));
  for (int i = 1; i <= 5; i++) {
    for (int j = 1; j <= 5; j++) {
      for (int k = 1; k <= 5; k++) {
        for (int l = 1; l < 301; l++) {
          vector<int> v({i, j, k});
          for (int m = 0; m < 3; m++) {
            set<int> st;
            for (int n = 0; n < 3; n++) {
              if (m && m == n) continue;
              st.insert(grundy[i][j][k][max(0, l - v[n])][n]);
            }
            for (auto n : st) {
              if (grundy[i][j][k][l][m] == n) grundy[i][j][k][l][m]++;
            }
          }
        }
        for (int l = 1; l <= 300; l++) {
          bool flag = true;
          for (int m = l + 100; m <= 300; m++) {
            flag &= grundy[i][j][k][m] == grundy[i][j][k][m - l];
          }
          if (flag) {
            md[i][j][k] = l;
            break;
          }
        }
      }
    }
  }
  int K;
  cin >> K;
  while (K--) {
    int M, a, b, c;
    cin >> M >> a >> b >> c;
    int x = 0;
    vector<long long int> v(M);
    for (auto &i : v) {
      cin >> i;
      if (i <= 100)
        x ^= grundy[a][b][c][i][0];
      else {
        int id = i % md[a][b][c];
        while (id < 100) id += md[a][b][c];
        x ^= grundy[a][b][c][id][0];
      }
    }
    if (x == 0) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    for (auto i : v) {
      if (i <= 100) {
        int bef = grundy[a][b][c][i][0];
        int nx = grundy[a][b][c][max(0LL, (i - a))][0];
        if ((x ^ bef ^ nx) == 0) ans++;
        nx = grundy[a][b][c][max(0LL, (i - b))][1];
        if ((x ^ bef ^ nx) == 0) ans++;
        nx = grundy[a][b][c][max(0LL, (i - c))][2];
        if ((x ^ bef ^ nx) == 0) ans++;
      } else {
        int id = i % md[a][b][c];
        while (id < 100) id += md[a][b][c];
        int bef = grundy[a][b][c][id][0];
        id = (i - a) % md[a][b][c];
        while (id < 100) id += md[a][b][c];
        int nx = grundy[a][b][c][id][0];
        if ((x ^ bef ^ nx) == 0) ans++;
        id = (i - b) % md[a][b][c];
        while (id < 100) id += md[a][b][c];
        nx = grundy[a][b][c][id][1];
        if ((x ^ bef ^ nx) == 0) ans++;
        id = (i - c) % md[a][b][c];
        while (id < 100) id += md[a][b][c];
        nx = grundy[a][b][c][id][2];
        if ((x ^ bef ^ nx) == 0) ans++;
      }
    }
    cout << ans << endl;
  }
}
