#include <bits/stdc++.h>
using namespace std;
const long long Mo = 998244353LL;
long long f[2][2010][11], g[2][2010][11], inv[2010], fac[2010];
long long ans;
int n, m, M, val[2010], lav[2010], T;
void add(long long &a, long long b) {
  a += b;
  a %= Mo;
}
void init() {
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  m = 0;
  M = 0;
}
void proc(int x) {
  int o = 0;
  int x_ = x;
  while (x_) {
    o ^= 1;
    x_ /= 10;
  }
  if (o)
    val[++m] = x % 11;
  else
    lav[++M] = x % 11;
}
void pre_dp() {
  f[0][0][0] = 1;
  int sing = (m + 1) / 2;
  for (int i = 1; i <= m; i++) {
    int o = i & 1;
    memset(f[o], 0, sizeof(f[o]));
    for (int j = 0; j <= sing; j++) {
      for (int res = 0; res < 11; res++) {
        if (sing - j > 0)
          add(f[o][j + 1][(res + val[i]) % 11], f[o ^ 1][j][res] * (sing - j));
        if (m - i + 1 - sing + j > 0)
          add(f[o][j][(res + val[i] * 10) % 11],
              f[o ^ 1][j][res] * (m - i + 1 - sing + j));
      }
    }
  }
  return;
}
long long C(int a, int b) {
  if (a < b) return 0LL;
  return (fac[a] * inv[b] % Mo * inv[a - b] % Mo);
}
void solve() {
  g[0][0][0] = 1;
  for (int i = 1; i <= M; i++) {
    int o = i & 1;
    memset(g[o], 0, sizeof(g[o]));
    for (int j = 0; j <= i - 1; j++) {
      for (int res = 0; res < 11; res++) {
        add(g[o][j + 1][(res + lav[i]) % 11], g[o ^ 1][j][res]);
        add(g[o][j][(res + lav[i] * 10) % 11], g[o ^ 1][j][res]);
      }
    }
  }
  ans = 0;
  int A = m / 2 + 1;
  int B = m + 1 - A;
  for (int a = 0; a <= M; a++) {
    int b = M - a;
    for (int RES = 0; RES < 11; RES++) {
      int res = (11 - RES) % 11;
      long long X = A ? fac[a] * C(a + A - 1, a) % Mo : (!a);
      long long Y = B ? fac[b] * C(b + B - 1, b) % Mo : (!b);
      add(ans,
          f[m & 1][(m + 1) / 2][RES] * X % Mo * Y % Mo * g[M & 1][a][res] % Mo);
    }
  }
}
long long fpm(long long a, long long b) {
  long long ans = 1LL;
  for (; b; b >>= 1) {
    if (b & 1LL) ans = ans * a % Mo;
    a = a * a % Mo;
  }
  return ans;
}
int main() {
  fac[0] = 1LL;
  for (int i = 1; i <= 2001; i++) fac[i] = fac[i - 1] * i % Mo;
  inv[2001] = fpm(fac[2001], Mo - 2LL);
  for (int i = 2000; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % Mo;
  for (scanf("%d", &T); T; T--) {
    scanf("%d", &n);
    init();
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      proc(x);
    }
    pre_dp();
    solve();
    cout << ans << endl;
  }
  return 0;
}
