#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000LL;
const int MAXN = 2005;
const int mod = 998244353;
int add(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return (long long)a * b % mod; }
int fact[2 * MAXN];
int choose[2 * MAXN][2 * MAXN];
int len(int x) { return x ? len(x / 10) + 1 : 0; }
void precalc() {
  fact[0] = 1;
  for (int i = (1); i < (MAXN); ++i) fact[i] = mul(fact[i - 1], i);
  for (int i = (0); i < (MAXN); ++i)
    for (int j = (0); j < (MAXN); ++j) {
      if (i < j)
        choose[i][j] = 0;
      else if (i == 0)
        choose[i][j] = 1;
      else
        choose[i][j] = add(choose[i - 1][j - 1], choose[i - 1][j]);
    }
}
void calc(int f[MAXN][11], vector<int> x) {
  static int dp[MAXN][MAXN][11];
  int N = x.size();
  memset(dp[N], 0, sizeof dp[N]);
  dp[N][0][0] = 1;
  for (int i = N - 1; i >= 0; --i) {
    for (int k = (0); k < (N + 1); ++k) {
      for (int r = (0); r < (11); ++r) {
        dp[i][k][r] = dp[i + 1][k][(r + x[i]) % 11];
        if (k)
          dp[i][k][r] =
              add(dp[i][k][r], dp[i + 1][k - 1][(r - x[i] + 11) % 11]);
      }
    }
  }
  for (int k = (0); k < (N + 1); ++k)
    for (int r = (0); r < (11); ++r) f[k][r] = dp[0][k][r];
}
void solve() {
  static int f[MAXN][11];
  static int g[MAXN][11];
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = (0); i < (n); ++i) cin >> a[i];
  vector<int> ones;
  vector<int> zeros;
  for (int i = (0); i < (n); ++i) {
    if (len(a[i]) % 2 == 1)
      ones.push_back(a[i] % 11);
    else
      zeros.push_back(a[i] % 11);
  }
  int N = ones.size();
  int M = zeros.size();
  calc(g, ones);
  calc(f, zeros);
  int pos_groups = (N + 2) / 2;
  int neg_groups = (N + 1) / 2;
  int pos_ones = (N + 1) / 2;
  int neg_ones = N / 2;
  if (N == 0) {
    int sum = 0;
    for (int x : zeros) sum += x;
    if (sum % 11 == 0)
      cout << fact[M] << endl;
    else
      cout << 0 << endl;
    return;
  }
  int sol = 0;
  for (int k = (0); k < (M + 1); ++k) {
    if (neg_groups == 0 && k < M) continue;
    for (int r = (0); r < (11); ++r) {
      int ones = mul(fact[pos_ones], mul(fact[neg_ones], g[pos_ones][r]));
      int put_zeros =
          mul(fact[k],
              mul(fact[M - k], mul(choose[pos_groups + k - 1][k],
                                   choose[neg_groups + M - k - 1][M - k])));
      int zeros = mul(put_zeros, f[k][(11 - r) % 11]);
      sol = add(sol, mul(ones, zeros));
    }
  }
  cout << sol << endl;
}
int main(void) {
  precalc();
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
