$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.

Difficulty: MEDIUM

Solutions:
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)


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)


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)


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))


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 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()


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)


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 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()


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 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)