description: n people gathered to hold a jury meeting of the upcoming competition, the i-th member of the jury came up with a_i tasks, which they want to share with each other.
  
  First, the jury decides on the order which they will follow while describing the tasks. Let that be a permutation p of numbers from 1 to n (an array of size n where each integer from 1 to n occurs exactly once).
  
  Then the discussion goes as follows:
  
    * If a jury member p_1 has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped. 
    * If a jury member p_2 has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped. 
    * ... 
    * If a jury member p_n has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped. 
    * If there are still members with tasks left, then the process repeats from the start. Otherwise, the discussion ends. 
  
  
  
  A permutation p is nice if none of the jury members tell two or more of their own tasks in a row. 
  
  Count the number of nice permutations. The answer may be really large, so print it modulo 998 244 353.
  
  Input
  
  The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
  
  The first line of the test case contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^5) — number of jury members.
  
  The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the number of problems that the i-th member of the jury came up with.
  
  The sum of n over all test cases does not exceed 2 ⋅ 10^5.
  
  Output
  
  For each test case, print one integer — the number of nice permutations, taken modulo 998 244 353.
  
  Example
  
  Input
  
  
  4
  2
  1 2
  3
  5 5 5
  4
  1 3 3 7
  6
  3 4 2 1 3 3
  
  
  Output
  
  
  1
  6
  0
  540
  
  Note
  
  Explanation of the first test case from the example:
  
  There are two possible permutations, p = [1, 2] and p = [2, 1]. For p = [1, 2], the process is the following:
  
    1. the first jury member tells a task; 
    2. the second jury member tells a task; 
    3. the first jury member doesn't have any tasks left to tell, so they are skipped; 
    4. the second jury member tells a task. 
  
  
  
  So, the second jury member has told two tasks in a row (in succession), so the permutation is not nice.
  
  For p = [2, 1], the process is the following:
  
    1. the second jury member tells a task; 
    2. the first jury member tells a task; 
    3. the second jury member tells a task. 
  
  
  
  So, this permutation is nice.
solution: #include <bits/stdc++.h>
  using namespace std;
  using namespace chrono;
  void _print(long long t) { cerr << t; }
  void _print(int t) { cerr << t; }
  void _print(string t) { cerr << t; }
  void _print(char t) { cerr << t; }
  void _print(long double t) { cerr << t; }
  void _print(double t) { cerr << t; }
  void _print(unsigned long long t) { cerr << t; }
  template <class T, class V>
  void _print(pair<T, V> p);
  template <class T>
  void _print(vector<T> v);
  template <class T>
  void _print(set<T> v);
  template <class T, class V>
  void _print(map<T, V> v);
  template <class T>
  void _print(multiset<T> v);
  template <class T, class V>
  void _print(pair<T, V> p) {
    cerr << "{";
    _print(p.first);
    cerr << ",";
    _print(p.second);
    cerr << "}";
  }
  template <class T>
  void _print(vector<T> v) {
    cerr << "[ ";
    for (T i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T>
  void _print(priority_queue<T> p) {
    cerr << "[ ";
    long long x = p.size();
    for (long long i = 0; i < x; i++) {
      long long top = p.top();
      _print(top);
      cerr << " ";
      p.pop();
    }
    cerr << "]";
  }
  template <class T>
  void _print(set<T> v) {
    cerr << "[ ";
    for (T i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T>
  void _print(multiset<T> v) {
    cerr << "[ ";
    for (T i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  template <class T, class V>
  void _print(map<T, V> v) {
    cerr << "[ ";
    for (auto i : v) {
      _print(i);
      cerr << " ";
    }
    cerr << "]";
  }
  long long gcd(long long a, long long b) {
    if (b > a) {
      return gcd(b, a);
    }
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }
  long long expo(long long a, long long b, long long mod) {
    long long res = 1;
    while (b > 0) {
      if (b & 1) res = (res * a) % mod;
      a = (a * a) % mod;
      b = b >> 1;
    }
    return res;
  }
  void extendgcd(long long a, long long b, long long *v) {
    if (b == 0) {
      v[0] = 1;
      v[1] = 0;
      v[2] = a;
      return;
    }
    extendgcd(b, a % b, v);
    long long x = v[1];
    v[1] = v[0] - v[1] * (a / b);
    v[0] = x;
    return;
  }
  long long mminv(long long a, long long b) {
    long long arr[3];
    extendgcd(a, b, arr);
    return arr[0];
  }
  long long mminvprime(long long a, long long b) { return expo(a, b - 2, b); }
  bool revsort(long long a, long long b) { return a > b; }
  void swap(int &x, int &y) {
    int temp = x;
    x = y;
    y = temp;
  }
  long long combination(long long n, long long r, long long m, long long *fact,
                        long long *ifact) {
    long long val1 = fact[n];
    long long val2 = ifact[n - r];
    long long val3 = ifact[r];
    return (((val1 * val2) % m) * val3) % m;
  }
  void google(int t) { cout << "Case #" << t << ": "; }
  vector<int> sieve(int n) {
    int *arr = new int[n + 1]();
    vector<int> vect;
    for (int i = 2; i <= n; i++)
      if (arr[i] == 0) {
        vect.push_back(i);
        for (long long j = (long long(i) * long long(i)); j <= n; j += i)
          arr[j] = 1;
      }
    return vect;
  }
  long long mod_add(long long a, long long b, long long m) {
    a = a % m;
    b = b % m;
    return (((a + b) % m) + m) % m;
  }
  long long mod_mul(long long a, long long b, long long m) {
    a = a % m;
    b = b % m;
    return (((a * b) % m) + m) % m;
  }
  long long mod_sub(long long a, long long b, long long m) {
    a = a % m;
    b = b % m;
    return (((a - b) % m) + m) % m;
  }
  long long mod_div(long long a, long long b, long long m) {
    a = a % m;
    b = b % m;
    return (mod_mul(a, mminvprime(b, m), m) + m) % m;
  }
  long long phin(long long n) {
    long long number = n;
    if (n % 2 == 0) {
      number /= 2;
      while (n % 2 == 0) n /= 2;
    }
    for (long long i = 3; i <= sqrt(n); i += 2) {
      if (n % i == 0) {
        while (n % i == 0) n /= i;
        number = (number / i * (i - 1));
      }
    }
    if (n > 1) number = (number / n * (n - 1));
    return number;
  }
  void precision(int a) { cout << setprecision(a) << fixed; }
  const int MOD = 998244353;
  void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;
    int mx = *max_element(a.begin(), a.end());
    int cmx = count(a.begin(), a.end(), mx);
    int k = count(a.begin(), a.end(), mx - 1);
    int ans = 1, sub = 1;
    for (long long i = 1; i <= n; ++i) {
      ans = ans * i % MOD;
      if (i != k + 1) sub = sub * i % MOD;
    }
    if (cmx == 1) ans = (ans - sub + MOD) % MOD;
    cout << ans << '\n';
  }
  int main() {
    freopen("________Error.txt", "w", stderr);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    auto start1 = high_resolution_clock::now();
    long long testCase;
    cin >> testCase;
    while (testCase--) solve();
    auto stop1 = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop1 - start1);
    cerr << "Time: " << duration.count() / 1000 << "\n";
  }
  