#include <bits/stdc++.h>
using namespace std;
template <class T>
using v2d = vector<vector<T> >;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxN = 3e5 + 10;
const int maxS = 1e3 + 10;
int n, x, y, z, sg[maxS][3], maxLen = 1e3, ans, pre[maxN], suf[maxN];
long long a[maxN], h[maxS], base = 4;
int firstZero(int x) {
  for (int i = 0; i < (int)(31); ++i) {
    if ((x >> i & 1) == 0) {
      return i;
    }
  }
  return -1;
}
void solve() {
  cin >> n >> x >> y >> z;
  sg[0][0] = sg[0][1] = sg[0][2] = 0;
  for (int i = 1; i <= (int)(maxLen); ++i) {
    int xmask = 0, ymask = 0, zmask = 0;
    if (i >= x) {
      xmask |= 1 << sg[i - x][0];
    } else {
      xmask |= 1;
    }
    if (i >= y) {
      ymask |= 1 << sg[i - y][2];
    } else {
      ymask |= 1;
    }
    if (i >= z) {
      zmask |= 1 << sg[i - z][1];
    } else {
      zmask |= 1;
    }
    sg[i][0] = firstZero(xmask | ymask | zmask);
    sg[i][1] = firstZero(xmask | ymask);
    sg[i][2] = firstZero(xmask | zmask);
  }
  int len = max({x, y, z}), period = -1, pos = -1;
  for (int i = (int)(0); i <= (int)(maxLen - len + 1); ++i) {
    h[i] = 0;
    for (int j = (int)(i); j <= (int)(i + len - 1); ++j) {
      for (int k = 0; k < (int)(3); ++k) {
        h[i] = h[i] * base + sg[j][k];
      }
    }
  }
  map<long long, int> mp;
  for (int i = (int)(0); i <= (int)(maxLen - len + 1); ++i) {
    if (mp.count(h[i])) {
      period = i - mp[h[i]];
      pos = mp[h[i]];
      break;
    }
    mp[h[i]] = i;
  }
  assert(period != -1 && pos != -1);
  for (int i = 1; i <= (int)(n); ++i) {
    cin >> a[i];
  }
  ans = 0;
  for (int i = (int)(0); i <= (int)(n + 1); ++i) {
    pre[i] = suf[i] = 0;
  }
  for (int i = 1; i <= (int)(n); ++i) {
    int t;
    if (a[i] >= pos) {
      t = (a[i] - pos) % period + pos;
    } else {
      t = a[i];
    }
    pre[i] = pre[i - 1] ^ sg[t][0];
  }
  for (int i = n; i; i--) {
    int t;
    if (a[i] >= pos) {
      t = (a[i] - pos) % period + pos;
    } else {
      t = a[i];
    }
    suf[i] = suf[i + 1] ^ sg[t][0];
  }
  for (int i = 1; i <= (int)(n); ++i) {
    int s = 0, t;
    if (i > 1) {
      s ^= pre[i - 1];
    }
    if (i < n) {
      s ^= suf[i + 1];
    }
    if (a[i] >= x) {
      if (a[i] - x >= pos) {
        t = (a[i] - x - pos) % period + pos;
        ans += ((s ^ sg[t][0]) == 0);
      } else {
        ans += ((s ^ sg[a[i] - x][0]) == 0);
      }
    } else {
      ans += (s == 0);
    }
    if (a[i] >= y) {
      if (a[i] - y >= pos) {
        t = (a[i] - y - pos) % period + pos;
        ans += ((s ^ sg[t][2]) == 0);
      } else {
        ans += ((s ^ sg[a[i] - y][2]) == 0);
      }
    } else {
      ans += (s == 0);
    }
    if (a[i] >= z) {
      if (a[i] - z >= pos) {
        t = (a[i] - z - pos) % period + pos;
        ans += ((s ^ sg[t][1]) == 0);
      } else {
        ans += ((s ^ sg[a[i] - z][1]) == 0);
      }
    } else {
      ans += (s == 0);
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
