$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 \le t \le 10^4$) — the number of test cases.

The first line of the test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — number of jury members.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 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 \cdot 10^5$.


-----Output-----

For each test case, print one integer — the number of nice permutations, taken modulo $998\,244\,353$.


-----Examples-----

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:

the first jury member tells a task;

the second jury member tells a task;

the first jury member doesn't have any tasks left to tell, so they are skipped;

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:

the second jury member tells a task;

the first jury member tells a task;

the second jury member tells a task.

So, this permutation is nice.

Source: codeforces | Difficulty: MEDIUM
Tags: Combinatorics

Mathematics


Solutions:
mod = 998244353
mx = 2 * 10 ** 5 + 2
(fact, inv_fact) = ([0] * (mx + 1), [0] * (mx + 1))
fact[0] = 1
for i in range(mx):
	fact[i + 1] = fact[i] * (i + 1) % mod
inv_fact[-1] = pow(fact[-1], mod - 2, mod)
for i in reversed(range(mx)):
	inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod
for _ in range(int(input())):
	n = int(input())
	l = sorted(map(int, input().split()))
	if l[-1] - l[-2] > 1:
		print(0)
		continue
	elif l[-1] == l[-2]:
		print(fact[n])
	else:
		k = l.count(l[-2])
		print((fact[n] - fact[n] * fact[k] * inv_fact[k + 1]) % mod)


