#include <bits/stdc++.h>
using namespace std;
const int N = 2e3, MOD = 998244353;
void add(int& a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  if (a < 0) a += MOD;
}
int mul(int a, int b) { return 1LL * a * b % MOD; }
int pow_mod(int a, int n = MOD - 2) {
  int t = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) t = mul(t, a);
    a = mul(a, a);
  }
  return t;
}
int f[N + 2], inv[N + 2];
int k(int x, int n) {
  if (!x) return 1;
  return mul(f[n + x - 1], inv[x - 1]);
}
int solve(vector<int>& even, vector<int>& old, int& sum, int n) {
  vector<vector<vector<int>>> dp(
      2, vector<vector<int>>(n + 1, vector<int>(11, 0)));
  int cur = 0;
  dp[0][0][0] = dp[1][0][0] = 1;
  for (int i = 0; i < old.size(); ++i) {
    for (int k = 0; k < 11; ++k)
      for (int j = 1; j <= min(int(old.size() / 2), i + 1); ++j) {
        dp[cur][j][k] = dp[!cur][j][k];
        add(dp[cur][j][k], dp[!cur][j - 1][(k + 11 - old[i]) % 11]);
      }
    cur = !cur;
  }
  for (int k = 0; k < 11; ++k) {
    dp[cur][0][k] = dp[!cur][0][k] = dp[!cur][old.size() / 2][k];
    for (int i = 1; i <= old.size() / 2; ++i)
      dp[cur][i][k] = dp[!cur][i][k] = 0;
  }
  int ans = 0;
  int x = old.size() / 2, y = old.size() - x;
  if (old.size())
    for (int i = 0; i < even.size(); ++i) {
      for (int k = 0; k < 11; ++k)
        for (int j = 1; j <= i + 1; ++j) {
          dp[cur][j][k] = dp[!cur][j][k];
          add(dp[cur][j][k], dp[!cur][j - 1][(k + 11 - even[i]) % 11]);
        }
      cur = !cur;
    }
  cur = !cur;
  for (int i = 0; i <= even.size(); ++i) {
    int plus = mul(mul(f[x], f[y]), dp[cur][i][sum]);
    plus = mul(plus, k((old.size() + 1) / 2, i));
    plus = mul(plus, k((old.size() + 2) / 2, even.size() - i));
    add(ans, plus);
  }
  return ans;
}
int main() {
  f[0] = inv[0] = 1;
  for (int i = 1; i <= N; ++i) f[i] = mul(f[i - 1], i);
  inv[N] = pow_mod(f[N]);
  for (int i = N - 1; i > 0; --i) inv[i] = mul(inv[i + 1], i + 1);
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int ntest;
  cin >> ntest;
  while (ntest--) {
    int n, sum = 0;
    cin >> n;
    vector<int> even, old;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      int tmp = x;
      bool cnt = 0;
      while (tmp) {
        cnt = !cnt;
        tmp /= 10;
      }
      if (cnt)
        old.push_back(x % 11);
      else
        even.push_back(x % 11);
      sum += x;
      sum %= 11;
    }
    if (sum & 1) {
      sum = 6 + sum / 2;
      cout << solve(even, old, sum, n) << endl;
    } else {
      sum /= 2;
      cout << solve(even, old, sum, n) << endl;
    }
  }
  return 0;
}
