#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
const int N = 2010;
int f[11][N], g[11][N], h[11][N];
int a[N], n;
inline pair<int, int> cal(int x) {
  int ret = 0, cnt = 0;
  while (x) {
    cnt++;
    if (cnt & 1)
      ret = (ret + x % 10) % 11;
    else
      ret = (ret - x % 10) % 11;
    x /= 10;
  }
  ret = (ret + 11) % 11;
  return make_pair(ret, cnt);
}
int c[N][N], fac[N];
int C[20];
inline void add(int& x, int y) { x = (x + y) % P; }
int main() {
  fac[0] = 1;
  for (int i = 1; i < N; i++) fac[i] = 1ll * fac[i - 1] * i % P;
  c[0][0] = 1;
  for (int i = 0; i < N; i++) {
    c[i][0] = 1;
    for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % P;
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    memset(C, 0, sizeof(C));
    scanf("%d", &n);
    int odd = 0, even = 0;
    memset(f, 0, sizeof(f));
    memset(h, 0, sizeof(h));
    f[0][0] = 1;
    h[0][0] = 1;
    for (int i = 1; i <= n; i++) {
      scanf("%d", a + i);
      pair<int, int> tmp = cal(a[i]);
      if (tmp.second & 1) {
        for (int j = 0; j < 11; j++)
          for (int k = 0; k <= odd + 1; k++) g[j][k] = 0;
        for (int j = 0; j < 11; j++)
          for (int k = 0; k <= odd; k++) {
            add(g[(j + tmp.first) % 11][k + 1], f[j][k]);
            add(g[(j - tmp.first + 11) % 11][k], f[j][k]);
          }
        for (int j = 0; j < 11; j++)
          for (int k = 0; k <= odd + 1; k++) f[j][k] = g[j][k];
        odd++;
      } else {
        for (int j = 0; j < 11; j++)
          for (int k = 0; k <= even + 1; k++) g[j][k] = 0;
        for (int j = 0; j < 11; j++)
          for (int k = 0; k <= even; k++) {
            add(g[(j - tmp.first + 11) % 11][k + 1], h[j][k]);
            add(g[(j + tmp.first + 11) % 11][k], h[j][k]);
          }
        for (int j = 0; j < 11; j++)
          for (int k = 0; k <= even + 1; k++) h[j][k] = g[j][k];
        even++;
      }
    }
    int num = odd + 1 >> 1;
    int ans = 0;
    if (num == 0) {
      int tmp = 0;
      for (int i = 1; i <= n; i++) tmp = (tmp + 11 + cal(a[i]).first) % 11;
      if (tmp % 11 == 0) ans = fac[n];
    }
    for (int j = 0; j < 11; j++) {
      for (int k = 0; k <= even; k++)
        if (num + k - 1 >= 0)
          add(ans, 1ll * f[j][num] * h[(11 - j) % 11][k] % P * fac[k] % P *
                       fac[even - k] % P * c[num + k - 1][k] % P *
                       c[even - k + odd - num][odd - num] % P);
    }
    ans = 1ll * ans * fac[num] % P * fac[odd - num] % P;
    ans = (ans + P) % P;
    printf("%d\n", ans);
  }
  return 0;
}
