#include <bits/stdc++.h>
using namespace std;
const long long L = 100;
const long long len[5][5][5] = {{{2, 3, 4, 5, 6},
                                 {3, 3, 4, 5, 6},
                                 {4, 4, 2, 7, 2},
                                 {5, 5, 7, 5, 3},
                                 {6, 6, 2, 3, 2}},
                                {{3, 3, 4, 5, 6},
                                 {3, 4, 5, 6, 7},
                                 {4, 5, 5, 6, 7},
                                 {5, 6, 6, 6, 7},
                                 {6, 7, 7, 7, 7}},
                                {{2, 4, 4, 5, 6},
                                 {4, 5, 5, 6, 7},
                                 {4, 5, 6, 7, 8},
                                 {5, 6, 7, 7, 8},
                                 {6, 7, 8, 8, 8}},
                                {{5, 3, 5, 5, 6},
                                 {3, 6, 6, 6, 7},
                                 {5, 6, 7, 7, 8},
                                 {5, 6, 7, 8, 9},
                                 {6, 7, 8, 9, 9}},
                                {{2, 3, 2, 6, 6},
                                 {3, 7, 7, 7, 7},
                                 {2, 7, 8, 8, 8},
                                 {6, 7, 8, 9, 9},
                                 {6, 7, 8, 9, 10}}};
long long mex(long long a, long long b, long long c = 4) {
  if (a != 0 && b != 0 && c != 0) return 0;
  if (a != 1 && b != 1 && c != 1) return 1;
  if (a != 2 && b != 2 && c != 2) return 2;
  return 3;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  for (long long nr = 0; nr < t; nr++) {
    long long n, f[3];
    cin >> n >> f[0] >> f[1] >> f[2];
    long long l = len[f[0] - 1][f[1] - 1][f[2] - 1];
    vector<vector<long long>> dp(L, vector<long long>(3, 0));
    for (long long i = 1; i < L; i++) {
      dp[i][0] = mex(dp[max(0LL, i - f[0])][0], dp[max(0LL, i - f[1])][1],
                     dp[max(0LL, i - f[2])][2]);
      dp[i][1] = mex(dp[max(0LL, i - f[0])][0], dp[max(0LL, i - f[2])][2]);
      dp[i][2] = mex(dp[max(0LL, i - f[0])][0], dp[max(0LL, i - f[1])][1]);
    }
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    for (long long i = 0; i < n; i++)
      a[i] -= a[i] >= L ? (((a[i] - L) / l) + 1) * l : 0;
    long long total = 0;
    for (long long i = 0; i < n; i++) total ^= dp[a[i]][0];
    long long count = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < 3; j++) {
        count += ((total ^ dp[a[i]][0] ^ dp[max(0LL, a[i] - f[j])][j]) == 0);
      }
    }
    cout << count << '\n';
  }
}
