#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
  s = 0;
  register long long f = 1;
  register char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
  s *= f;
  return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0) putchar('-'), x = -x;
  long long buf[21], top = 0;
  while (x) buf[++top] = x % 10, x /= 10;
  if (!top) buf[++top] = 0;
  while (top) putchar(buf[top--] ^ '0');
  return;
}
inline void setIn(std::string s) {
  freopen(s.c_str(), "r", stdin);
  return;
}
inline void setOut(std::string s) {
  freopen(s.c_str(), "w", stdout);
  return;
}
inline void setIO(std::string s = "") {
  setIn(s + ".in");
  setOut(s + ".out");
  return;
}
template <class t>
inline bool ckmin(t &x, t y) {
  if (x > y) {
    x = y;
    return 1;
  }
  return 0;
}
template <class t>
inline bool ckmax(t &x, t y) {
  if (x < y) {
    x = y;
    return 1;
  }
  return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
const long long MaxN = 2050;
const long long p = 998244353;
inline long long fpow(long long a, long long b) {
  register long long res = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) res = res * a % p;
  return res;
}
struct CC {
  long long f[MaxN << 1], inv[MaxN << 1];
  CC() {
    f[0] = 1;
    for (long long i = 1; i < (MaxN << 1); ++i) f[i] = f[i - 1] * i % p;
    inv[(MaxN << 1) - 1] = fpow(f[(MaxN << 1) - 1], p - 2);
    for (long long i = (MaxN << 1) - 2; ~i; --i)
      inv[i] = inv[i + 1] * (i + 1) % p;
  }
  inline long long operator()(const long long &n, const long long &m) const {
    if (n < m) return 0;
    return f[n] * inv[m] % p * inv[n - m] % p;
  }
} C;
long long f[2][MaxN][11], g[2][MaxN][11], A[MaxN], B[MaxN], n, m, q;
char s[MaxN];
inline void add(long long &x, long long y) { (x += y) >= p && (x -= p); }
inline void work() {
  read(q), n = m = 0;
  while (q--) {
    std::scanf("%s", s + 1);
    long long len = std::strlen(s + 1), S = 0;
    for (long long i = 1; i <= len; ++i) S = (S * 10 + (s[i] ^ 48)) % 11;
    if (len & 1)
      A[++n] = S;
    else
      B[++m] = S;
  }
  std::memset(f, 0, sizeof f), std::memset(g, 0, sizeof g);
  f[0][0][0] = g[0][0][0] = 1;
  for (long long i = 1; i <= n; ++i, std::memset(f[i & 1], 0, sizeof f[i & 1]))
    for (long long j = 0; j <= n / 2; ++j)
      for (long long k = 0; k < 11; ++k) {
        add(f[i & 1][j][k], f[(i & 1) ^ 1][j][(k - A[i] + 11) % 11]);
        if (j) add(f[i & 1][j][k], f[(i & 1) ^ 1][j - 1][(k + A[i]) % 11]);
      }
  for (long long i = 1; i <= m; ++i, std::memset(g[i & 1], 0, sizeof g[i & 1]))
    for (long long j = 0; j <= m; ++j)
      for (long long k = 0; k < 11; ++k) {
        add(g[i & 1][j][k], g[(i & 1) ^ 1][j][(k - B[i] + 11) % 11]);
        if (j) add(g[i & 1][j][k], g[(i & 1) ^ 1][j - 1][(k + B[i]) % 11]);
      }
  register long long ans = 0;
  if (!n) {
    write(g[m & 1][0][0] * C.f[m] % p), std::puts("");
    return;
  }
  for (long long i = 0; i <= m; ++i)
    for (long long j = 0; j < 11; ++j)
      add(ans, f[n & 1][n / 2][j] * g[m & 1][i][(11 - j) % 11] % p *
                   C.f[n / 2] % p * C.f[n - (n / 2)] % p * C.f[i] % p *
                   C.f[m - i] % p * C(m - i + n / 2, n / 2) % p *
                   C(i + n - n / 2 - 1, n - n / 2 - 1) % p);
  write(ans), std::puts("");
}
signed main(void) {
  long long t;
  read(t);
  while (t--) work();
  return 0;
}