import sys
import os
import math
from io import BytesIO, IOBase
from collections import defaultdict, Counter, deque
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 998244353
pre = [1, 1]
inv = [1] * (2 * 10 ** 5 + 1)
inf = [1] * (2 * 10 ** 5 + 1)
for i in range(2, 2 * 10 ** 5 + 1):
	inv[i] = inv[mod % i] * (mod - mod // i) % mod
	inf[i] = inf[i - 1] * inv[i] % mod
	pre.append(pre[-1] * i % mod)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	if a[0] - a[1] == 0:
		print(pre[n])
		continue
	if a[0] - a[1] >= 2:
		print(0)
		continue
	c = Counter(a)
	ans = pre[n]
	cur = 0
	for j in range(c[a[1]], n):
		cur = (cur + pre[j] * inf[j - c[a[1]]] % mod) % mod
	cur = cur * pre[n - (1 + c[a[1]])] % mod
	print((ans - cur + mod) % mod)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from bisect import bisect_left as lower_bound, bisect_right as upper_bound

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def lebe():
	return list(map(int, input()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def joro(L):
	return ''.join(map(str, L))

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def tir(a, b, c):
	if 0 == c:
		return 1
	if len(a) <= b:
		return 0
	if c != -1:
		return tir(a, 1 + b, c + a[b]) or tir(a, b + 1, c - a[b]) or tir(a, 1 + b, c)
	else:
		return tir(a, 1 + b, a[b]) or tir(a, b + 1, -a[b]) or tir(a, 1 + b, -1)

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def tr(n):
	return n * (n + 1) // 2

def ti(x):
	import math
	if x >= 0:
		s = math.sqrt(x)
	if s * s == x:
		return 1
	return 0
boi = 998244353
fa = [0] * 1000007
fa[0] = 1
for i in range(1, 1000007):
	fa[i] = fa[i - 1] * i % boi

def pow(x, y, p):
	re = 1
	x = x % p
	while y > 0:
		if y % 2 != 0:
			re = re * x % p
		y = y // 2
		x = x * x % p
	return re

def mi(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	if n < r:
		return 0
	if r == 0:
		return 1
	return fa[n] * mi(fa[r], p) % p * mi(fa[n - r], p) % p % p

def iu():
	import re
	import sys
	input = sys.stdin.readline
	import math as my
	m = so()
	L = le()
	L.sort()
	if L[m - 1] - L[m - 2] > 1:
		print(0)
		return
	if m == 1:
		print(1)
	elif L[m - 1] == L[m - 2]:
		print(fa[m])
	else:
		nu = 0
		for i in range(m):
			if L[i] < L[m - 2]:
				nu += 1
		bec = fa[m]
		to = 0
		for i in range(nu + 1):
			xo = fa[m - i - 1] * ncr(nu, i, boi) % boi
			xo = xo * fa[i] % boi
			to = xo + to
		print((bec + boi - to) % boi)

def main():
	for i in range(so()):
		iu()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
mod = 998244353
for asdad in range(t):
	mx = 0
	mcnt = 0
	n = int(input())
	liste = [-1]
	for a in input().split():
		liste.append(int(a))
		mx = max(mx, int(a))
	mcnt = liste.count(mx)
	(p, b) = (1, 1)
	ans = 1
	if mcnt == 1:
		mcnt = liste.count(mx - 1)
		p = mcnt + 1
		b = mcnt
	for i in range(1, n + 1):
		if i == p:
			ans = ans * b % mod
		else:
			ans = ans * i % mod
	print(ans)


import math
M = 998244353
for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	m = max(a)
	print(math.factorial(len(a)) * (1 < a.count(m) or 1 - pow(a.count(m - 1) + 1, M - 2, M)) % M)


tst = int(input())
for _ in range(tst):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	m = max(arr)
	c = arr.count(m)
	k = arr.count(m - 1)
	mod = 998244353
	ans = 1
	sub = 1
	for i in range(1, n + 1):
		ans = ans * i % mod
		if i != k + 1:
			sub = sub * i % mod
	if c >= 2:
		print(ans % mod)
	else:
		print((ans - sub) % mod)


import sys
input = sys.stdin.buffer.readline
MOD = 998244353

def solve():
	A.sort()
	if A[N - 1] == A[N - 2]:
		return factorial[N]
	if A[N - 1] - A[N - 2] > 1:
		return 0
	k = 0
	for a in A:
		if a == A[N - 2]:
			k += 1
	bad = factorial[k] * factorial[N] % MOD * pow(factorial[k + 1], MOD - 2, MOD) % MOD
	return (factorial[N] - bad) % MOD

def compute_factorials(N=int(1000000.0)):
	fact = [1] * (N + 1)
	for i in range(2, N + 1):
		fact[i] = fact[i - 1] * i % MOD
	return fact
factorial = compute_factorials()
test_cases = int(input())
for test_case in range(test_cases):
	N = int(input())
	A = list(map(int, input().split()))
	print(solve())


fact = [1, 1]
for i in range(2, 2 * 10 ** 5 + 1):
	fact.append(fact[-1] * i % 998244353)

def main():
	global fact
	n = int(input())
	a = sorted(list(map(int, input().split())))
	if n == 1:
		print(1)
	elif a[-1] == a[-2]:
		print(fact[n])
	elif a[-1] == a[-2] + 1:
		t = a.count(a[-2])
		print((fact[n] - fact[n] * pow(fact[t + 1], -1, 998244353) * fact[t]) % 998244353)
	else:
		print(0)
for _ in range(int(input())):
	main()


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split(' ')
	max1 = -1
	k1 = 0
	max2 = -1
	k2 = 0
	for s in a:
		i = int(s)
		if i > max1:
			max2 = max1
			k2 = k1
			max1 = i
			k1 = 1
		elif i == max1:
			k1 = k1 + 1
		elif i < max1 and i > max2:
			max2 = i
			k2 = 1
		elif i == max2:
			k2 = k2 + 1
	if max2 == -1 or k1 > 1:
		ans = 1
		for j in range(1, n + 1):
			ans = ans * j % 998244353
		print(ans)
	elif max1 - max2 > 1:
		print(0)
	else:
		ans = k2
		for j in range(1, n + 1):
			if j != k2 + 1:
				ans = ans * j % 998244353
		print(ans)


def main():
	mod = 998244353
	max_n = 200005
	nCr = make_nCr_mod(max_n, mod)
	fact = [0] * (max_n + 1)
	fact[0] = 1
	for i in range(max_n):
		fact[i + 1] = fact[i] * (i + 1) % mod
	tc = ri()
	for i in range(tc):
		n = ri()
		a = ria()
		a = sorted(a)
		cnt = Counter(a)
		if a[-1] - a[-2] >= 2:
			wi(0)
			continue
		if cnt[a[-1]] >= 2:
			wi(fact[n])
		else:
			z = n - 1 - cnt[a[-1] - 1]
			galat = 0
			for i in range(z + 1):
				galat += nCr(z, i) * fact[i] * fact[n - 1 - i]
			wi((fact[n] - galat) % mod)

def rant():
	return 'AAAAAAAAAAAAAAAAARRRGHHHHHHHHHHHHHHHHHHHHHHHH'

def position_dict(arr):
	posn = {}
	for i in range(len(arr)):
		if arr[i] in posn:
			posn[arr[i]].append(i)
		else:
			posn[arr[i]] = [i]
	return posn

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def make_nCr_mod(max_n=2 * 10 ** 5, mod=10 ** 9 + 7):
	max_n = min(max_n, mod - 1)
	(fact, inv_fact) = ([0] * (max_n + 1), [0] * (max_n + 1))
	fact[0] = 1
	for i in range(max_n):
		fact[i + 1] = fact[i] * (i + 1) % mod
	inv_fact[-1] = pow(fact[-1], mod - 2, mod)
	for i in reversed(range(max_n)):
		inv_fact[i] = inv_fact[i + 1] * (i + 1) % mod

	def nCr_mod(n, r):
		res = 1
		while n or r:
			(a, b) = (n % mod, r % mod)
			if a < b:
				return 0
			res = res * fact[a] % mod * inv_fact[b] % mod * inv_fact[a - b] % mod
			n //= mod
			r //= mod
		return res
	return nCr_mod

class DisjointSetUnion:

	def __init__(self, n):
		self.parent = [*range(n + 1)]
		self.size = [1] * (n + 1)
		(self.min, self.max) = ([*range(n + 1)], [*range(n + 1)])
		self.count = n

	def get(self, a):
		if self.parent[a] == a:
			return a
		x = a
		while a != self.parent[a]:
			a = self.parent[a]
		while x != self.parent[x]:
			(self.parent[x], x) = (a, self.parent[x])
		return a

	def union(self, a, b):
		(a, b) = (self.get(a), self.get(b))
		if a != b:
			if self.size[a] > self.size[b]:
				(a, b) = (b, a)
			self.parent[a] = b
			self.size[b] += self.size[a]
			self.min[b] = min(self.min[a], self.min[b])
			self.max[b] = max(self.max[a], self.max[b])
			self.count -= 1

	def sz(self, a):
		return self.size[self.get(a)]

	def count_sets(self):
		return self.count

class SegmentTree:

	def __init__(self, data, default=0, func=max):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		stop += 1
		start += self._size
		stop += self._size
		res_left = res_right = self._default
		while start < stop:
			if start & 1:
				res_left = self._func(res_left, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res_right = self._func(self.data[stop], res_right)
			start >>= 1
			stop >>= 1
		return self._func(res_left, res_right)

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SparseTable:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, start, stop):
		depth = (stop + 1 - start).bit_length() - 1
		return self.func(self._data[depth][start], self._data[depth][stop + 1 - (1 << depth)])

	def __getitem__(self, idx):
		return self._data[0][idx]

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
import sys, os, io, copy

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from math import log2
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
starttime = datetime.datetime.now()
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
main()
endtime = datetime.datetime.now()
time = (endtime - starttime).total_seconds() * 1000
if os.path.exists('input.txt'):
	print('Time:', time, 'ms')


from sys import stdin
input = stdin.readline
mod = 998244353

def mul(a, b):
	return a % mod * (b % mod) % mod

def ncr(n, r):
	return mul(fact[n], mul(pow(fact[n - r], mod - 2, mod), pow(fact[r], mod - 2, mod)))
size = 2 * 10 ** 5 + 1
fact = [1]
for i in range(1, size):
	fact.append(mul(fact[-1], i))

def answer():
	(m1, m2) = (a[-1], a[-2])
	if m1 == m2:
		return fact[n]
	(x1, x2) = (a.count(a[-1]), a.count(a[-2]))
	if m1 - m2 > 1:
		return 0
	x = x1 + x2
	ans = mul(ncr(n, x), mul(x1, x2))
	ans = mul(ans, fact[x - 2])
	ans = mul(ans, x - 1)
	return mul(ans, fact[n - x])
for T in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	print(answer())


from collections import Counter
from math import factorial
mod = 998244353
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	a = max(arr)
	ans = Counter(arr)
	if ans[a] > 1:
		print(factorial(len(arr)) % mod)
	else:
		k = ans[a - 1]
		f = factorial(len(arr))
		print((f - f // (k + 1)) % mod)


from itertools import product
import itertools
import math
import sys
import heapq
from collections import deque
MOD = 1000000000007

def find(parent, i):
	if parent[i] != i:
		parent[i] = find(parent, parent[i])
	return parent[i]

def union(parent, rank, xx, yy):
	x = find(parent, xx)
	y = find(parent, yy)
	if rank[x] > rank[y]:
		parent[y] = x
	elif rank[y] > rank[x]:
		parent[x] = y
	else:
		parent[y] = x
		rank[x] += 1
ans = 0
K = int(sys.stdin.readline().strip())
x = 0
y = 0
for _ in range(K):
	n = int(sys.stdin.readline().strip())
	s = list(map(int, sys.stdin.readline().strip().split()))
	s.sort(reverse=True)
	if s[0] == s[1]:
		print(math.factorial(n) % 998244353)
	elif s[0] - s[1] > 1:
		print(0)
	else:
		k = 1
		for i in range(2, n):
			if s[i] == s[1]:
				k += 1
		print(math.factorial(n) * k // (k + 1) % 998244353)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 10 ** 16
md = 998244353

def nCr(com_n, com_r):
	if com_r < 0:
		return 0
	if com_n < com_r:
		return 0
	return fac[com_n] * ifac[com_r] % md * ifac[com_n - com_r] % md
n_max = 200005
fac = [1]
for i in range(1, n_max + 1):
	fac.append(fac[-1] * i % md)
ifac = [1] * (n_max + 1)
ifac[n_max] = pow(fac[n_max], md - 2, md)
for i in range(n_max - 1, 1, -1):
	ifac[i] = ifac[i + 1] * (i + 1) % md

def fs(aa):
	f = s = -1
	for a in aa:
		if a >= f:
			(f, s) = (a, f)
		elif a > s:
			s = a
	return (f, s)

def solve():
	n = II()
	aa = LI()
	(f, s) = fs(aa)
	if f == s:
		print(fac[n])
	elif f - s > 1:
		print(0)
	else:
		c = aa.count(s)
		ans = (fac[n] - fac[n] * pow(c + 1, md - 2, md) % md) % md
		print(ans)
for testcase in range(II()):
	solve()


from functools import lru_cache
M = 998244353
fs = [1, 1]

def factorial(n):
	while n >= len(fs):
		fs.append(fs[-1] * len(fs) % M)
	return fs[n]
for _ in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	if a[-1] == a[-2]:
		ans = factorial(n)
	elif a[-1] == a[-2] + 1:
		x = 1
		i = n - 2
		while i - 1 >= 0 and a[i - 1] == a[-2]:
			i -= 1
			x += 1
		ans = factorial(n) * x * pow(x + 1, -1, M)
	else:
		ans = 0
	print(ans % M)


from math import factorial
MOD = 998244353

def fact(n, skip):
	f = 1
	sub = 1
	for i in range(2, n + 1):
		f = f * i % MOD
		if i != skip:
			sub = sub * i % MOD
	return (f, sub)

def smart_fact(n):
	r = 1
	while n > 1:
		if n / MOD % 2 == 1:
			r = MOD - r
		r = r * factorial(n % MOD) % MOD
		n //= MOD
	return r

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		words = input().split(' ')
		jury = (int(i) for i in words)
		jury = sorted(jury, reverse=True)
		(first, second) = jury[:2]
		diff = first - second
		if diff == 0:
			(res, _) = fact(n, 0)
			print(res)
			continue
		if diff == 1:
			times = 1
			for t in jury[2:]:
				if second == t:
					times += 1
			(res, sub) = fact(n, times + 1)
			res = (res - sub + MOD) % MOD
			print(res)
			continue
		print(0)
main()


from __future__ import print_function
import math
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 998244353

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
mx = 1 + 2 * 10 ** 5
fac = [1] * mx
for i in range(1, mx):
	fac[i] = i * fac[i - 1] % mod
for _ in range(inp()):
	n = inp()
	l = inlt()
	l.sort()
	m = max(l)
	if l.count(m) > 1 or m - 1 in l:
		if l.count(m) > 1:
			print(fac[n])
		else:
			ans = fac[n]
			x = l.count(m - 1)
			minus = fac[x] * ncr(n, x + 1, mod) * fac[n - x - 1] % mod
			print((ans - minus + mod) % mod)
	else:
		print(0)


from collections import Counter
import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	a = list(set(a))
	a.sort()
	mod = 998244353
	if c[a[-1]] > 1:
		print(math.factorial(n) % mod)
	elif a[-1] - 1 != a[-2]:
		print(0)
	else:
		print(c[a[-2]] * math.factorial(n) // (c[a[-2]] + 1) % mod)


def sol():
	n = int(input())
	arr = [int(x) for x in input().split()]
	m = 998244353
	fact = (n + 1) * [0]
	fact[0] = 1
	for i in range(1, n + 1):
		fact[i] = fact[i - 1] * i % m
	if n == 1:
		return 1
	cnt = dict()
	maksi = 0
	for el in arr:
		cnt[el] = cnt.get(el, 0) + 1
		maksi = max(maksi, el)
	if cnt[maksi] != 1:
		return fact[n]
	if maksi - 1 not in cnt:
		return 0
	rozne = cnt[maksi - 1]
	inne = n - 1 - rozne
	lewa = 1
	ans = 0
	for i in range(n, rozne, -1):
		ans = (ans + fact[rozne + inne] * lewa) % m
		lewa = lewa * inne % m
		inne -= 1
	return (fact[n] - ans) % m

def main():
	for i in range(int(input())):
		print(sol())
main()


MOD = 998244353
fact = [1] * (2 * 10 ** 5 + 1)
for i in range(2, 2 * 10 ** 5 + 1):
	fact[i] = fact[i - 1] * i % MOD

def solve(n, arr):
	arr.sort(reverse=True)
	if arr[0] > arr[1] + 1:
		return 0
	if arr[0] == arr[1]:
		return fact[n]
	k = arr.count(arr[1])
	return fact[n] * k % MOD * pow(k + 1, MOD - 2, MOD) % MOD
import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


import os
import sys
from collections import *
from fractions import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
M = 998244353

def preNCR(n, r, p=M):
	num = 1
	den = 1
	ans = [1]
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
		ans.append(num * pow(den, p - 2, p) % p)
	return ans

def preFAC(n):
	ans = [1]
	for i in range(1, n + 1):
		ans.append(ans[-1] * i % M)
	return ans
for _ in range(Int()):
	n = Int()
	a = array()
	ans = 0
	a.sort()
	fac = preFAC(n)
	if a[-1] > a[-2]:
		right = len([i for i in a if a[-1] > 1 + i])
		ans = 0
		nCr = preNCR(right, right)
		for i in range(right + 1):
			here = nCr[i] * (fac[i] * fac[n - 1 - i]) % M % M
			ans = (ans + here) % M
	print((fac[n] - ans + M) % M)


LIM = 200005
MOD = 998244353
dp = [1] * LIM
for i in range(2, LIM):
	dp[i] = dp[i - 1] * i % MOD
inv = [0] * LIM
inv[-1] = pow(dp[-1], -1, mod=MOD)
for i in range(LIM - 2, -1, -1):
	inv[i] = inv[i + 1] * (i + 1) % MOD

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a[-1] - a[-2] > 1:
		print(0)
	else:
		if a[-1] == a[-2]:
			for i in range(1, n + 1):
				print(dp[n])
				return
		k = a.count(a[-2])
		ans = k * dp[n] * pow(k + 1, -1, mod=MOD) % MOD
		print(ans)
t = int(input())
for _ in range(t):
	solve()


import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		to = f(*args, **kwargs)
		if stack:
			return to
		else:
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						return to
					to = stack[-1].send(to)
	return wrappedfunc

class Graphs:

	def __init__(self):
		self.graph = graphDict(set)

	def add_edge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def dfs_utility(self, nodes, visited_nodes):
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes)

	def dfs(self, node):
		Visited = set()
		self.dfs_utility(i, Visited)

	def bfs(self, node, f_node):
		count = float('inf')
		visited = set()
		level = 0
		if node not in visited:
			queue.append([node, level])
			visited.add(node)
		flag = 0
		while queue:
			parent = queue.popleft()
			if parent[0] == f_node:
				flag = 1
				count = min(count, parent[1])
			level = parent[1] + 1
			for item in self.graph[parent[0]]:
				if item not in visited:
					queue.append([item, level])
					visited.add(item)
		return count if flag else -1

class Tree:

	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None

def inorder(node, lis):
	if node:
		inorder(node.left, lis)
		lis.append(node.data)
		inorder(node.right, lis)
	return lis

def leaf_node_sum(root):
	if root is None:
		return 0
	if root.left is None and root.right is None:
		return root.data
	return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return 0
	return max(hight(root.left), hight(root.right)) + 1

class UF:

	def __init__(self, N):
		self._id = list(range(N))
		self._count = N
		self._rank = [0] * N

	def find(self, p):
		id = self._id
		while p != id[p]:
			p = id[p] = id[id[p]]
		return p

	def count(self):
		return self._count

	def connected(self, p, q):
		return self.find(p) == self.find(q)

	def union(self, p, q):
		id = self._id
		rank = self._rank
		i = self.find(p)
		j = self.find(q)
		if i == j:
			return
		self._count -= 1
		if rank[i] < rank[j]:
			id[i] = j
		elif rank[i] > rank[j]:
			id[j] = i
		else:
			id[j] = i
			rank[i] += 1

	def __str__(self):
		return ' '.join([str(x) for x in self._id])

	def __repr__(self):
		return 'UF(' + str(self) + ')'

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0), []))

def p_sum(array):
	return list(itertools.accumulate(array))

def diophantine(a: int, b: int, c: int):
	(d, x, y) = extended_gcd(a, b)
	r = c // d
	return (r * x, r * y)

@bootstrap
def extended_gcd(a: int, b: int):
	if b == 0:
		(d, x, y) = (a, 1, 0)
	else:
		(d, p, q) = (yield extended_gcd(b, a % b))
		x = q
		y = p - q * (a // b)
	yield (d, x, y)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, **kwargs):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
mod = 998244353
for _ in range(int(inp())):
	n = int(inp())
	arr = list_inp(int)
	arr.sort(reverse=True)
	if arr[0] - arr[1] > 1:
		print(0)
	else:
		dic = collections.Counter(arr)
		if dic[arr[0]] > 1:
			tmp = 1
			for i in range(2, n + 1):
				tmp *= i
				tmp %= mod
			print(tmp % mod)
		else:
			l = dic[arr[1]]
			tmp = 1
			for i in range(2, n + 1):
				tmp *= i
				tmp %= mod
			tmp *= pow(l + 1, -1, mod)
			tmp *= pow(l, 1, mod)
			print(tmp % mod)


import itertools
from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import sys

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return list(map(str, input().strip()))

def grid(r, c):
	return [lint() for i in range(r)]
from collections import defaultdict, Counter, deque
import math
import heapq
from heapq import heappop, heappush
import bisect
from math import factorial, inf
from itertools import groupby
from itertools import permutations as comb

def gcd(a, b):
	while b:
		a %= b
		tmp = a
		a = b
		b = tmp
	return a

def lcm(a, b):
	return a // gcd(a, b) * b

def check_prime(n):
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def nCr(n, r):
	return fact(n) // (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def primefactors(n):
	num = 0
	while n % 2 == 0:
		num += 1
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			num += 1
			n = n // i
	if n > 2:
		num += 1
	return num

def ask(a, b, c):
	print(c, a, b, flush=True)
	n = I()
	return n

def linear_sieve(n):
	is_composite = [False] * n
	prime = []
	for i in range(2, n):
		if not is_composite[i]:
			prime.append(i)
		for j in prime:
			is_composite[i * j] = True
			if i % prime == 0:
				break
	return prime

def dfs(i, p, d):
	(a, tmp) = (0, 0)
	for j in d[i]:
		if j != p:
			a += 1
			tmp += dfs(j, i)
	if a == 0:
		return 0
	return tmp / a + 1

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n // i
	if n > 2:
		l.append(n)
	return l
d = []
primes = []
prim = [0] * (10 ** 5 + 1)

def sieve(n):
	for i in range(n):
		d.append(i)
	for i in range(2, n):
		if d[i] == i:
			prim[i] = 1
			primes.append(i)
		j = 0
		while j < len(primes) and primes[j] <= d[i] and (primes[j] * i < n):
			d[i * primes[j]] = primes[j]
			j += 1

def primeFactors(n):
	factors = []
	while n != 1:
		factors.append(d[n])
		n //= d[n]
	return factors

def func(a):
	b = 1
	res = 0
	for i in range(len(a) - 1, -1, -1):
		res += b * int(a[i])
		b *= 2
	return res
mod = 998244353
t = 1
t = I()
for _ in range(t):
	n = I()
	s = lint()
	s.sort()
	d = Counter(s)
	if s[n - 1] - s[n - 2] > 1:
		print(0)
	elif s[n - 1] != s[n - 2]:
		tmp = d[s[n - 2]]
		if n >= mod:
			print(0)
		else:
			res = 1
			for i in range(1, n + 1):
				if i == tmp + 1:
					continue
				if i == tmp:
					res = res * i % mod
				res = res * i % mod
			print(res % mod)
	else:
		print(factorial(n) % mod)


def factorial(n):
	ans = 1
	for k in range(2, n + 1):
		ans = ans * k % MOD
	return ans

def factorial_absent(n, absent):
	ans = 1
	for k in range(2, n + 1):
		if k != absent:
			ans = ans * k % MOD
	return ans
MOD = 998244353
TestCases = int(input())
for _ in range(TestCases):
	N = int(input())
	a = list(map(int, input().split()))
	mx = max(a)
	mx_count = a.count(mx)
	mx2_count = a.count(mx - 1)
	if mx_count > 1:
		print(factorial(N))
	elif mx2_count == 0:
		print(0)
	else:
		print((factorial(N) - factorial_absent(N, mx2_count + 1) + MOD) % MOD)


MOD = 998244353
for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input().split()]
	mx = max(arr)
	cmx = arr.count(mx)
	k = arr.count(mx - 1)
	ans = 1
	sub = 1
	for i in range(1, n + 1):
		ans = ans * i % MOD
		if i != k + 1:
			sub = sub * i % MOD
	if cmx == 1:
		ans = (ans - sub + MOD) % MOD
	print(ans)


def gcd(a, b):
	if a < b:
		(b, a) = (a, b)
	while a * b > 0:
		a %= b
		(b, a) = (a, b)
	return a

def candy(k, c):
	if gcd(k, c) > 1:
		return -1
	s = [1, 0]
	r = [c, k]
	q = [0]
	i = 2
	while r[i - 1] != 0:
		q.append(r[i - 2] // r[i - 1])
		s.append(s[i - 2] - s[i - 1] * q[i - 1])
		r.append(r[i - 2] - r[i - 1] * q[i - 1])
		i += 1
	return s[i - 2] % k

def sex(n, a):
	m = max(a)
	idx = a.index(m)
	okay = False
	for i in range(n):
		if i != idx and m - a[i] <= 1:
			okay = True
			break
	if not okay:
		return 0
	okay = False
	for i in range(idx + 1, n):
		if a[i] == m:
			okay = True
			break
	if okay:
		return fac[n]
	tot = 0
	for i in range(n):
		if a[i] == m - 1:
			tot += 1
	return (fac[n] - fac[n] * candy(p, tot + 1)) % p
p = 998244353
fac = [1] * 200001
for i in range(2, 200001):
	fac[i] = fac[i - 1] * i
	fac[i] %= p
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(sex(n, a))


def solve():
	n = int(input())
	a = sorted([int(i) for i in input().split()])
	mx = max(a)
	smx = 0
	for i in a:
		if i == mx - 1:
			smx += 1
	out = 1
	sub = 1
	mod = 998244353
	for i in range(1, n + 1):
		out = out * i % mod
		if smx + 1 != i:
			sub = sub * i % mod
	if a.count(max(a)) > 1:
		return out
	else:
		return (out - sub + mod) % mod
for _ in range(int(input())):
	print(solve())


def jc(n):
	t = 1
	for i in range(1, n + 1):
		t *= i
		t %= 998244353
	return t
for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	imax = max(l)
	if l.count(imax) != 1:
		print(jc(n))
	elif l.count(imax - 1) == 0:
		print(0)
	else:
		x = l.count(imax - 1)
		y = n - 1 - x
		j = jc(x)
		tmp = x + 2
		for i in range(y):
			j *= tmp + i
			j %= 998244353
		print((jc(n) - j) % 998244353)


mod = 998244353
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = 1
	for i in range(n):
		f = f * (i + 1) % mod
	a.sort()
	if a[-1] - a[-2] >= 2:
		print(0)
	elif a[-1] == a[-2]:
		print(f)
	else:
		i = n - 2
		while i >= 0 and a[i] == a[n - 2]:
			i -= 1
		c = n - 2 - i
		f = f * c % mod
		f = f * pow(c + 1, mod - 2, mod) % mod
		print(f)


M = 998244353
f = [1]
for i in range(1, 8 ** 6):
	f += (f[-1] * i % M,)
for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	print(f[len(a)] * (1 < a.count((m := max(a))) or 1 - pow(a.count(m - 1) + 1, M - 2, M)) % M)


mod = 998244353

def power(x, y, p):
	res = 1
	x = x % p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def modinv(n, p):
	return power(n, p - 2, p)

def ncr(n, r, p):
	if n < r:
		return 0
	if r == 0:
		return 1
	return fac[n] * modinv(fac[r], p) % p * modinv(fac[n - r], p) % p % p

def fun():
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	if a[n - 1] - a[n - 2] > 1:
		print(0)
		return
	if n == 1:
		print(1)
	elif a[n - 1] == a[n - 2]:
		print(fac[n])
	else:
		nu = 0
		for i in range(n):
			if a[i] < a[n - 2]:
				nu += 1
		ans = fac[n]
		to = 0
		for i in range(nu + 1):
			xo = fac[n - i - 1] * ncr(nu, i, mod) % mod
			xo = xo * fac[i] % mod
			to = (to + xo) % mod
		print((ans - to + mod) % mod)
fac = [0] * 200007
fac[0] = 1
for i in range(1, 200007):
	fac[i] = fac[i - 1] * i % mod
for _ in range(int(input())):
	fun()


import sys
input = sys.stdin.readline

def main():

	def extended_gcd(a, b):
		(s, old_s) = (0, 1)
		(r, old_r) = (b, a)
		while r:
			q = old_r // r
			(old_r, r) = (r, old_r - q * r)
			(old_s, s) = (s, old_s - q * s)
		return (old_r, old_s, (old_r - old_s * a) // b if b else 0)

	def modinv(a, m):
		(g, x, _) = extended_gcd(a % m, m)
		return x % m if g == 1 else None
	MOD = 998244353
	fact = [1]
	for x in range(1, 200005):
		fact.append(fact[-1] * x % MOD)

	def comb(n, r):
		modi = modinv(fact[r] * fact[n - r], MOD)
		return fact[n] * modi % MOD
	t = int(input())
	for _ in range(t):
		n = int(input())
		ar = list(map(int, input().split()))
		m = max(ar)
		if ar.count(m) > 1:
			print(fact[n])
		else:
			m2c = ar.count(m - 1)
			ans = 0
			for x in range(m2c, n):
				toadd = fact[x] * fact[n - x - 1] % MOD
				toadd *= comb(n - m2c - 1, x - m2c)
				ans += toadd % MOD
				ans %= MOD
			print((fact[n] - ans) % MOD)
main()


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left
mod = 998244353

def moduloinverse(a):
	return pow(a, mod - 2, mod)

def solve(we):
	n = iin()
	l = lin()
	l.sort()
	if l[-1] - l[-2] >= 2:
		print(0)
		return
	fac = [1]
	for i in range(1, n + 1):
		fac.append(fac[-1] * i % mod)
	if l[-1] == l[-2] or l[-1] == l[0]:
		print(fac[-1] % mod)
	else:
		t = l.count(l[-2])
		q = n - t - 1
		ans = fac[n - 1]
		for i in range(1, n - t):
			z = fac[n - 1 - i] * fac[q] % mod
			z = z * moduloinverse(fac[q - i]) % mod
			ans = (ans + z) % mod
		print((fac[n] - ans) % mod)
qwe = 1
qwe = iin()
for _ in range(qwe):
	solve(_ + 1)


mod = 998244353
from math import factorial
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = max(l)
	if l.count(m) > 1:
		print(factorial(n) % mod)
	else:
		k = l.count(m - 1)
		f = factorial(n)
		print((f - f // (k + 1)) % mod)


md = 998244353
T = int(input())
for t in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	m = max(arr)
	mc = arr.count(m)
	mcc = arr.count(m - 1)
	(ans, sub) = (1, 1)
	for i in range(1, n + 1):
		ans = ans * i % md
		if i != mcc + 1:
			sub = sub * i % md
	if mc == 1:
		ans = (ans - sub + md) % md
	print(ans)


from __future__ import division, print_function
import math
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return int(input())

def inps():
	return input().strip()

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
maxn = 998244353
N = 2 * 10 ** 5 + 10
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans
fac = [1, 1]
for i in range(2, 2 * 10 ** 5 + 100):
	fac.append(fac[i - 1] * i % maxn)
p = maxn
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
for _ in range(inp()):
	n = inp()
	l = inlt()
	s = l.copy()
	s.sort()
	if s[-1] - s[-2] > 1:
		print(0)
	else:
		mx = max(l)
		cnt = 0
		for i in range(n):
			if l[i] == mx:
				cnt += 1
		if cnt > 1:
			print(fac[n])
		else:
			cnt = 0
			for i in range(n):
				if mx - l[i] >= 2:
					cnt += 1
			ans = fac[n]
			for j in range(cnt + 1):
				ans = (ans - fac[n - j - 1] * (Binomial(cnt, j, maxn) * fac[j])) % maxn
			if ans % maxn > 0:
				print(ans % maxn)
			else:
				while ans % maxn < 0:
					ans += maxn
				print(ans % maxn)


import math
MOD = 998244353

def solve(arr):
	n = len(arr)
	max_val = max(arr)
	max_count = arr.count(max_val)
	prev_count = arr.count(max_val - 1)
	res = 1
	extra = 1
	for i in range(1, n + 1):
		res = res * i % MOD
		if i != prev_count + 1:
			extra = extra * i % MOD
	return res - (max_count == 1) * extra
for _ in '_' * int(input()):
	input()
	print(solve(sorted([*map(int, input().split())])) % 998244353)


def f(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i % 998244353
	return res

def g(a, b):
	res = 1
	for i in range(2, a + b + 1):
		if i != b:
			res = res * i % 998244353
	res = res * (b - 1) % 998244353
	return res
for t in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	mx = max(s)
	if n == 1:
		print(1 if mx <= 1 else 0)
	if s.count(mx) == 1:
		smx = [0, 0]
		for i in s:
			if i != mx:
				if i == smx[0]:
					smx[1] += 1
				else:
					smx = max(smx, [i, 1])
		if smx[0] == mx - 1:
			print(g(n - smx[1] - 1, smx[1] + 1))
		else:
			print(0)
	else:
		print(f(n))


mod = 998244353

def make_mod_mul(mod=10 ** 9 + 7):
	fmod_inv = 1.0 / mod

	def mod_mul(a, b, c=0):
		res = a * b + c - mod * int(fmod_inv * a * b + fmod_inv * c)
		if res >= mod:
			return res - mod
		elif res < 0:
			return res + mod
		else:
			return res
	return mod_mul
mod_mul = make_mod_mul(mod)

def mod_pow(x, y):
	if y == 0:
		return 1
	res = 1
	while y > 1:
		if y & 1 == 1:
			res = mod_mul(res, x)
		x = mod_mul(x, x)
		y >>= 1
	return mod_mul(res, x)
MAX = 200005
fact = [1]
for zz in range(1, MAX + 1):
	fact.append(mod_mul(fact[-1], zz))

def nCr(n, r):
	num = fact[n]
	den = mod_mul(fact[r], fact[n - r])
	return num * pow(den, mod - 2, mod) % mod
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	ans = 'yes'
	m = max(a)
	mm = a[0]
	for i in range(1, len(a)):
		if a[i] > mm and a[i] != m:
			mm = a[i]
	if a[-1] == a[-2]:
		print(fact[n])
	elif m - mm > 1:
		print(0)
	elif m == mm:
		print(fact[n])
	elif a[-1] == a[-2] and n == 2:
		print(2)
	else:
		k = 0
		for i in range(len(a)):
			if a[i] == mm:
				k += 1
		ans = fact[n]
		for i in range(k, n):
			ans = (ans + mod - nCr(i, i - k) * fact[k] * fact[n - k - 1]) % mod
		if n == 2:
			print(1)
		else:
			print(ans)


TC = int(input())
for test in range(TC):
	n = int(input())
	nums = list(map(int, input().split()))
	h = max(nums)
	countH = nums.count(h)
	if countH > 1:
		prod = 1
		for i in range(1, n + 1):
			prod = prod * i % 998244353
		print(prod)
	else:
		countN = nums.count(h - 1)
		if countN > 0:
			prod = countN
			for i in range(1, n + 1):
				if i != countN + 1:
					prod = prod * i % 998244353
			print(prod)
		else:
			print(0)


MOD = 998244353

def factorial(n):
	r = 1
	for i in range(2, n + 1):
		r = r * i % MOD
	return r

def f(a, b):
	r = 1
	for i in range(a, b + 1):
		r = r * i % MOD
	return r
from collections import Counter
from math import comb as comb

def solve(n, ais):
	ais.sort(reverse=True)
	freq = Counter(ais)
	max = ais[0]
	count_max = freq[max]
	if count_max > 1:
		return factorial(n)
	secmax = ais[1]
	if secmax + 1 < max:
		return 0
	count_secmax = freq[secmax]
	not_nice = f(count_max + count_secmax + 1, n) * factorial(count_secmax)
	return (MOD + factorial(n) - not_nice) % MOD
t = int(input())
for _ in range(t):
	n = int(input())
	ais = list(map(int, input().split()))
	print(solve(n, ais))


p = 998244353
t = int(input())
for xx in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr.sort()
	r = arr[-1]
	m = 0
	for i in range(n - 1, -1, -1):
		if arr[i] == r:
			m += 1
		else:
			break
	if m > 1:
		ans = 1
		for i in range(1, n + 1):
			ans = ans * i % p
		print(ans)
	elif arr[-1] - arr[-2] > 1:
		print(0)
	else:
		s = arr[-2]
		d = 0
		for i in range(n - 2, -1, -1):
			if arr[i] == s:
				d += 1
			else:
				break
		ans = 1
		for i in range(1, n + 1):
			if i == d + 1:
				ans = ans * d % p
			else:
				ans = ans * i % p
		print(ans)


m = int(998244353)
X = 2 * 10 ** 5
factorial = [1]
for k in range(1, X + 1):
	factorial.append(factorial[-1] * k % m)
t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	sorted_ls = sorted(ls)
	if sorted_ls[-1] - sorted_ls[-2] > 1:
		print(0)
	elif sorted_ls[-1] - sorted_ls[-2] == 0:
		print(factorial[n])
	else:
		total_possible = factorial[n]
		max_element = sorted_ls[-1]
		reduced = 0
		diff_greater_one = 0
		local_fac = [1]
		for i in range(1, n):
			x = local_fac[-1] * i % m
			local_fac.append(x)
		for k in range(n - 1):
			if max_element - sorted_ls[k] > 1:
				diff_greater_one += 1
		diff_one = n - 1 - diff_greater_one
		lk = [1]
		for k in range(1, diff_greater_one + 1):
			temp = lk[-1] * ((diff_greater_one - k + 1) % m) % m
			lk.append(temp)
		for k in range(diff_greater_one + 1):
			temp = local_fac[n - 1 - k] * lk[k] % m
			reduced += temp
		answer = (total_possible - reduced) % m
		print(answer)


from sys import stdin, stdout

def INPUT():
	return list((int(i) for i in stdin.readline().split()))

def inp():
	return stdin.readline()

def out(x):
	return stdout.write(x)
from math import *
from decimal import *
INT_MAX = 10 ** 13
mod = 998244353

def pow(a, n):
	res = 1
	while n:
		if n & 1:
			res = res * a % mod
		a = a * a
		a %= mod
		n >>= 1
	return res
for i in range(int(input())):
	n = int(input())
	f = 1
	for i in range(1, n + 1):
		f *= i
		f %= mod
	A = INPUT()
	count = {}
	for i in range(n):
		if A[i] in count:
			count[A[i]] += 1
		else:
			count[A[i]] = 1
	X = list(set(A))
	X.sort()
	if count[X[-1]] >= 2 or len(X) == 1:
		print(f)
		continue
	if X[-1] - X[-2] > 1:
		print(0)
		continue
	else:
		a = count[X[-2]]
		inv = pow(a + 1, mod - 2)
		print(a * f * inv % mod)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()
import bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10 ** 6
	n = random.randint(1, N)
	a = [random.randint(1, n) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print(inp)
			print('naive', a1)
			print('solve', a2)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = 1 << 63
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
alp = [chr(ord('a') + i) for i in range(26)]
show_flg = False
show_flg = True
ans = 0
mo = 998244353
f = [1]
n = 2 * 10 ** 5 + 1
for i in range(1, n + 1):
	f += (f[-1] * i % mo,)
for _ in range(I()):
	ans = 0
	n = I()
	a = LI()
	a.sort()
	if a[0] == a[-1]:
		ans = f[n]
	else:
		m = a.count(a[-1])
		s = a.count(a[-1] - 1)
		if m > 1:
			ans = f[n]
		elif a[-1] - 1 not in a:
			ans = 0
		else:
			ans = f[n] * s * pow(m + s, mo - 2, mo) % mo
	print(ans % mo)


MOD = 998244353

def fact(n: int) -> int:
	while len(fact.v) <= n:
		fact.v.append(fact.v[-1] * len(fact.v) % MOD)
	return fact.v[n]
fact.v = [1]

def inv(x: int) -> int:
	return pow(x, MOD - 2, MOD)

def comb(n: int, k: int) -> int:
	return fact(n) * inv(fact(k)) * inv(fact(n - k)) % MOD
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = max(a)
	c0 = a.count(x)
	if c0 > 1:
		print(fact(n))
	else:
		c1 = a.count(x - 1)
		if c1 == 0:
			print(0)
		else:
			print(comb(n, c1 + 1) * c1 * fact(c1) * fact(n - c1 - 1) % MOD)


from collections import Counter, deque
from sys import stdout
import time
from math import factorial, log

def mod_fac(e, s=1):
	p = 1
	for i in range(s, e + 1):
		p = p * i % mod
	return p

def main():
	n = int(input())
	a = list(sorted([int(i) for i in input().split()]))[::-1]
	mx = a[0]
	nmx = 0
	for i in range(n):
		el = a[i]
		if el == mx:
			nmx += 1
			if nmx > 1:
				print(mod_fac(n))
				return
		else:
			mxx = a[i]
			break
	if mxx < mx - 1:
		print(0)
		return
	k = a.count(mxx)
	print((mod_fac(n) - mod_fac(n, k + 2) * mod_fac(k)) % mod)
mod = 998244353
for t in range(int(input())):
	main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict, deque
import sys
import os, sys
from io import BytesIO, IOBase
from bisect import bisect, insort
from array import array
from math import factorial
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	ans = factorial(n)
	mod = 998244353
	if arr[-1] == arr[-2]:
		print(ans % mod)
	else:
		cnt = arr.count(arr[-1] - 1)
		ans -= ans // (cnt + 1)
		print(ans % mod)


D = 998244353
factorial = [1] * (2 * 10 ** 5 + 1)
for i in range(1, len(factorial)):
	factorial[i] = factorial[i - 1] * i % D
for _t in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	if n == 1:
		ans = 1
	else:
		c_max = a.count(a[-1])
		if c_max == 1:
			if a[-2] + 1 < a[-1]:
				ans = 0
			else:
				c_second_max = a.count(a[-2])
				ans = factorial[n]
				for i in range(c_second_max, n):
					ways = factorial[n - 1 - c_second_max] * pow(factorial[i - c_second_max], D - 2, D) % D * factorial[i] % D
					ans -= ways
		else:
			ans = factorial[n]
	print((ans % D + D) % D)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
p = 998244353
pre = [1]
for i in range(1, 2 * 10 ** 5 + 5):
	pre.append(pre[-1] * i % p)

def ncr(n, r, p):
	if r == 0:
		return 1
	x = pre[n]
	x1 = pre[r] * pre[n - r]
	x1 = pow(x1, p - 2, p)
	return x * x1 % p
while t:
	t -= 1
	n = inp()
	a = lis()
	a.sort()
	if a[-1] == a[-2]:
		print(pre[n])
		continue
	if a[-1] - a[-2] > 1:
		print(0)
		continue
	z = a[-2]
	c = a.count(z)
	tot = n - c - 1
	res = pre[n]
	ex = 0
	for i in range(tot + 1):
		fi = ncr(tot, i, p) * pre[c + tot - i] * pre[i]
		ex += fi
	res -= ex
	print(res % p)


from collections import Counter

def il():
	return list(map(int, input().split()))

def ii():
	return int(input())

def imi():
	return map(int, input().split())
p = 998244353
fac = [1] * 200007
for i in range(2, 200007):
	fac[i] = fac[i - 1] * i % p
t = ii()
for _ in range(t):
	n = ii()
	ar = il()
	co = Counter(ar)
	m1 = max(ar)
	if co[m1] > 1:
		print(fac[n])
		continue
	m2 = 0
	for i in ar:
		if i != m1:
			m2 = max(m2, i)
	if m1 - m2 > 1:
		print(0)
	else:
		y = co[m2]
		m = n - y - 1
		a = 1
		for b in range(n - m + 1, n + 1):
			a = a * b % p
		a = a * fac[y] % p
		print((p + fac[n] - a) % p)


def answer():
	from collections import Counter
	n = int(input())
	a = list(map(int, input().split()))
	mod = 998244353
	a.sort()
	M = a[-1]
	m = a[-2]
	if M - m > 1:
		print(0)
		return
	if M == m:
		tmp = 1
		for i in range(2, n + 1):
			tmp *= i
			tmp %= mod
		print(tmp % mod)
	else:
		c = Counter(a)
		tmp = 1
		for i in range(2, n + 1):
			tmp *= i
			tmp %= mod
		cm = c[m]
		tmp *= pow(1 + cm, -1, mod)
		tmp *= pow(cm, 1, mod)
		print(tmp % mod)
t = int(input())
for _ in range(t):
	answer()


from collections import defaultdict as dd
import sys
input = lambda : sys.stdin.readline().rstrip()

def solve(N, A):
	ans = 0
	MOD = 998244353
	num = dd(int)
	maxnum = 0
	for a in A:
		maxnum = max(maxnum, a)
		num[a] += 1
	if num[maxnum] >= 2:
		ans = 1
		for i in range(N):
			ans *= i + 1
			ans %= MOD
	elif num[maxnum - 1] > 0:
		n2 = num[maxnum - 1]
		p2 = 1
		for i in range(n2):
			p2 *= i + 1
			p2 %= MOD
		p1 = p2 * (n2 + 1) % MOD
		ans = (p1 - p2) % MOD
		nokori = 1
		for i in range(N - (n2 + 1)):
			nokori *= n2 + 2 + i
			nokori %= MOD
		ans = ans * nokori % MOD
	return ans
T = int(input())
for i in range(1, T + 1):
	N = int(input())
	A = list(map(int, input().split()))
	ans = solve(N, A)
	print(ans)


import sys
import math
input = sys.stdin.readline

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = {}
	m = 998244353
	mv = max(arr)
	smv = -1
	for i in range(n):
		if arr[i] not in cnt:
			cnt[arr[i]] = 0
		cnt[arr[i]] += 1
		if arr[i] < mv:
			smv = max(smv, arr[i])
	if smv == -1 or cnt[mv] >= 2:
		ans = 1
		for j in range(1, n + 1):
			ans *= j
			ans %= m
		return ans % m
	elif mv - smv == 1:
		num = cnt[smv]
		ans = 1
		inc = 1
		for j in range(1, n + 1):
			ans *= j
			ans %= m
			if j != num + 1:
				inc *= j
				inc %= m
		return (ans - inc) % m
	else:
		return 0
for _ in range(int(input())):
	print(main())


def fac(n, m):
	ans = 1
	for i in range(1, n + 1):
		ans = ans * i % m
	return ans
srd = int(input())
for fghj in range(srd):
	n = int(input())
	s = list(map(int, input().split()))
	s.sort(reverse=True)
	x = True
	for i in range(n - 1):
		if s[i] != s[0]:
			break
		if s[i] - s[i + 1] > 1:
			x = False
			break
	mf = 1
	sf = 0
	temp = s[0]
	for i in range(1, n):
		if s[i] == temp:
			mf += 1
		else:
			temp = s[i]
			break
	for i in range(1, n):
		if s[i] == temp:
			sf += 1
		elif temp > s[i]:
			break
	if not x and mf == 1:
		print(0)
		continue
	if mf > 1:
		print(fac(n, 998244353))
	else:
		print(int(int(fac(n, 998244353) - fac(n, 998244353 * (sf + 1)) / (sf + 1)) % 998244353))


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
mod = 10 ** 9 + 7
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	mod = 998244353
	if a[-1] - a[-2] >= 2:
		print(0)
		continue
	fact = [1]
	for i in range(1, n + 69):
		fact += [fact[-1] * i % mod]
	if a[-1] == a[-2]:
		print(fact[n])
		continue
	x = 0
	for i in a:
		if i == a[-2]:
			x += 1
	print(fact[n] * x * pow(x + 1, mod - 2, mod) % mod)


import sys
input = sys.stdin.readline
T = int(input())
mod = 998244353
cnb_max = 2 * 10 ** 5 + 10
kai = [1] * (cnb_max + 1)
rkai = [1] * (cnb_max + 1)
for i in range(cnb_max):
	kai[i + 1] = kai[i] * (i + 1) % mod
rkai[cnb_max] = pow(kai[cnb_max], mod - 2, mod)
for i in range(cnb_max):
	rkai[cnb_max - 1 - i] = rkai[cnb_max - i] * (cnb_max - i) % mod

def cnb(x, y):
	if y > x:
		return 0
	if x < 0:
		return 0
	if y < 0:
		return 0
	return kai[x] * rkai[y] * rkai[x - y] % mod

def npr(x, y):
	if y > x:
		return 0
	if x < 0:
		return 0
	if y < 0:
		return 0
	return kai[x] * rkai[x - y] % mod
for iii in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a[-1] >= a[-2] + 2:
		print(0)
		continue
	maxa = a[-1]
	cnt = a.count(maxa)
	if cnt >= 2:
		print(kai[n])
		continue
	mi = 0
	for i in range(n):
		if a[i] <= maxa - 2:
			mi += 1
	ans = kai[n]
	for k in range(1, n + 1):
		if n - k > mi:
			continue
		sub = 1
		sub *= npr(mi, n - k)
		sub = sub * kai[k - 1] % mod
		ans -= sub
		ans %= mod
	print(ans)


mod = 998244353
for _ in range(int(input())):
	ans = 1
	n = int(input())
	l = [int(i) for i in input().split()]
	num_max = max(l)
	count_max = l.count(num_max)
	count_premax = l.count(num_max - 1)
	if count_max > 1:
		for i in range(1, n + 1):
			ans = ans * i % mod
	elif count_premax == 0:
		ans = 0
	else:
		for i in range(1, n + 1):
			if i != count_premax + 1 and i != count_premax:
				ans = ans * i % mod
			if i == count_premax:
				ans = ans * i * i % mod
	print(ans)


def power(n, p, m):
	res = 1
	while p != 0:
		if p % 2 == 1:
			res = res * n % m
		p >>= 1
		n = n * n % m
	return res
fact = [1, 1]
mod = 998244353
for i in range(2, 200001):
	fact.append(fact[-1] * i % mod)
T = int(input())
for t in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if arr[0] == arr[1]:
		print(fact[N])
	elif arr[0] == arr[1] + 1:
		highest2 = arr.count(arr[1])
		ans = fact[highest2] * highest2 % mod
		ans = ans * fact[N] % mod
		ans = ans * power(fact[N - highest2 - 1], mod - 2, mod) % mod
		ans = ans * power(fact[highest2 + 1], mod - 2, mod) % mod
		ans = ans * fact[N - highest2 - 1] % mod
		print(ans)
	else:
		print(0)


import math
mod = 998244353
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a[-1] == a[-2]:
		ans = 1
		for j in range(1, n + 1):
			ans *= j
			ans %= mod
		print(ans)
	elif a[-1] - a[-2] >= 2:
		print(0)
	else:
		x = a.count(a[-2])
		ans = 1
		for j in range(1, n + 1):
			if j == x + 1:
				ans *= j - 1
			else:
				ans *= j
			ans %= mod
		print(ans)


from collections import defaultdict
div = 998244353

def factorial(n):
	p = 1
	for i in range(1, n + 1):
		p = p * i % div
	return p

def semi_factorial(n, q):
	p = 1
	for i in range(1, n + 1):
		if i == q + 1:
			p = p * q % div
		else:
			p = p * i % div
	return p

def solve(n, A):
	(max_a, min_a) = (max(A), min(A))
	d = defaultdict(int)
	for a in A:
		d[a] += 1
	if d[max_a] == 1:
		if d[max_a - 1] == 0:
			return 0
		return semi_factorial(n, d[max_a - 1]) % div
	return factorial(n) % div

def main():
	ans = []
	t = int(input())
	for _ in range(t):
		n = int(input())
		A = list(map(int, input().split(' ')))
		ans.append(solve(n, A))
	for a in ans:
		print(a)
main()


from math import *
k = 998244353
p = [1] * (2 * 10 ** 5 + 1)
for i in range(2, len(p)):
	p[i] = i % k * p[i - 1] % k

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

def mi(a, m):
	return power(a, m - 2, m)
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	if a.count(m) > 1:
		print(p[n])
	else:
		s = -1
		c = 0
		for i in a:
			if i != m and i > s:
				s = i
				c = 1
			elif i != m and i == s:
				c += 1
		if m - s > 1:
			print(0)
		else:
			m = p[n] * (c % k) * mi(c + 1, k) % k
			print(m)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
mod = 998244353

def fact(n):
	f = [1 for x in range(n + 1)]
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % mod
	return f
f = fact(200000)

def npr(n, r):
	result = f[n] * pow(f[n - r], mod - 2, mod) % mod
	return result
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	d = {}
	for i in range(n):
		if arr[i] in d:
			d[arr[i]] += 1
		else:
			d[arr[i]] = 1
	last = max(d)
	if d[last] > 1:
		sys.stdout.write(f'{f[n]}\n')
		continue
	if last - 1 not in d:
		sys.stdout.write(f'{0}\n')
		continue
	valid = f[n]
	invalid = 0
	l1 = d[last - 1]
	for i in range(l1 + 1, n + 1):
		invalid += npr(i - 1, l1)
		invalid %= mod
	invalid *= f[n - 1 - l1]
	invalid %= mod
	ans = valid % mod - invalid % mod + mod
	ans %= mod
	sys.stdout.write(f'{ans}\n')


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
fact = [1] * 200001
for i in range(1, 200001):
	fact[i] = fact[i - 1] * i
	fact[i] %= mod1
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	if l[-1] == l[-2]:
		print(fact[n])
		continue
	ans = 0
	cou = defaultdict(int)
	for i in range(n):
		cou[l[i]] += 1
	se = set(l)
	se = sorted(se)
	if se[-1] - se[-2] > 1:
		print(0)
		continue
	n1 = cou[l[-1] - 1]
	n2 = n - cou[l[-1] - 1] - 1
	cop = n2
	for i in range(n2 + 1):
		de = fact[cop - i] * fact[i] % mod1
		k = fact[cop] * fact[n2] * fact[n1] % mod1
		k *= pow(de, mod1 - 2, mod1)
		k %= mod1
		ans += k
		n1 += 1
		n2 -= 1
	print((fact[n] - ans) % mod1)


t = int(input())
for w in range(t):
	n = int(input())
	N = list(map(int, input().split()))
	firstMaximum = 0
	secondMaximum = 0
	for i in range(n):
		if N[i] > firstMaximum:
			secondMaximum = firstMaximum
			firstMaximum = N[i]
		elif N[i] > secondMaximum:
			secondMaximum = N[i]
	firstMaxCount = 0
	secondMaxCount = 0
	for i in range(n):
		if N[i] == firstMaximum:
			firstMaxCount += 1
		elif N[i] == secondMaximum:
			secondMaxCount += 1
	if firstMaxCount > 1:
		res = 1
		for i in range(1, n + 1):
			res *= i
			res %= 998244353
		print(res)
	elif firstMaximum != secondMaximum + 1:
		print(0)
	else:
		res = 1
		for i in range(1, n + 1):
			if i == secondMaxCount + 1:
				continue
			res *= i
			res %= 998244353
		res *= secondMaxCount
		res %= 998244353
		print(res)


import sys
import os.path
from collections import *
import math
import bisect
import heapq as hq
from fractions import Fraction
from random import randint
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
mod = 998244353
fact = [1] * 200005
for i in range(1, len(fact)):
	fact[i] = fact[i - 1] * i % mod

def power(x, y, m):
	if y == 0:
		return 1
	p = power(x, y // 2, m) % m
	p = p * p % m
	if y % 2 == 0:
		return p
	else:
		return x * p % m

def modInverse(a):
	return power(a, mod - 2, mod)

def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr.sort()
	if arr[-1] - arr[-2] > 1:
		print(0)
		return
	if arr[-1] == arr[-2]:
		print(fact[n])
		return
	res = 0
	x = arr.index(arr[-2])
	num = 1
	den = 1
	res = 0
	for i in range(x):
		num = num * (x - i) % mod
		den = den * (i + 1) % mod
		y = 1
		y = y * fact[n - (i + 2)] % mod
		y = y * fact[i + 1] % mod
		y = y * num % mod
		y = y * modInverse(den) % mod
		res = (res + y) % mod
	print((fact[n] - (fact[n - 1] + res) % mod + mod) % mod)
t = int(input())
while t:
	t -= 1
	solve()


mod = 998244353
N = 200005
f = [1] * N
rf = [1] * N

def a(n, k):
	return f[n] * rf[n - k] % mod

def main():
	from sys import stdin
	input = stdin.buffer.readline
	for i in range(1, N):
		f[i] = f[i - 1] * i % mod
	for i in range(2, N):
		rf[i] = (mod - mod // i * rf[mod % i] % mod) % mod
	for i in range(1, N):
		rf[i] = rf[i] * rf[i - 1] % mod
	for _ in range(int(input())):
		n = int(input())
		(*v,) = map(int, input().split())
		mx = mx2 = 0
		cnt = cnt2 = 0
		for x in v:
			if x > mx:
				mx2 = mx
				mx = x
				cnt2 = cnt
				cnt = 1
			elif x == mx:
				cnt += 1
			elif x > mx2:
				mx2 = x
				cnt2 = 1
			elif x == mx2:
				cnt2 += 1
		if cnt > 1:
			print(f[n])
		elif mx - mx2 == 1:
			t = 0
			for i in range(cnt2, n):
				t = (t + a(i, cnt2) * f[n - cnt2 - 1] % mod) % mod
			print((f[n] - t) % mod)
		else:
			print(0)
main()


big = 998244353
N = int(input())
for test in range(N):
	n = int(input())
	alpha = list(map(int, input().split()))
	maxx = max(alpha)
	count = 0
	for i in alpha:
		if i == maxx:
			count += 1
	if count > 1:
		ans = 1
		for i in range(1, n + 1):
			ans = ans * i % big
		print(ans)
	else:
		count2 = 0
		for i in alpha:
			if i == maxx - 1:
				count2 += 1
		ans = 1
		for i in range(1, n + 1):
			ans = ans * i % big
		temp = 1
		for i in range(1, n + 1):
			if i != count2 + 1:
				temp = temp * i % big
		if ans - temp < 0:
			print((ans - temp + big) % big)
		else:
			print(ans - temp)


import sys
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def li():
	return [int(i) for i in input().split()]

def lli(rows):
	return [li() for _ in range(rows)]

def si():
	return input()

def ii():
	return int(input())

def ins():
	return input().split()
facts = [1] * 200010
mod = 998244353
for i in range(2, 200010):
	facts[i] = facts[i - 1] * i % mod

def solve():
	n = II()
	a = LI()
	b = sorted(a)
	cb = b.count(b[-1])
	if cb > 1:
		return facts[n]
	else:
		p = b.count(b[-2])
		if b[-1] - b[-2] > 1:
			return 0
		if n == 2:
			return 1
		res = 1
		for i in range(p + 2, n + 1):
			res = res * i % mod
		return (facts[n] - res * facts[p] + mod) % mod

def main():
	for _ in range(II()):
		sys.stdout.write(str(solve()) + '\n')
main()


def cc(n):
	su = 1
	for i in range(1, n + 1):
		su *= i
		su %= 998244353
	return su
n = int(input())
for _ in range(n):
	nn = int(input())
	arr = [int(c) for c in input().split()]
	arr.sort(reverse=True)
	co = arr[0] - arr[1]
	if co > 1:
		print(0)
	elif co == 0:
		aa = cc(nn)
		print(int(aa))
	else:
		kk = arr.count(arr[0] - 1)
		aa = cc(nn)
		bb = cc(kk)
		for j in range(1, nn - kk):
			bb *= kk + 1 + j
			bb %= 998244353
		print(int(aa - bb) % 998244353)


mod = 998244353

def fact(n):
	numb = 1
	for i in range(1, n + 1):
		numb = numb * i % mod
	return numb

def fact1(n, k):
	numb = 1
	for i in range(1, n + 1):
		if i != k + 1:
			numb = numb * i % mod
	return numb
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a[-1] == a[-2]:
		print(fact(n))
	elif a[-1] > a[-2] + 1:
		print(0)
	else:
		k = a.count(a[-2])
		ans = fact1(n, k)
		ans *= k
		ans %= mod
		print(ans)


import math
from collections import Counter
MOD = 998244353
for _ in range(int(input())):
	N = int(input())
	A = sorted(list(map(int, input().split())))
	if A[-1] - A[-2] > 1:
		print(0)
		continue
	B = dict(Counter(A))
	ans = 1
	if A[-1] > A[-2]:
		c = B[A[-1] - 1]
		ans = math.factorial(c)
		ans *= c
		ans %= MOD
		c += 1
		for i in range(c + 1, N + 1):
			ans *= i
			ans %= MOD
	else:
		for i in range(N, 1, -1):
			ans *= i
			ans %= MOD
	print(ans)


import array
import bisect
import decimal
import fractions
import heapq
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def ints_get():
	return map(int, input().strip().split())

def list_get():
	return list(map(int, sys.stdin.readline().strip().split()))

def chars_get():
	return list(map(str, sys.stdin.readline().strip().split()))

def output(to_be_printed, end='\n'):
	sys.stdout.write(str(to_be_printed) + end)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list_get()
		a.sort()
		if a[n - 1] > a[n - 2] + 1:
			output(0)
		elif a[n - 1] == a[n - 2]:
			output(math.factorial(n) % 998244353)
		else:
			out = math.factorial(n)
			x = 1
			a.reverse()
			for i in range(2, n):
				if a[i] == a[1]:
					x += 1
				else:
					break
			out //= x + 1
			out *= x
			out %= 998244353
			output(out)
	return
main()


f = [0] * 200001
f[0] = 1
for i in range(1, 200001):
	f[i] = f[i - 1] * i % 998244353
for i in range(int(input())):
	n = int(input())
	a = sorted(map(int, input().split()))
	if a[-1] == a[-2]:
		print(f[n])
	elif a[-1] - a[-2] > 1:
		print(0)
	else:
		k = 0
		for i in a:
			if i == a[-1] - 1:
				k += 1
		z = 1
		for i in range(1, n + 1):
			if i == k + 1:
				continue
			z *= i
			z %= 998244353
		print((f[n] - z) % 998244353)


from sys import stdin
MOD = 998244353
fact = [1] * (2 * 10 ** 5 + 1)
for i in range(2, 2 * 10 ** 5 + 1):
	fact[i] = fact[i - 1] * i % MOD

def solve(a):
	a.sort(reverse=True)
	if a[0] > a[1] + 1:
		return 0
	elif a[0] == a[1]:
		return fact[n]
	k = a.count(a[1])
	return fact[n] * k % MOD * pow(k + 1, MOD - 2, MOD) % MOD
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	print(solve(a))


import math
fac = [1]
mod = 998244353
for i in range(1, 5 * 10 ** 5):
	val = fac[-1] % mod * i % mod
	val %= mod
	fac.append(val)

def nCr(a, b):
	second_val = fac[a - b] * fac[b]
	return pow(fac[a], 1, mod) * pow(second_val, -1, mod)

def main(arr):
	arr.sort()
	n = len(arr)
	if arr[-1] - arr[-2] > 2:
		return 0
	if arr[-1] - arr[-2] == 0:
		return fac[n]
	less = 0
	max_val = arr[-1]
	for e in arr:
		if e + 1 == max_val:
			less += 1
	ans = fac[n]
	for i in range(less, n):
		nums = n - i - 1
		val = nCr(n - less - 1, nums) * fac[nums] * fac[i] % mod
		ans -= val
	return ans % mod
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = main(arr)
	ans.append(s)
for e in ans:
	print(e)


MOD = 998244353
N = 200006
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
	fact[i] = fact[i - 1] * i % MOD
invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)
for i in range(N - 2, -1, -1):
	invfact[i] = invfact[i + 1] * (i + 1) % MOD

def nCk(n, k):
	if k < 0 or n < k:
		return 1
	else:
		return fact[n] * invfact[k] * invfact[n - k] % MOD

def nHk(n, k):
	return nCk(n + k - 1, k)
import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	maxist = -1
	secist = -1
	for i in range(n):
		maxist = max(maxist, a[i])
	sum = 0
	sux = 0
	for i in range(n):
		if a[i] == maxist:
			sum += 1
		else:
			secist = max(secist, a[i])
	for i in range(n):
		if a[i] == secist:
			sux += 1
	if sum > 1:
		print(fact[n])
		return
	if maxist - secist > 1:
		print(0)
		return
	ans = 0
	for i in range(0, n - sux):
		ans += fact[n - 1 - i] * fact[i] * nCk(n - sux - 1, i)
	print((fact[n] - ans) % MOD)
for _ in range(int(input())):
	main()


v = 2 * 10 ** 5 + 1
fact = [1] * v
mod = 998244353
for i in range(1, v):
	fact[i] = fact[i - 1] * i % mod
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	maxi = max(a)
	if maxi == 1:
		print(fact[n])
	elif a.count(maxi) > 1:
		print(fact[n])
	elif a.count(maxi - 1) == 0:
		print('0')
	else:
		smaxi = a.count(maxi - 1)
		ans = fact[n]
		t = smaxi + 1
		ans -= fact[n] * pow(fact[t], -1, mod) * fact[smaxi]
		print(ans % mod)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
import math as mt
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
mod = 998244353

def power(k, n):
	if n == 0:
		return 1
	if n % 2:
		return power(k, n - 1) * k % mod
	t = power(k, n // 2)
	return t * t % mod

def totalPrimeFactors(n):
	count = 0
	if n % 2 == 0:
		count += 1
		while n % 2 == 0:
			n //= 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			count += 1
			while n % i == 0:
				n //= i
		i += 2
	if n > 2:
		count += 1
	return count
N = 200001
factorialNumInverse = [-1] * (N + 1)
naturalNumInverse = [-1] * (N + 1)
fact = [1] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def ncr(n, r):
	p = mod
	ans = fact[n] * factorialNumInverse[r] % p * factorialNumInverse[n - r] % p
	return ans

def main():
	InverseofNumber(mod)
	InverseofFactorial(mod)
	for i in range(1, N):
		fact[i] = fact[i - 1] * i % mod
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		a.sort()
		maxx = a[-1]
		smax = -1
		for i in range(n - 1, -1, -1):
			if a[i] < maxx:
				smax = a[i]
				break
		if smax == -1 or a.count(maxx) > 1:
			print(fact[n])
		elif a[-1] - a[-2] >= 2:
			print(0)
		else:
			s = a.count(maxx)
			m = a.count(smax)
			ans = fact[m + s] * ncr(n, m + s) % mod
			for i in range(m - 1, n - s):
				t = ncr(i, m - 1) * ncr(n - (i + 1), s) % mod
				t = t * fact[m] % mod
				t = t * fact[s] % mod
				ans -= t
				ans = (ans + mod) % mod
			ans = ans * fact[n - m - s] % mod
			print(ans)
	return
main()


import math
import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, chain, combinations, groupby
from operator import itemgetter
from types import GeneratorType
from typing import Iterable, TypeVar, Union
MOD = 998244353

def modFact(n, p):
	if n >= p:
		return 0
	result = 1
	for i in range(1, n + 1):
		result = result * i % p
	return result

def inv(n, p):
	return pow(n, p - 2, p)
for _ in range(II()):
	n = II()
	a = LI()
	if a.count(max(a)) > 1:
		print(modFact(n, MOD))
		continue
	if max(a) - 1 not in a:
		print(0)
		continue
	c = a.count(max(a) - 1)
	print(modFact(n, MOD) * inv(c + 1, MOD) * c % MOD)


import os, sys, math
from io import BytesIO, IOBase
ip = lambda : input()
it = lambda : int(input())
ma = lambda : map(int, input().split(' '))
li = lambda : list(map(int, input().split(' ')))
mod = 10 ** 9 + 7
md = 998244353

def ncr(n):
	arr = [1] * (n + 1)
	for i in range(1, n + 1):
		arr[i] = arr[i - 1] * (n + 1 - i) // i
		arr[i] %= md
	return arr

def main():
	for _ in range(int(input())):
		n = it()
		a = li()
		d = dict()
		m = 1
		x = 1
		for i in range(2, n + 1):
			x = x * i % md
		for i in range(n):
			if a[i] > m:
				m = a[i]
			try:
				d[a[i]] += 1
			except KeyError:
				d[a[i]] = 1
		if d[m] > 1:
			print(x)
			continue
		if m - 1 not in d:
			print(0)
			continue
		y = 1
		for i in range(2, n + 1):
			if i == d[m - 1] + 1:
				continue
			y = y * i % md
		ans = x - y
		print(ans % md)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
MOD = 998244353
facto = dict()

def initFacto(N):
	facto[0] = 1
	facto[1] = 1
	for n in range(2, N + 1):
		facto[n] = n * facto[n - 1] % MOD

def insertRest(space, rest):
	ans = 1
	while rest:
		ans = ans * space % MOD
		rest -= 1
		space += 1
	return ans

def solve():
	N = int(input())
	nums = list(map(int, input().split()))
	uniq = list(set(nums))
	uniq.sort()
	first = uniq[-1]
	firstCnt = nums.count(first)
	all_cases = facto[N]
	if len(uniq) == 1 or firstCnt >= 2:
		print(all_cases)
		return
	second = uniq[-2]
	secondCnt = nums.count(second)
	if first - second != 1:
		print(0)
		return
	rest = N - 1 - secondCnt
	insertPt = secondCnt + 2
	ans = facto[secondCnt] * insertRest(insertPt, rest) % MOD
	print((all_cases - ans + MOD) % MOD)
T = int(input())
initFacto(int(2 * 100000.0))
for _ in range(T):
	solve()


import sys
input = sys.stdin.readline
mod = 998244353
l = 2 * pow(10, 5) + 5
fact = [1] * (l + 1)
for i in range(1, l + 1):
	fact[i] = i * fact[i - 1] % mod
inv = [1] * (l + 1)
inv[l] = pow(fact[l], mod - 2, mod)
for i in range(l - 1, -1, -1):
	inv[i] = (i + 1) * inv[i + 1] % mod

def comb(n, r):
	return fact[n] * inv[r] * inv[n - r] % mod if n >= r >= 0 else 0
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a[-2] + 1 < a[-1]:
		ans = 0
	elif a[-1] == a[-2]:
		ans = fact[n]
	else:
		c = a.count(a[-2])
		ans = fact[n]
		ans -= fact[c] * fact[n] % mod * inv[c + 1] % mod
		ans %= mod
	print(ans)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'
mod = 10 ** 9 + 7

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def mod_ncr(n, r, p):
	return fact[n] * pow(fact[r] * fact[n - r], p - 2, p) % p

def ispali(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True
mod = 998244353
fact = [1] * (3 * 10 ** 5)
for i in range(2, 3 * 10 ** 5):
	fact[i] = fact[i - 1] * i % mod

def main():
	ans = ''
	for _ in range(ii()):
		n = ii()
		arr = sorted(li())
		mx = arr[-1]
		if arr.count(mx) > 1:
			ans += str(fact[n]) + '\n'
		else:
			mx2 = arr[-2]
			if mx - mx2 > 1:
				ans += '0\n'
			else:
				x = fact[n]
				cnt_mx2 = arr.count(mx2)
				tmp = 0
				for i in range(n - 1, cnt_mx2 - 1, -1):
					tmp += mod_ncr(i, cnt_mx2, mod) % mod
				tmp %= mod
				tmp = fact[n - cnt_mx2 - 1] * fact[cnt_mx2] * tmp % mod
				ans += str((x - tmp) % mod) + '\n'
	print(ans)
main()


from sys import *
mod = 998244353
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if n == 1:
		stdout.write(str(0) + '\n')
		continue
	a.sort()
	mx = a[-1]
	cnt = a.count(mx)
	ans = 1
	for i in range(1, n + 1):
		ans = ans % mod * (i % mod) % mod
	if cnt > 1:
		stdout.write(str(ans) + '\n')
	elif a[-1] - a[-2] > 1:
		stdout.write(str(0) + '\n')
	else:
		cnt = a.count(a[-2])
		cnt += 1
		ans2 = 1
		for i in range(1, n + 1):
			if i == cnt:
				continue
			ans2 = ans2 % mod * (i % mod) % mod
		ret = (ans - ans2) % mod
		stdout.write(str(ret) + '\n')


mod = 998244353
preF = [1] * 200005
from collections import Counter
from math import factorial as fac
for i in range(1, len(preF)):
	preF[i] = preF[i - 1] * i % mod
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	c = Counter(a)
	m = max(a)
	a = sorted(list(set(a)))
	f = fac(n)
	if c[a[-1]] > 1:
		print(f % mod)
		continue
	if a[-1] - 1 != a[-2]:
		print(0)
		continue
	print(c[a[-2]] * (f // (c[a[-2]] + 1)) % mod)


mod = 998244353
import sys
input = sys.stdin.readline

def ncr(n, r):
	return fact[n] * pow(fact[r] * fact[n - r] % mod, mod - 2, mod) % mod
fact = [1, 1]
for i in range(2, 200002):
	fact.append(fact[-1] * i % mod)
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	if a.count(m) > 1:
		print(fact[n])
		continue
	c = a.count(m - 1)
	if c == 0:
		print(0)
		continue
	ans = fact[n]
	for i in range(c, n):
		ans -= ncr(i, c) * fact[c] * fact[n - c - 1] % mod
		ans = ans % mod
	print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
from random import randint as ri
mod = int(1000000000.0) + 7
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
nn = int(300000.0) + 1
f = 1
fact = [None] * nn
fact[0] = 1
for i in range(1, nn):
	f *= i
	f %= mod
	fact[i] = f
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	dic = Counter(arr)
	cur = max(arr)
	if dic[cur] >= 2:
		ans = fact[n]
	else:
		ct = 0
		for i in arr:
			if i == cur - 1:
				ct += 1
		if ct == 0:
			ans = 0
		else:
			ans = 0
			left = n
			for i in range(n):
				left -= 1
				if left >= ct:
					num = fact[left]
					den = fact[left - ct]
					g = gcd(num, den)
					num //= g
					den //= g
					val = pow(den, mod - 2, mod) * num % mod
					rem = n - ct - 1
					val *= fact[rem]
					val %= mod
					ans += val
					ans %= mod
			ans = fact[n] - ans
			ans %= mod
	print(ans)


(P, fac) = (998244353, [1])
for i in range(1, 2 ** 18):
	fac += [fac[-1] * i % P]
for _ in range(int(input())):
	(n, a) = (int(input()), list(map(int, input().split())))
	print(fac[n] * (a.count((m := max(a))) > 1 or 1 - pow(a.count(m - 1) + 1, P - 2, P) + P) % P)


T = 1
T = int(input())
while T:
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	i = 1
	if a[n - 1] - a[n - 2] > 1:
		print(0)
	else:
		seg_max = 0
		MOD = 998244353
		for i in range(n - 1):
			if a[i] == a[n - 2]:
				seg_max += 1
		if a[n - 1] == a[n - 2]:
			ans = 1
			for i in range(1, n + 1):
				ans = ans * i % MOD
			print(ans)
		else:
			ans = 1
			for i in range(1, n + 1):
				if i == seg_max + 1:
					ans = ans * seg_max % MOD
				else:
					ans = ans * i % MOD
			print(ans)
	T -= 1


import sys
inputt = sys.stdin.readline
printt = sys.stdout.write
import math
import functools
from collections import deque
import heapq
from queue import PriorityQueue

def get():
	return inputt().strip()

def gets():
	return inputt().split()

def getint():
	return int(inputt())

def getints():
	return map(int, inputt().split())
mod = 998244353

def fact(n):
	nn = 1
	for i in range(1, n + 1):
		nn *= i
		nn %= mod
	return nn

def div(n, k):
	x = 1
	y = 0
	z = 0
	w = 1
	(a, b) = (k, mod)
	while b != 0:
		c = a // b
		(x, y, z, w) = (z, w, x - c * z, y - c * w)
		(a, b) = (b, a % b)
	return n * x % mod
for _ in range(getint()):
	n = getint()
	a = list(getints())
	a.sort()
	m1 = a[-1]
	m2 = a[-2]
	delta = m1 - m2
	if delta == 0:
		print(fact(n))
	elif delta >= 2:
		print(0)
	else:
		k = a.count(m2)
		print(div(fact(n) * k, k + 1))


from sys import *
from math import *

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * power(den, p - 2, p) % p
mod = 998244353
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if n == 1:
		stdout.write(str(0) + '\n')
		continue
	a.sort()
	mx = a[-1]
	cnt = a.count(mx)
	ans = 1
	for i in range(1, n + 1):
		ans = ans % mod * (i % mod) % mod
	if cnt > 1:
		stdout.write(str(ans) + '\n')
	elif a[-1] - a[-2] > 1:
		stdout.write(str(0) + '\n')
	else:
		cnt = a.count(a[-2])
		cnt += 1
		ans2 = 1
		for i in range(1, n + 1):
			if i == cnt:
				continue
			ans2 = ans2 % mod * (i % mod) % mod
		ret = (ans - ans2) % mod
		stdout.write(str(ret) + '\n')


MOD = 998244353
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(max1, max2) = (0, 0)
	for i in a:
		if i >= max1:
			max2 = max1
			max1 = i
		elif i >= max2:
			max2 = i
	ans = 1
	if max1 != max2:
		if max1 > max2 + 1:
			print(0)
		else:
			count = 0
			for i in a:
				if i == max2:
					count += 1
			for i in range(1, n + 1):
				if i != count + 1:
					ans = ans * i % MOD
				else:
					ans = ans * count % MOD
			print(ans)
	else:
		for i in range(1, n + 1):
			ans = ans * i % MOD
		print(ans)


from collections import Counter

def modFact(n, p):
	if n >= p:
		return 0
	result = 1
	for i in range(1, n + 1):
		result = result * i % p
	return result
MOD = 998244353
for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	c = Counter(a)
	k = sorted(c.keys())
	if len(k) == 1:
		print(modFact(n, MOD))
	else:
		k1 = k[-1]
		v1 = c[k1]
		k2 = k[-2]
		v2 = c[k2]
		if v1 > 1:
			print(modFact(n, MOD))
		elif k1 - k2 > 1:
			print(0)
		else:
			ans = modFact(n, MOD) * v2 * pow(1 + v2, -1, MOD)
			print(ans % MOD)


def solve(n, tasks):
	mod_val = 998244353
	max1 = 0
	max2 = 0
	for t in tasks:
		if t > max1:
			max2 = max1
			max1 = t
		elif t > max2:
			max2 = t
	if max1 > max2 + 1:
		return 0
	if max1 == max2 + 1:
		count2 = tasks.count(max2)
		tot = get_factorial(n, mod_val)
		for i in range(n):
			if i >= count2:
				tmp = choose(n - count2 - 1, i - count2, mod_val) * get_factorial(n - i - 1, mod_val) % mod_val
				tmp = tmp * get_factorial(i, mod_val) % mod_val
				tot = (tot - tmp) % mod_val
		return tot
	res = get_factorial(n, mod_val)
	return res
fac_cache = {}
inv_fac_cache = {}
mod_val = 998244353

def invert_mod(i, mod_val):
	return pow(i, mod_val - 2, mod_val)

def choose(N, k, mod_val):
	if k == 0:
		return 1
	if k == N:
		return 1
	if k == 1:
		return N
	if k == N - 1:
		return N
	n_fac = get_factorial(N, mod_val)
	nk_inv_fac = get_inv_factorial(N - k, mod_val)
	k_inv_fac = get_inv_factorial(k, mod_val)
	res = n_fac * nk_inv_fac % mod_val
	res = res * k_inv_fac % mod_val
	return res

def get_factorial(N, mod_val):
	cached_res = fac_cache.get(N, None)
	if cached_res:
		return cached_res
	res = 1
	for i in range(2, N + 1):
		res = res * i % mod_val
		fac_cache[i] = res
	return res

def get_inv_factorial(k, mod_val):
	cached_res = inv_fac_cache.get(k, None)
	if cached_res:
		return cached_res
	res = 1
	for i in range(2, k + 1):
		res = res * invert_mod(i, mod_val) % mod_val
		inv_fac_cache[i] = res
	return res
import os
import io
import time
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input().decode().strip())
for t in range(T):
	n = int(input().decode().strip())
	tasks = [int(x) for x in input().decode().strip().split(' ')]
	res = solve(n, tasks)
	print(res)


M = 998244353

def solve(n, l):
	m = max(l)
	c1 = l.count(m)
	c2 = l.count(m - 1)
	(ans1, ans2) = (1, 1)
	for i in range(1, n + 1):
		ans1 = ans1 * i % M
		if i != c2 + 1:
			ans2 = ans2 * i % M
	if c1 >= 2:
		print(ans1)
	else:
		print((ans1 - ans2) % M)
t = int(input())
while t:
	n = int(input())
	l = [int(i) for i in input().split(' ')]
	solve(n, l)
	t -= 1


from math import factorial
t = int(input())
for _ in range(t):
	n = int(input())
	x = [int(j) for j in input().split()]
	histo = {}
	for i in x:
		if i in histo:
			histo[i] += 1
		else:
			histo[i] = 1
	first = max(x)
	second = first - 1
	qtd_first = histo[first]
	if qtd_first > 1:
		print(factorial(n) % 998244353)
	elif qtd_first == 1:
		if not second in histo:
			print(0)
		else:
			qtd_second = histo[second]
			if qtd_second == 1:
				print(factorial(n) // 2 % 998244353)
			else:
				print(factorial(n) // (qtd_second + 1) * qtd_second % 998244353)


import sys
from sys import stdin

def modfac(n, MOD):
	f = 1
	factorials = [1]
	for m in range(1, n + 1):
		f *= m
		f %= MOD
		factorials.append(f)
	inv = pow(f, MOD - 2, MOD)
	invs = [1] * (n + 1)
	invs[n] = inv
	for m in range(n, 1, -1):
		inv *= m
		inv %= MOD
		invs[m - 1] = inv
	return (factorials, invs)

def modnCr(n, r):
	return fac[n] * inv[n - r] * inv[r] % mod
mod = 998244353
(fac, inv) = modfac(500000, mod)
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	m = max(a)
	maxnum = 0
	mbxnum = 0
	for i in range(n):
		if a[i] == m:
			maxnum += 1
		elif a[i] == m - 1:
			mbxnum += 1
	if maxnum >= 2:
		ans = fac[n]
	elif mbxnum == 0:
		ans = 0
	else:
		rem = n - maxnum - mbxnum
		ans = fac[n] - modnCr(n, rem) * fac[rem] * fac[mbxnum]
	ANS.append(str(ans % mod))
print('\n'.join(ANS))


MOD = 998244353
fac = {0: 1, 1: 1}
for t in range(int(input())):
	n = int(input())
	problems = [int(i) for i in input().split()]
	m = max(problems)
	cm = problems.count(m)
	cs = problems.count(m - 1)
	ans = 1
	if cm > 1:
		for i in range(1, n + 1):
			ans = ans * i % MOD
		print(ans)
	elif cs == 0:
		print(0)
	else:
		for i in range(1, n + 1):
			if i != cs + 1:
				ans = ans * i % MOD
		print(cs * ans % MOD)


import sys
import getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
(yes, no) = ('YES', 'NO')
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def minus_one(arr):
	return [x - 1 for x in arr]

def minus_one_matrix(mrr):
	return [[x - 1 for x in row] for row in mrr]
p = 998244353
qrr = [1 for _ in range(2 * 10 ** 5 + 10)]
val = 1
for i in range(1, 2 * 10 ** 5 + 5):
	val = val * i % p
	qrr[i] = val

def factorial_mod_p(n, p):
	return qrr[n]

@functools.lru_cache(maxsize=2 * 10 ** 5 + 10)
def ncr_mod_p(n, r, p):
	num = factorial_mod_p(n, p)
	dem = factorial_mod_p(r, p) * factorial_mod_p(n - r, p)
	return num * pow(dem, p - 2, p) % p
p = 998244353
factorial_mod_p(2 * 10 ** 5 + 1, p)

def solve_(arr):
	p = 998244353
	if len(arr) == 1:
		return 1
	c = Counter(arr)
	maxarr = max(c)
	if c[maxarr] > 1:
		return factorial_mod_p(len(arr), p)
	if c[maxarr - 1] == 0:
		return 0
	k = c[maxarr - 1]
	r = len(arr) - k - 1
	a = factorial_mod_p(k + 1, p) - factorial_mod_p(k, p)
	b = factorial_mod_p(r, p)
	c = ncr_mod_p(r + k + 1, k + 1, p)
	log(k, r, a, b, c)
	return a * b * c % p
for case_num in range(int(input())):
	k = int(input())
	arr = list(map(int, input().split()))
	res = solve(arr)
	print(res)


import math
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	m = max(A)
	k = A.count(m - 1)
	ans = 1
	sub = 1
	for i in range(2, n + 1):
		ans = ans * i % 998244353
		if i != k + 1:
			sub = sub * i % 998244353
	if A.count(m) > 1:
		k = A.count(m - 1)
		ans = ans % 998244353
		print(ans)
	elif A.count(m - 1) == 0:
		print(0)
	else:
		ans = ans - sub
		ans = ans % 998244353
		print(ans)


import sys
from collections import Counter
input = sys.stdin.buffer.readline
MOD = 998244353
T = int(input())
for _ in range(T):
	n = int(input())
	f = [1] * (n + 1)
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % MOD
	nums = Counter(map(int, input().split()))
	nums = list(sorted(nums.items(), reverse=True))
	if len(nums) == 1 or nums[0][1] > 1:
		print(f[n])
	elif nums[0][0] - nums[1][0] > 1:
		print(0)
	else:
		res = (f[n] - f[n - 1]) % MOD
		m = n - 1 - nums[1][1]
		(a, b) = (1, n - 1)
		for r in range(m, 0, -1):
			(a, b) = (a * r % MOD, b - 1)
			res = (res - a * f[b]) % MOD
		print(res)


for j in range(int(input())):
	n = int(input())
	mas_sort = list(map(int, input().split()))
	mas_sort = sorted(mas_sort)
	maximum = mas_sort[-1]
	count_maximums = mas_sort.count(maximum)
	count_premaximums = mas_sort.count(maximum - 1)
	result_normal = 1
	correction = 1
	for i in range(1, n + 1):
		result_normal = result_normal * i % 998244353
		if i != count_premaximums + 1:
			correction = correction * i % 998244353
	if count_maximums == 1:
		result_normal = (result_normal - correction + 998244353) % 998244353
	print(result_normal)


import os
import sys
from io import BytesIO, IOBase
_print = print
BUFSIZE = 8192

def dbg(*args, **kwargs):
	_print('\x1b[95m', end='')
	_print(*args, **kwargs)
	_print('\x1b[0m', end='')

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())
MAX_N = 3 * 10 ** 5
MOD = 998244353
MAX_N = min(MAX_N, MOD - 1)
fac = [1] * (MAX_N + 1)
for i in range(MAX_N):
	fac[i + 1] = fac[i] * (i + 1) % MOD
A000142 = fac.__getitem__
from heapq import nlargest

def solve():
	n = itg()
	arr = tuple(mpint())
	(b, a) = nlargest(2, arr)
	if a == b:
		return A000142(n)
	if b - a != 1:
		return 0
	m = arr.count(a)
	return A000142(n) * m % MOD * pow(m + 1, MOD - 2, MOD) % MOD

def main():
	for _ in range(itg()):
		print(solve())
DEBUG = 0
URL = 'https://codeforces.com/contest/1569/problem/C'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
else:
	if DEBUG != 2:
		dbg = lambda *args, **kwargs: ...
		(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	if DEBUG == 3:

		def print(*args, **kwargs):
			_print(*args, **kwargs)
			sys.stdout.flush()
	main()


import sys

def readnum():
	input = sys.stdin.readline
	a = list(map(int, input().split()))
	return a

def printf(val):
	sys.stdout.write(str(val) + '\n')

def power(a, b, mod):
	if b == 1:
		return a
	if b == 0:
		return 1
	ans = power(a, b // 2, mod)
	ans *= ans
	if b % 2:
		ans *= a
	ans = ans % mod
	return ans
t = readnum()[0]

def factorial(n, start, skip, mod):
	res = start
	for i in range(1, n + 1):
		if i == skip:
			continue
		res *= i
		res = res % mod
	return res
for _ in range(t):
	n = readnum()
	arr = readnum()
	(max_f, max_s) = (0, 0)
	for i in range(len(arr)):
		if arr[i] > max_f:
			max_s = max_f
			max_f = arr[i]
		elif arr[i] > max_s:
			max_s = arr[i]
	max_f_c = sum([max_f == i for i in arr])
	max_s_c = sum([max_s == i for i in arr])
	if max_f_c > 1:
		print(factorial(len(arr), 1, None, 998244353))
	elif max_f - max_s > 1:
		print(0)
	else:
		print(factorial(len(arr), max_s_c, max_s_c + 1, 998244353))


class BinomialCoefficient:

	def __init__(self, end, _mod):
		self.end = end
		self.mod = _mod
		self.factorial = self.get_fact()

	def inv_mod(self, num):
		return pow(num, self.mod - 2, self.mod)

	def get_fact(self):
		factorial = [1 for x in range(self.end)]
		for i in range(1, self.end):
			factorial[i] = factorial[i - 1] * i % self.mod
		return factorial

	def binomial_coefficient(self, n, k):
		return self.factorial[n] * pow(self.factorial[k], self.mod - 2, self.mod) * pow(self.factorial[n - k], self.mod - 2, self.mod) % self.mod

def func():
	big = max(a)
	if a.count(big) > 1:
		print(fact.factorial[n])
	else:
		k = a.count(big - 1)
		if k == 0:
			print(0)
		else:
			print((fact.factorial[n] - fact.factorial[n] * fact.inv_mod(k + 1)) % mod)
mod = 998244353
fact = BinomialCoefficient(end=2 * 10 ** 5 + 5, _mod=998244353)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	func()


import heapq, math
from collections import defaultdict, deque
from os import getcwd
from itertools import permutations
import sys, os.path
if os.path.exists('C:/Users/Dhanush/Desktop/cp/input.txt'):
	sys.stdout = open('C:/Users/Dhanush/Desktop/cp/output.txt', 'w')
	sys.stdin = open('C:/Users/Dhanush/Desktop/cp/input.txt', 'r')
input = sys.stdin.readline
mod = 998244353
N = 200001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)

def InverseofNumber(p):
	naturalNumInverse[0] = naturalNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p

def InverseofFactorial(p):
	factorialNumInverse[0] = factorialNumInverse[1] = 1
	for i in range(2, N + 1, 1):
		factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p

def factorial(p):
	fact[0] = 1
	for i in range(1, N + 1):
		fact[i] = fact[i - 1] * i % p

def Binomial(N, R, p):
	ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
	return ans

def isnice(l):
	i = 0
	prev = -1
	cnt = n
	while cnt > 0:
		if l[i] == 1:
			if prev == i:
				return False
			l[i] = 0
			cnt -= 1
			prev = i
		elif l[i] > 1:
			if prev == i:
				return False
			l[i] -= 1
			prev = i
		elif prev == i:
			return True
		i = (i + 1) % n
	return True
factarr = [1]
maxi = 2 * 10 ** 5
p = mod
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
res = 1
for i in range(1, maxi + 5):
	res = res * i % mod
	factarr.append(res)

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
tc = int(input())
for _ in range(tc):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	d = defaultdict(int)
	for i in l:
		d[i] += 1
	if l[-1] == l[-2]:
		print(factarr[n])
	elif l[-1] > l[-2] + 1:
		print(0)
	else:
		prev = l[-2]
		count = d[prev]
		ans = factarr[n]
		for i in range(count + 1, n + 1):
			c1 = factarr[i - 1]
			c2 = factarr[n - i]
			tot = c1 * c2 % mod
			tot = tot * Binomial(n - count - 1, i - count - 1, mod) % mod
			ans = (ans - tot + mod) % mod
		print(ans)


import heapq, math
from collections import defaultdict, deque
from os import getcwd
from itertools import permutations
import sys, os.path
if os.path.exists('C:/Users/Dhanush/Desktop/cp/input.txt'):
	sys.stdout = open('C:/Users/Dhanush/Desktop/cp/output.txt', 'w')
	sys.stdin = open('C:/Users/Dhanush/Desktop/cp/input.txt', 'r')
input = sys.stdin.readline
mod = 998244353
factarr = [1]
maxi = 2 * 10 ** 5
res = 1
for i in range(1, maxi + 5):
	res = res * i % mod
	factarr.append(res)

def power(a, n):
	r = 1
	while n:
		if n % 2 == 1:
			r = r * a % mod
		n = n // 2
		a = a * a % mod
	return r

def ncr(n, r, p):
	if r > n:
		return 0
	res = factarr[n]
	res = res * power(factarr[r], p - 2) % p
	res = res * power(factarr[n - r], p - 2) % p
	return res
tc = int(input())
for _ in range(tc):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	d = defaultdict(int)
	for i in l:
		d[i] += 1
	if l[-1] == l[-2]:
		print(factarr[n])
	elif l[-1] > l[-2] + 1:
		print(0)
	else:
		prev = l[-2]
		count = d[prev]
		ans = factarr[n]
		for i in range(count + 1, n + 1):
			c1 = factarr[i - 1]
			c2 = factarr[n - i]
			tot = c1 * c2 % mod
			tot = tot * ncr(n - count - 1, i - count - 1, mod) % mod
			ans = (ans - tot + mod) % mod
		print(ans)


for _ in range(int(input())):
	mod = 998244353
	n = int(input())
	arr = list(map(int, input().split()))
	max_arr = max(arr)
	count_mx = arr.count(max_arr)
	k = arr.count(max_arr - 1)
	res = 1
	tmp = 1
	for i in range(1, n + 1):
		res = res * i % mod
		if i != k + 1:
			tmp = tmp * i % mod
	if count_mx == 1:
		res = (res - tmp) % mod
	print(res % mod)


def fact(num, le):
	reply = 1
	for ind in range(le, num + 1):
		reply *= ind
		reply %= 998244353
	return reply
for _ in range(int(input())):
	size = int(input())
	arr = list(map(int, input().split()))
	mx = max(arr)
	(mx_am, pre_mx_am) = (arr.count(mx), arr.count(mx - 1))
	ans = fact(size, 1)
	if mx_am > 1:
		print(ans % 998244353)
	elif pre_mx_am == 0:
		print(0)
	else:
		bad_pos = fact(size, 2 + pre_mx_am)
		bp_1 = fact(pre_mx_am, 1)
		ans = (ans - bad_pos * bp_1 % 998244353 + 998244353) % 998244353
		print(ans)


import sys
input = sys.stdin.readline
from collections import *
MAX = 2 * 10 ** 5 + 100
MOD = 998244353
fact = [0] * MAX
inv = [0] * MAX
finv = [0] * MAX
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
	fact[i] = fact[i - 1] * i % MOD
	inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
	finv[i] = finv[i - 1] * inv[i] % MOD

def C(n, r):
	if n < r:
		return 0
	if n < 0 or r < 0:
		return 0
	return fact[n] * (finv[r] * finv[n - r] % MOD) % MOD
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if a[-1] - a[-2] >= 2:
		print(0)
		continue
	if a[-1] == a[-2]:
		print(fact[n])
		continue
	c = a.count(a[-2])
	print((fact[n] - C(n, c + 1) * fact[n - c - 1] * fact[c] % MOD) % MOD)


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

def SieveOfEratosthenes(n=10000):
	p = 2
	c = 0
	while p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				prime[i] = False
		p += 1

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

class LazySegUpdate:

	def __init__(self, N):
		self.N = N
		n = 4 * N
		self.tree = [0] * n
		self.lazy = [0] * n

	def queryHelper(self, index, s, e, l, r):
		if self.lazy[index]:
			update = self.lazy[index]
			self.lazy[index] = 0
			self.tree[index] = max(self.tree[index], update)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], update)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], update)
		if s > e or s > r or e < l:
			return 0
		if s >= l and e <= r:
			return self.tree[index]
		mid = (s + e) // 2
		return max(self.queryHelper(2 * index, s, mid, l, r), self.queryHelper(2 * index + 1, mid + 1, e, l, r))

	def updateHelper(self, index, s, e, l, r, h):
		if self.lazy[index]:
			update = self.lazy[index]
			self.lazy[index] = 0
			self.tree[index] = max(self.tree[index], update)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], update)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], update)
		if s > e or s > r or e < l:
			return
		if s >= l and e <= r:
			self.tree[index] = max(self.tree[index], h)
			if s != e:
				self.lazy[2 * index] = max(self.lazy[2 * index], h)
				self.lazy[2 * index + 1] = max(self.lazy[2 * index + 1], h)
			return
		mid = (s + e) // 2
		self.updateHelper(2 * index, s, mid, l, r, h)
		self.updateHelper(2 * index + 1, mid + 1, e, l, r, h)
		self.tree[index] = max(self.tree[2 * index], self.tree[2 * index + 1])

	def query(self, l, r):
		return self.queryHelper(1, 0, self.N - 1, l, r - 1)

	def update(self, l, r, h):
		self.updateHelper(1, 0, self.N - 1, l, r - 1, h)

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
modulo = 998244353

def fac(n):
	r = 1
	while n > 1:
		r = r * n % modulo
		n -= 1
	return r
for _ in ' ' * int(input()):
	n = int(input())
	a = sorted(map(int, input().split()))
	if a[-2] == a[-1]:
		print(fac(n))
	elif a[-2] + 1 == a[-1]:
		sb = a.count(a[-1] - 1)
		print(fac(n) * sb * pow(sb + 1, modulo - 2, modulo) % modulo)
	else:
		print(0)