#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int SIZE = 2017;
int dp[SIZE][11];
int fac[SIZE];
int C[SIZE][SIZE];
void ADD(int &x, long long v) { x = (x + v) % MOD; }
int mod11(int x) {
  if (x >= 11) x -= 11;
  if (x < 0) x += 11;
  return x;
}
void solve(vector<int> oe[]) {
  int odd_n = ((int)(oe[1]).size());
  int even_n = ((int)(oe[0]).size());
  memset((dp), 0, sizeof((dp)));
  dp[0][0] = 1;
  int need_pos = (odd_n + 1) / 2;
  for (int i = 0; i < (odd_n); ++i) {
    for (int j = need_pos; j >= 0; j--) {
      int tmp[11] = {};
      for (int k = 0; k < (11); ++k) {
        if (!dp[j][k]) continue;
        ADD(dp[j + 1][mod11(k + oe[1][i])], dp[j][k]);
        ADD(tmp[mod11(k - oe[1][i])], dp[j][k]);
      }
      memcpy(dp[j], tmp, sizeof(int) * 11);
    }
  }
  int res[11];
  memcpy(res, dp[need_pos], sizeof(int) * 11);
  memset((dp), 0, sizeof((dp)));
  dp[0][0] = 1;
  for (int i = 0; i < (even_n); ++i) {
    for (int j = even_n; j >= 0; j--) {
      int tmp[11] = {};
      for (int k = 0; k < (11); ++k) {
        if (!dp[j][k]) continue;
        ADD(dp[j + 1][mod11(k + oe[0][i])], dp[j][k]);
        ADD(tmp[mod11(k - oe[0][i])], dp[j][k]);
      }
      memcpy(dp[j], tmp, sizeof(int) * 11);
    }
  }
  if (!odd_n) {
    printf("%d\n", (int)((long long)dp[even_n][0] * fac[even_n] % MOD));
    return;
  }
  int ans = 0;
  for (int i = 0; i < (even_n + 1); ++i) {
    for (int j = 0; j < (11); ++j) {
      int need_v = (11 - j) % 11;
      ADD(ans, (long long)res[need_v] * dp[i][j] % MOD * fac[i] % MOD *
                   fac[even_n - i] % MOD * C[(odd_n + 2) / 2 - 1 + i][i] % MOD *
                   C[(odd_n + 1) / 2 - 1 + (even_n - i)][even_n - i] % MOD *
                   fac[need_pos] % MOD * fac[odd_n - need_pos]);
    }
  }
  printf("%d\n", ans);
}
int main() {
  for (int i = 0; i < (SIZE); ++i) {
    C[i][0] = 1;
    for (int j = (1); j < (i + 1); ++j) {
      C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
      if (C[i][j] >= MOD) C[i][j] -= MOD;
    }
  }
  fac[0] = 1;
  for (int i = (1); i < (SIZE); ++i) {
    fac[i] = (long long)fac[i - 1] * i % MOD;
  }
  char s[12];
  int ___T, case_n = 1;
  scanf("%d ", &___T);
  while (___T-- > 0) {
    int(n);
    scanf("%d", &n);
    vector<int> oe[2];
    for (int i = 0; i < (n); ++i) {
      scanf("%s", (s));
      int sn = strlen(s);
      int r = 0;
      for (int i = 0; i < (sn); ++i) {
        int v = s[sn - 1 - i] - '0';
        if (i & 1)
          r -= v;
        else
          r += v;
      }
      r %= 11;
      if (r < 0) r += 11;
      oe[sn & 1].push_back(r);
    }
    solve(oe);
  }
  return 0;
}
