#include <bits/stdc++.h>
long long T, frac[5000], inv[5000], n, x, a[5000], b[5000], tot1, tot2,
    dp1[10][2010][20], dp2[10][2010][20];
long long quickpow(long long x, long long y) {
  if (x == 0) return 0;
  if (x == 1) return 1;
  if (y == 0) return 1;
  if (y == 1) return x;
  if (y % 2 == 0) return quickpow(x * x % 998244353, y / 2);
  return quickpow(x * x % 998244353, y / 2) * x % 998244353;
}
long long C(long long n, long long m) {
  if (m < 0 && m > n) return 0;
  return frac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
long long calc(long long n, long long m) {
  if (n == 0 && m == 0) return 1;
  return quickpow(n, m);
}
signed main() {
  scanf("%lld", &T);
  frac[0] = inv[0] = 1;
  for (long long i = 1; i <= 4000; i++)
    frac[i] = frac[i - 1] * i % 998244353,
    inv[i] = quickpow(frac[i], 998244353 - 2);
  while (T--) {
    scanf("%lld", &n);
    tot1 = tot2 = 0;
    for (long long i = 1; i <= n; i++) {
      scanf("%lld", &x);
      long long X = x, type = 0;
      while (X) X /= 10, type ^= 1;
      if (type)
        a[++tot1] = x % 11;
      else
        b[++tot2] = x % 11;
    }
    for (long long i = 0; i <= 1; i++)
      for (long long j = 0; j <= n; j++)
        for (long long k = 0; k < 11; k++) dp1[i][j][k] = dp2[i][j][k] = 0;
    dp1[0][0][0] = dp2[0][0][0] = 1;
    for (long long i = 1; i <= tot1; i++)
      for (long long j = 0; j <= i; j++)
        for (long long k = 0; k < 11; k++) {
          dp1[i % 2][j][k] = dp1[(i - 1) % 2][j][(k - a[i] + 11) % 11];
          if (j)
            dp1[i % 2][j][k] =
                (dp1[i % 2][j][k] + dp1[(i - 1) % 2][j - 1][(k + a[i]) % 11]) %
                998244353;
        }
    for (long long i = 1; i <= tot2; i++)
      for (long long j = 0; j <= i; j++)
        for (long long k = 0; k < 11; k++) {
          dp2[i % 2][j][k] = dp2[(i - 1) % 2][j][(k - b[i] + 11) % 11];
          if (j)
            dp2[i % 2][j][k] =
                (dp2[i % 2][j][k] + dp2[(i - 1) % 2][j - 1][(k + b[i]) % 11]) %
                998244353;
        }
    long long Ans = 0;
    if (tot1 == 0) {
      Ans = dp2[tot2 % 2][0][0] * frac[tot2] % 998244353;
      printf("%d\n", Ans);
      continue;
    }
    for (long long i = 0; i <= tot2; i++)
      for (long long j = 0; j < 11; j++) {
        long long x = C(tot2 - i + (tot1 + 1) / 2 - 1, tot2 - i);
        long long y = C(i + tot1 + 1 - (tot1 + 1) / 2 - 1, i);
        (Ans += dp1[tot1 % 2][(tot1) / 2][j] * dp2[tot2 % 2][i][(11 - j) % 11] %
                998244353 * frac[tot1 / 2] % 998244353 * frac[tot1 - tot1 / 2] %
                998244353 * frac[tot2 - i] % 998244353 * frac[i] % 998244353 *
                x % 998244353 * y % 998244353) %= 998244353;
      }
    printf("%lld\n", Ans);
  }
}
