#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353;
int f[2010][11];
int g[2010][11];
int tmp[11];
int odd[2010], even[2010];
int getval(int x) {
  int ans = 0, op = 1;
  while (x) {
    int t = x % 10;
    ans = (ans + op * t + 11) % 11;
    op = -op;
    x /= 10;
  }
  if (op > 0) return ans + 11;
  return ans;
}
int fac[4010];
int inv[4010];
int fpow(int a, int b) {
  int ans = 1, t = a;
  while (b) {
    if (b & 1) ans = 1ll * ans * t % Mod;
    t = 1ll * t * t % Mod;
    b >>= 1;
  }
  return ans;
}
void init() {
  int N = 4000;
  fac[0] = 1;
  for (int i = 1; i <= N; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
  inv[N] = fpow(fac[N], Mod - 2);
  for (int i = N; i >= 1; i--) inv[i - 1] = 1ll * inv[i] * i % Mod;
  return;
}
int C(int x, int y) {
  if (x < 0 || y < 0 || x - y < 0) return 0;
  return 1ll * fac[x] * inv[y] % Mod * inv[x - y] % Mod;
}
int S(int n, int m) {
  if (m <= 0) {
    if (n > 0) return 0;
    return 1;
  }
  return 1ll * fac[n] * C(n + m - 1, m - 1) % Mod;
}
void solve() {
  int N1 = 0, N2 = 0;
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    x = getval(x);
    if (x < 11)
      odd[++N1] = x;
    else
      even[++N2] = x - 11;
  }
  memset(f, 0, sizeof(f));
  memset(g, 0, sizeof(g));
  int O = (N1 + 1) / 2;
  f[0][0] = 1;
  for (int i = 1; i <= N1; i++)
    for (int j = O; j >= 0; j--) {
      memset(tmp, 0, sizeof(tmp));
      for (int k = 0; k < 11; k++) {
        int to = (k - odd[i] + 11) % 11;
        tmp[to] = (tmp[to] + f[j][k]) % Mod;
      }
      if (j > 0) {
        for (int k = 0; k < 11; k++) {
          int to = (k + odd[i]) % 11;
          tmp[to] = (tmp[to] + f[j - 1][k]) % Mod;
        }
      }
      for (int k = 0; k < 11; k++) f[j][k] = tmp[k];
    }
  g[0][0] = 1;
  for (int i = 1; i <= N2; i++)
    for (int j = N2; j >= 0; j--) {
      memset(tmp, 0, sizeof(tmp));
      for (int k = 0; k < 11; k++) {
        int to = (k - even[i] + 11) % 11;
        tmp[to] = (tmp[to] + g[j][k]) % Mod;
      }
      if (j > 0) {
        for (int k = 0; k < 11; k++) {
          int to = (k + even[i]) % 11;
          tmp[to] = (tmp[to] + g[j - 1][k]) % Mod;
        }
      }
      for (int k = 0; k < 11; k++) g[j][k] = tmp[k];
    }
  int ans = 0;
  for (int i = 0; i <= N2; i++)
    for (int j = 0; j < 11; j++)
      ans = (ans + 1ll * g[i][(11 - j) % 11] * f[O][j] % Mod * fac[O] % Mod *
                       fac[N1 - O] % Mod * S(i, (N1 + 2) / 2) % Mod *
                       S(N2 - i, (N1 + 1) / 2)) %
            Mod;
  printf("%d\n", ans);
  return;
}
int main() {
  init();
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
