#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
const long long mod = 998244353;
vector<long long> fact;
long long add(long long x, long long y) {
  x += y;
  if (x >= mod) return x - mod;
  return x;
}
long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) return x + mod;
  return x;
}
long long mult(long long x, long long y) { return (x * y) % mod; }
long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1ll) ans = (a * ans) % mod;
    a = (a * a) % mod;
    b >>= 1ll;
  }
  return ans;
}
void precal(long long n) {
  fact.assign(n, 0);
  fact[0] = fact[1] = 1;
  for (long long i = 2; i < n; i++) {
    fact[i] = mult(fact[i - 1], i);
  }
}
long long ncr(long long n, long long r) {
  if (n < r || n < 0 || r < 0) return 0;
  return mult(mult(fact[n], power(fact[r], mod - 2)),
              power(fact[n - r], mod - 2));
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (a[n - 1] == a[n - 2]) {
    cout << fact[n] << "\n";
    return;
  }
  if (a[n - 1] - a[n - 2] > 1) {
    cout << 0 << "\n";
    return;
  }
  long long ans = fact[n];
  long long small = 0;
  for (long long i = 0; i < n; i++) {
    if (a[n - 1] - a[i] == 1) small++;
  }
  ans -= (fact[n] * power(small + 1, mod - 2)) % mod;
  if (ans < 0) ans += mod;
  cout << ans << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  precal(200200);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
