#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000,1000000000")
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (int i = 0; i < (int)vec.size(); ++i) is >> vec[i];
  return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < (int)vec.size(); ++i) os << vec[i] << " ";
  return os;
}
template <class T>
istream& operator>>(istream& is, pair<T, T>& a) {
  is >> a.first >> a.second;
  return is;
}
const double pi = acos(-1.0);
const long long mod = 998244353;
const long long INF = 2e18;
const int inf = (int)1e9 + 7;
const int maxlen = (int)1e5 + 100;
const double eps = 1e-7;
long long binpow(long long a, long long n) {
  int res = 1;
  while (n) {
    if (n & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    n >>= 1;
  }
  return res;
}
long long del(long long a, long long b) {
  long long d = binpow(b, mod - 2);
  return (a * d) % mod;
}
void solve() {
  int n;
  cin >> n;
  int mx = -1, mx_n, mn_n = -1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a > mx) {
      if (a == mx + 1) {
        mn_n = mx_n;
      } else
        mn_n = 0;
      mx = a;
      mx_n = 0;
    }
    if (a == mx) mx_n++;
    if (a == mx - 1) mn_n++;
  }
  if (mx_n == 1 && mn_n == 0) {
    cout << 0 << endl;
    return;
  }
  if (mx_n > 1) {
    long long fact = 1;
    for (int i = 2; i <= n; i++) {
      fact = (fact * i) % mod;
    }
    cout << fact << endl;
    return;
  }
  long long fact = 1;
  vector<long long> f(n + 1);
  f[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact = (fact * i) % mod;
    f[i] = fact;
  }
  long long sum = 0;
  for (int i = mn_n; i <= n - 1; i++) {
    long long jopa = del(f[i], f[i - mn_n]);
    jopa = (jopa * f[n - mn_n - 1]) % mod;
    sum = (sum + jopa) % mod;
  }
  sum = (f[n] + mod - sum) % mod;
  cout << sum << endl;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
