#include <bits/stdc++.h>
using namespace std;
int N, T, fact[2011][2011];
pair<int, int> arr[2011];
int dp1[12][2011], dp2[12][2011];
void add(int &a, int b) { a = (a + b) % 998244353; }
int main() {
  if (fopen("data.in", "r")) freopen("data.in", "r", stdin);
  fact[0][0] = 1;
  for (int i = 0; i < 2011; i++) {
    if (i) fact[i][i] = i;
    for (int j = 0; j < i; j++) fact[i][j] = 1;
    for (int j = i + 1; j < 2011; j++)
      fact[i][j] = (1LL * j * fact[i][j - 1]) % 998244353;
  }
  scanf("%d", &T);
  for (int i = 0; i < T; i++) {
    scanf("%d", &N);
    int cnt = 0;
    for (int j = 0; j < N; j++) {
      scanf("%d", &arr[j].first);
      arr[j].second = 0;
      for (int k = arr[j].first; k; k /= 10) arr[j].second = !arr[j].second;
      cnt += arr[j].second;
      arr[j].first = arr[j].first % 11;
    }
    memset(dp1, 0, sizeof(dp1));
    memset(dp2, 0, sizeof(dp2));
    dp1[0][0] = 1;
    for (int j = 0; j < N; j++) {
      if (arr[j].second) continue;
      int v = arr[j].first;
      for (int k = 0; k < 11; k++) {
        for (int l = 0; l < N; l++) {
          add(dp2[(k + v) % 11][l + 1], dp1[k][l]);
          add(dp2[(k - v + 11) % 11][l], dp1[k][l]);
        }
      }
      memcpy(dp1, dp2, sizeof(dp2));
      memset(dp2, 0, sizeof(dp2));
    }
    for (int j = 0; j < 11; j++) {
      for (int k = 0; k <= N - cnt; k++) {
        if (cnt || k == N) {
          long long v =
              (1LL * dp1[j][k] * fact[cnt / 2 + 1][cnt / 2 + k]) % 998244353;
          if (cnt)
            v = (v * fact[(cnt + 1) / 2][(cnt + 1) / 2 - 1 + N - k - cnt]) %
                998244353;
          add(dp2[j][0], v);
        }
      }
    }
    memcpy(dp1, dp2, sizeof(dp2));
    memset(dp2, 0, sizeof(dp2));
    for (int j = 0; j < N; j++) {
      if (!arr[j].second) continue;
      int v = arr[j].first;
      for (int k = 0; k < 11; k++) {
        for (int l = 0; l < N; l++) {
          add(dp2[(k + v) % 11][l + 1], dp1[k][l]);
          add(dp2[(k - v + 11) % 11][l], dp1[k][l]);
        }
      }
      memcpy(dp1, dp2, sizeof(dp2));
      memset(dp2, 0, sizeof(dp2));
    }
    long long v = dp1[0][(cnt + 1) / 2];
    v = (v * fact[1][(cnt + 1) / 2]) % 998244353;
    v = (v * fact[1][cnt / 2]) % 998244353;
    printf("%I64d\n", v);
  }
  return 0;
}
