#include <bits/stdc++.h>
using namespace std;
namespace fastIO {
bool IOerror = 0;
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline long long read() {
  bool sign = 0;
  char ch = getchar();
  long long x = 0;
  for (; blank(ch); ch = getchar())
    ;
  if (IOerror) return 0;
  if (ch == '-') sign = 1, ch = getchar();
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  if (sign) x = -x;
  return x;
}
};  // namespace fastIO
using namespace fastIO;
long long a[1000010], b[1000010], f1[2][2010][11], f2[2][2010][11], ans[11],
    now = 0, c[2010][2010], fac[1000010], now1, now2;
long long calc(long long x, long long y) {
  if (!y) {
    if (x)
      return 0;
    else
      return 1;
  }
  return fac[x] * c[x + y - 1][y - 1] % 998244353;
}
signed main() {
  fac[0] = 1;
  for (long long i = 1; i <= 2000; i++) fac[i] = fac[i - 1] * i % 998244353;
  c[0][0] = 1;
  for (long long i = 1; i <= 2000; i++) {
    c[i][0] = 1;
    for (long long j = 1; j <= i; j++) {
      c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 998244353;
    }
  }
  long long t = read();
  while (t--) {
    long long anss = 0;
    now1 = now2 = 0;
    long long n = read();
    for (long long i = 1; i <= n; i++) {
      long long x = read(), now = 0;
      long long bb = x % 11;
      while (x) {
        now++;
        x /= 10;
      }
      if (now & 1)
        a[++now1] = bb;
      else
        b[++now2] = bb;
    }
    memset(f1[0], 0, sizeof(f1[0]));
    memset(f2[0], 0, sizeof(f2[0]));
    f1[0][0][0] = 1;
    f2[0][0][0] = 1;
    for (long long i = 1; i <= now1; i++) {
      memset(f1[i & 1], 0, sizeof(f1[i & 1]));
      for (long long j = 0; j <= now1 / 2; j++) {
        for (long long k = 0; k <= 10; k++) {
          f1[i & 1][j][k] += f1[(i & 1) ^ 1][j][(k + 11 - a[i]) % 11],
              f1[i & 1][j][k] %= 998244353;
          if (j)
            f1[i & 1][j][k] += f1[(i & 1) ^ 1][j - 1][(k + a[i]) % 11],
                f1[i & 1][j][k] %= 998244353;
        }
      }
    }
    for (long long i = 1; i <= now2; i++) {
      memset(f2[i & 1], 0, sizeof(f2[i & 1]));
      for (long long j = 0; j <= now2; j++) {
        for (long long k = 0; k <= 10; k++) {
          f2[i & 1][j][k] += f2[(i & 1) ^ 1][j][(k + 11 - b[i]) % 11],
              f2[i & 1][j][k] %= 998244353;
          if (j)
            f2[i & 1][j][k] += f2[(i & 1) ^ 1][j - 1][(k + b[i]) % 11],
                f2[i & 1][j][k] %= 998244353;
        }
      }
    }
    for (long long i = 0; i <= 10; i++) {
      ans[i] = f1[now1 & 1][now1 / 2][i] * fac[now1 / 2] % 998244353 *
               fac[now1 - now1 / 2] % 998244353;
    }
    for (long long i = 0; i <= now2; i++) {
      for (long long j = 0; j <= 10; j++) {
        anss += ans[j] * f2[now2 & 1][i][(11 - j) % 11] % 998244353 *
                calc(i, (now1 + 1) / 2) % 998244353 *
                calc(now2 - i, now1 + 1 - (now1 + 1) / 2) % 998244353,
            anss %= 998244353;
      }
    }
    cout << anss << "\n";
  }
  return 0;
}
