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: import java.util.*;
  import java.io.*;
  
  public class C {
  
      public void prayGod() throws IOException {
          int t = nextInt();
          while (t-- > 0) {
              int n = nextInt();
              int[] a = nextIntArray(n);
  
              long[] fact = new long[n + 1];
              long[] invFact = new long[n + 1];
              long[] inv = new long[n + 1];
  
              fact[0] = fact[1] = 1;
              inv[1] = invFact[0] = invFact[1] = 1;
  
              for (int i = 2; i <= n; i++) {
                  fact[i] = (fact[i - 1] * i) % mod;
                  inv[i] = mod - (mod / i) * inv[(int) mod % i] % mod;
                  invFact[i] = invFact[i - 1] * inv[i] % mod;
              }
  
              if (n == 1) {
                  out.println(1);
                  continue;
              }
  
              sort(a);
              int minDelta = iinf, countMax = 0;
  
              for (int i = 0; i < n - 1; i++) {
                  minDelta = Math.min(minDelta, a[n - 1] - a[i]);
              }
  
              for (int i = n - 1; i >= 0; i--) {
                  if (a[i] == a[n - 1])
                      countMax++;
              }
  
              if (minDelta > 1) {
                  out.println(0);
                  continue;
              }
  
              if (countMax > 1) {
                  out.println(fact[n]);
                  continue;
              }
  
              int lowPool = 0;
              for (int i = 0; i < n; i++) {
                  if (a[i] <= a[n - 1] - 2)
                      lowPool++;
              }
  
              long ret = fact[n];
  
              // out.println(lowPool);
  
              for (int i = lowPool; i >= 0; i--) {
                  long right = i != 0 ? (fact[lowPool] * invFact[lowPool - i] % mod) : 1;
                  long left = fact[n - i - 1];
                  long total = (left * right) % mod;
                  // out.printf("%d %d %d %d\n", i, left, right, total);
                  ret = (ret - total + mod) % mod;
              }
  
              out.println(ret);
  
          }
      }
  
      public void printVerdict(boolean verdict) {
          if (verdict)
              out.println(VERDICT_YES);
          else
              out.println(VERDICT_NO);
      }
  
      static final String VERDICT_YES = "YES";
      static final String VERDICT_NO = "NO";
      static final boolean RUN_TIMING = true;
      static final boolean AUTOFLUSH = false;
      static final boolean FILE_INPUT = false;
      static final boolean FILE_OUTPUT = false;
  
      static int iinf = 0x3f3f3f3f;
      static long inf = (long) 1e18 + 10;
      static long mod = (long) 998244353;
  
      static char[] inputBuffer = new char[1 << 20];
      static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1 << 20);
      static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), AUTOFLUSH);
  
      // int data-type
      public int nextInt() throws IOException {
          return Integer.parseInt(next());
      }
  
      public int[] nextIntArray(int n) throws IOException {
          int[] arr = new int[n];
          for (int i = 0; i < n; i++)
              arr[i] = nextInt();
          return arr;
      }
  
      public void sort(int[] a) {
          shuffle(a);
          Arrays.sort(a);
      }
  
      public static void printArray(int[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      // long data-type
      public long nextLong() throws IOException {
          return Long.parseLong(next());
      }
  
      public long[] nextLongArray(int n) throws IOException {
          long[] arr = new long[n];
          for (int i = 0; i < n; i++)
              arr[i] = nextLong();
          return arr;
      }
  
      public static void printArray(long[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      public void sort(long[] a) {
          shuffle(a);
          Arrays.sort(a);
      }
  
      // double data-type
      public double nextDouble() throws IOException {
          return Double.parseDouble(next());
      }
  
      public double[] nextDoubleArray(int n) throws IOException {
          double[] arr = new double[n];
          for (int i = 0; i < n; i++)
              arr[i] = nextDouble();
          return arr;
      }
  
      public static void printArray(double[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      // Generic type
      public <T> void sort(T[] a) {
          shuffle(a);
          Arrays.sort(a);
      }
  
      public static <T> void printArray(T[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      public String next() throws IOException {
          int len = 0;
          int c;
          do {
              c = in.read();
          } while (Character.isWhitespace(c) && c != -1);
          if (c == -1) {
              throw new NoSuchElementException("Reached EOF");
          }
          do {
              inputBuffer[len] = (char) c;
              len++;
              c = in.read();
          } while (!Character.isWhitespace(c) && c != -1);
          while (c != '\n' && Character.isWhitespace(c) && c != -1) {
              c = in.read();
          }
          if (c != -1 && c != '\n') {
              in.unread(c);
          }
          return new String(inputBuffer, 0, len);
      }
  
      public String nextLine() throws IOException {
          int len = 0;
          int c;
          while ((c = in.read()) != '\n' && c != -1) {
              if (c == '\r') {
                  continue;
              }
              inputBuffer[len] = (char) c;
              len++;
          }
          return new String(inputBuffer, 0, len);
      }
  
      public boolean hasNext() throws IOException {
          String line = nextLine();
          if (line.isEmpty()) {
              return false;
          }
          in.unread('\n');
          in.unread(line.toCharArray());
          return true;
      }
  
      public void shuffle(int[] arr) {
          int n = arr.length;
          for (int i = 0; i < n; i++) {
              int j = (int) (Math.random() * (n - i));
              int temp = arr[i];
              arr[i] = arr[j];
              arr[j] = temp;
          }
      }
  
      public void shuffle(long[] arr) {
          int n = arr.length;
          for (int i = 0; i < n; i++) {
              int j = (int) (Math.random() * (n - i));
              long temp = arr[i];
              arr[i] = arr[j];
              arr[j] = temp;
          }
      }
  
      public void shuffle(Object[] arr) {
          int n = arr.length;
          for (int i = 0; i < n; i++) {
              int j = (int) (Math.random() * (n - i));
              Object temp = arr[i];
              arr[i] = arr[j];
              arr[j] = temp;
          }
      }
  
      public static void main(String[] args) throws IOException {
          if (FILE_INPUT)
              in = new PushbackReader(new BufferedReader(new FileReader(new File("output.txt"))), 1 << 20);
          if (FILE_OUTPUT)
              out = new PrintWriter(new FileWriter(new File("output.txt")));
  
          long time = 0;
          time -= System.nanoTime();
          new C().prayGod();
          time += System.nanoTime();
  
          if (RUN_TIMING)
              System.err.printf("%.3f ms%n", time / 1000000.0);
  
          out.flush();
          in.close();
      }
  }