#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e3 + 10, mod = 998244353;
long long a[maxn], b[maxn], lena, lenb, f[2][maxn][11], g[2][maxn][11],
    C[maxn][maxn], pw[maxn], inv[maxn];
long long qpow(long long a, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) res = res * a % mod;
    a = a * a % mod;
    p >>= 1;
  }
  return res;
}
void init() {
  pw[0] = 1;
  C[0][0] = 1;
  for (long long i = 1; i <= 2000; i++)
    pw[i] = pw[i - 1] * i % mod, C[i][0] = 1;
  for (long long i = 1; i <= 2000; i++)
    for (long long j = 1; j <= 2000; j++)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
long long calc(long long n, long long m) {
  if (m == 0) return n == 0;
  return pw[n] * C[n + m - 1][m - 1] % mod;
}
void work() {
  long long n;
  scanf("%lld", &n);
  lena = lenb = 0;
  for (long long i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    long long opt = 0;
    for (long long j = x; j; j /= 10) opt ^= 1;
    if (opt)
      a[++lena] = x % 11;
    else
      b[++lenb] = x % 11;
  }
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  f[0][0][0] = g[0][0][0] = 1;
  for (long long i = 1; i <= lena; i++) {
    memset(f[i & 1], 0, sizeof(f[i & 1]));
    for (long long j = 0; j <= i; j++)
      for (long long k = 0; k < 11; k++) {
        long long x = (k - a[i] + 11) % 11;
        long long y = (k + a[i] + 11) % 11;
        f[i & 1][j][k] = (f[i & 1][j][k] + f[(i - 1) & 1][j][x]) % mod;
        if (j != 0)
          f[i & 1][j][k] = (f[i & 1][j][k] + f[(i - 1) & 1][j - 1][y]) % mod;
      }
  }
  for (long long i = 1; i <= lenb; i++) {
    memset(g[i & 1], 0, sizeof(g[i & 1]));
    for (long long j = 0; j <= i; j++)
      for (long long k = 0; k < 11; k++) {
        long long x = (k - b[i] + 11) % 11;
        long long y = (k + b[i] + 11) % 11;
        g[i & 1][j][k] = (g[i & 1][j][k] + g[(i - 1) & 1][j][x]) % mod;
        if (j != 0)
          g[i & 1][j][k] = (g[i & 1][j][k] + g[(i - 1) & 1][j - 1][y]) % mod;
      }
  }
  long long ans = 0;
  for (long long i = 0; i <= lenb; i++)
    for (long long j = 0; j < 11; j++) {
      long long a =
          g[lenb & 1][i][j] * f[lena & 1][lena / 2][(11 - j) % 11] % mod;
      long long b = pw[lena / 2] * pw[lena - lena / 2] % mod;
      long long c =
          calc(i, lena - lena / 2) * calc(lenb - i, lena / 2 + 1) % mod;
      ans = (ans + a * b % mod * c % mod) % mod;
    }
  printf("%lld\n", ans);
}
signed main() {
  init();
  long long t;
  scanf("%lld", &t);
  while (t--) work();
  return 0;
}
