#include <bits/stdc++.h>
using namespace std;
long long int fact[100005], ifact[100005], dp[2][2005][12], dp1[2][2005][12],
    store[12], arr[2005];
vector<long long int> odd, even, temp;
inline long long int add(long long int x, long long int y) {
  x += y;
  if (x >= 998244353) x -= 998244353;
  return x;
}
inline long long int sub(long long int x, long long int y) {
  return (x - y + 998244353) % 998244353;
}
inline long long int mul(long long int x, long long int y) {
  return (x * y) % 998244353;
}
long long int bpow(long long int x, long long int n) {
  long long int ans = 1;
  while (n > 0) {
    if (n & 1) ans *= x;
    x *= x;
    ans %= 998244353;
    x %= 998244353;
    n /= 2;
  }
  return ans;
}
void pre_calc(long long int N) {
  fact[0] = ifact[0] = 1;
  for (long long int i = 1; i <= N; ++i) {
    fact[i] = (fact[i - 1] * i) % 998244353;
    ifact[i] = bpow(fact[i], 998244353 - 2);
  }
}
long long int ncr(int n, int r) {
  if (r < 0 or n < r) return 0;
  long long int ans = fact[n];
  ans = (ans * ifact[r]) % 998244353;
  ans = (ans * ifact[n - r]) % 998244353;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  ;
  cin.tie(0);
  ;
  long long int i, j, n, t, x, y, z, ans, sign, sum, odd_sz, even_sz, req, pos1,
      pos2, k;
  pre_calc(100000);
  cin >> t;
  while (t--) {
    cin >> n;
    for (i = 1; i <= n; i++) cin >> arr[i];
    odd.clear();
    even.clear();
    for (i = 1; i <= n; i++) {
      temp.clear();
      x = arr[i];
      while (x > 0) {
        temp.push_back(x % 10);
        x /= 10;
      }
      reverse(temp.begin(), temp.end());
      sum = 0;
      sign = 1;
      for (auto it : temp) {
        if (sign)
          sum = (sum + it) % 11;
        else
          sum = (sum - it + 11) % 11;
        sign = 1 - sign;
      }
      if (temp.size() & 1)
        odd.push_back(sum);
      else
        even.push_back(sum);
    }
    odd_sz = odd.size();
    even_sz = even.size();
    if (odd_sz) {
      req = (odd_sz + 1) / 2;
      for (i = 0; i <= 1; i++) {
        for (j = 0; j <= req; j++) {
          for (k = 0; k < 11; k++) dp[i][j][k] = 0;
        }
      }
      dp[0][1][odd[0]] = 1;
      dp[0][0][(11 - odd[0]) % 11] = 1;
      for (i = 1; i < odd_sz; i++) {
        for (j = 0; j <= min(i, req); j++) {
          for (k = 0; k < 11; k++) {
            if (j + 1 <= req)
              dp[i & 1][j + 1][(k + odd[i]) % 11] = add(
                  dp[i & 1][j + 1][(k + odd[i]) % 11], dp[(i - 1) & 1][j][k]);
            dp[i & 1][j][(k - odd[i] + 11) % 11] = add(
                dp[i & 1][j][(k - odd[i] + 11) % 11], dp[(i - 1) & 1][j][k]);
          }
        }
        for (j = 0; j <= req; j++) {
          for (k = 0; k < 11; k++) dp[(i - 1) & 1][j][k] = 0;
        }
      }
      for (i = 0; i < 11; i++)
        store[i] = mul(dp[(odd_sz - 1) & 1][req][i],
                       mul(fact[req], fact[odd_sz - req]));
    }
    if (even_sz) {
      for (i = 0; i <= 1; i++) {
        for (j = 0; j <= even_sz; j++) {
          for (k = 0; k < 11; k++) dp1[i][j][k] = 0;
        }
      }
      dp1[0][1][even[0]] = 1;
      dp1[0][0][(11 - even[0]) % 11] = 1;
      for (i = 1; i < even_sz; i++) {
        for (j = 0; j <= i; j++) {
          for (k = 0; k < 11; k++) {
            dp1[i & 1][j + 1][(k + even[i]) % 11] = add(
                dp1[i & 1][j + 1][(k + even[i]) % 11], dp1[(i - 1) & 1][j][k]);
            dp1[i & 1][j][(k - even[i] + 11) % 11] = add(
                dp1[i & 1][j][(k - even[i] + 11) % 11], dp1[(i - 1) & 1][j][k]);
          }
        }
        for (j = 0; j <= even_sz; j++) {
          for (k = 0; k < 11; k++) dp1[(i - 1) & 1][j][k] = 0;
        }
      }
    }
    if (even_sz == 0) {
      cout << store[0] << "\n";
      continue;
    }
    if (odd_sz == 0) {
      cout << mul(dp1[(even_sz - 1) & 1][even_sz][0], fact[n]) << "\n";
      continue;
    }
    ans = 0;
    for (i = 0; i < 11; i++) {
      for (j = 0; j < 11; j++) {
        if ((i + j) % 11) continue;
        for (k = 0; k <= even_sz; k++) {
          x = store[i];
          y = dp1[(even_sz - 1) & 1][k][j];
          if (x == 0 || y == 0) continue;
          pos1 = odd_sz / 2 + 1;
          pos2 = (odd_sz + 1) / 2;
          z = mul(
              x,
              mul(y, mul(ncr(pos1 + k - 1, pos1 - 1),
                         mul(fact[k], mul(ncr(pos2 + even_sz - k - 1, pos2 - 1),
                                          fact[even_sz - k])))));
          ans = add(ans, z);
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
