#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long fac[2101], n, m;
struct node {
  int len, x;
  inline void get() {
    x = len = 0;
    long long xx = read(), op = 1;
    while (xx) {
      x += xx % 10 * op + 11;
      x %= 11;
      xx /= 10;
      len++;
      op *= -1;
    }
  }
} a[2101];
inline bool cmp(node a, node b) { return ((a.len % 2) > (b.len % 2)); }
long long g[2][4120][11], f[2][2020][11];
int main() {
  fac[0] = 1;
  for (long long i = 1; i <= 2000; i++) fac[i] = fac[i - 1] * i % 998244353;
  int T = read();
  while (T--) {
    n = read();
    for (int i = 1; i <= n; i++) {
      a[i].get();
    }
    bool cur = 0;
    memset(g, 0, sizeof g);
    memset(f, 0, sizeof f);
    sort(a + 1, a + 1 + n, cmp);
    register int i, ZERO = n + 2;
    g[cur][ZERO][0] = 1;
    for (i = 1; i <= n; i++) {
      if (a[i].len % 2 == 0) break;
      cur ^= 1;
      memset(g[cur], 0, sizeof g[cur]);
      for (int j = ZERO - i; j <= ZERO + i; j++) {
        for (int k = 0; k < 11; k++) {
          g[cur][j][k] =
              (g[cur][j][k] + g[cur ^ 1][j + 1][(k - a[i].x + 11) % 11]) %
              998244353;
          g[cur][j][k] =
              (g[cur][j][k] + g[cur ^ 1][j - 1][(k + a[i].x + 11) % 11]) %
              998244353;
        }
      }
    }
    i--;
    for (int k = 0; k < 11; k++) {
      int op = ((i % 2 == 1) ? i / 2 + 1 : i / 2);
      f[cur][op][k] = g[cur][op - i / 2 + ZERO][k] * fac[op] % 998244353 *
                      fac[i / 2] % 998244353;
    }
    i++;
    for (; i <= n; i++) {
      cur ^= 1;
      memset(f[cur], 0, sizeof f[cur]);
      for (int j = 0; j <= i; j++) {
        for (int k = 0; k < 11; k++) {
          long long eve = j, od = i - j;
          f[cur][j][(k - a[i].x + 11) % 11] =
              (f[cur][j][(k - a[i].x + 11) % 11] +
               f[cur ^ 1][j][k] * 1ll * od % 998244353) %
              998244353;
          f[cur][j + 1][(k + a[i].x + 11) % 11] =
              (f[cur][j + 1][(k + a[i].x + 11) % 11] +
               f[cur ^ 1][j][k] * 1ll * eve % 998244353) %
              998244353;
        }
      }
    }
    long long ans = 0;
    for (int i = 0; i <= n; i++) ans = (ans + f[cur][i][0]) % 998244353;
    cout << (ans % 998244353 + 998244353) % 998244353 << endl;
  }
  return 0;
}
