You are given an array A of N integers . You want to convert the array A into a permutation of N integers. To do this, you can apply the following operation on array A exactly once .

Pick an integer X, where 1 ≤ X ≤ 2\cdot 10^{7}. For each i , 1 ≤ i ≤ N , replace A_{i} by A_{i} \% X.

Find out whether it is possible to convert A into a permutation of N integers. If it is possible, print YES (all uppercase alphabets) and any possible value of X for which it is possible. Otherwise, print NO (all uppercase alphabets).

Note - An array of N integers is called a permutation if it contains all integers from 1  to N exactly once.

------ Input Format ------ 

- The first line contains an integer T denoting the number of test cases. The T test cases then follow.
- The first line of each test case contains an integer N.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}.

------ Output Format ------ 

For each testcase, output the required answer in a single line. If an answer exists, print YES and an integer X (1 ≤ X ≤ 2 \cdot 10^{7}) separated by a single space. Otherwise, print NO.

Note that the strings are case-sensitive and must be in uppercase alphabets.

------ Constraints ------ 

$1 ≤ T ≤ 100$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 10^{7}$
- Sum of $N$ over all cases won't exceed $10^{5}$

------ subtasks ------ 

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------ 
2
3
2 7 1
2
2 2
----- Sample Output 1 ------ 
YES 4
NO
----- explanation 1 ------ 
- In the first case, choosing $X=4$ yields $A$ as $[ 2\% 4, 7\% 4 , 1\% 4] = [2,3,1]$ which is a permutation of $N=3$.
- In the second case, we can't make $A_{i}$ = $1$ for any $i$ and for any value of $X$.

Difficulty: VERY_HARD
Tags: Number theory

Mathematics

Starter code:

Solutions:
import math
import bisect

def check(x, l, n):
	if x < n:
		return 0
	sa = set({})
	for i in range(len(l)):
		b = l[i] % x
		if b > n or b == 0 or b in sa:
			return 0
		sa.add(b)
	return 1
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().strip().split()))
	s = sum(l) - n * (n + 1) // 2
	ans = -1
	for i in range(1, int(s ** (1 / 2)) + 1):
		if s % i == 0:
			if check(i, l, n):
				ans = i
				break
			if check(s // i, l, n):
				ans = s // i
				break
	visit = set()
	for i in l:
		if i >= 1 and i <= n:
			visit.add(i)
	if len(visit) == n:
		ans = n + 1
	if ans != -1:
		print('YES', ans)
	else:
		print('NO')


from sys import stdin
from bisect import bisect_left
inp = stdin.readline

def makePr(p_limit):
	track = [False, True] * (p_limit // 2 + 1)
	if p_limit % 2 == 0:
		track.pop()
	track[0:3] = [False, False, True]
	pc = 3
	while pc * pc <= p_limit:
		if track[pc]:
			for a in range(pc * pc, p_limit + 1, 2 * pc):
				track[a] = False
		pc += 2
	return [n for (n, p) in enumerate(track) if p]

def get_facs(val, prs, lim):
	facs = [1]
	if val < lim * lim:
		px_en = bisect_left(prs, lim)
	else:
		px_en = bisect_left(prs, (val + 1) ** 0.5)
	px = 0
	while px <= px_en:
		p = prs[px]
		if val % p == 0:
			pfac = [1, p]
			val //= p
			while val % p == 0:
				pfac.append(p * pfac[-1])
				val //= p
			facs = [f * pf for pf in pfac for f in facs]
			px_en = min(px_en, bisect_left(prs, (val + 1) ** 0.5))
		px += 1
	if val > 1:
		facs.extend([val * f for f in facs])
	return sorted(facs)

def check_opt(Ays, m, n, res):
	for a in Ays:
		am = a % m
		if am > n or am == 0 or res[am]:
			return False
		res[am] = True
	return True

def is_mod_perm(prs):
	N = int(inp())
	if N == 1:
		v = int(inp())
		if v == 1:
			v = 3
		return f'YES {v - 1}'
	Ays = sorted(map(int, inp().split()), reverse=True)
	if len(set(Ays)) < N:
		return 'NO'
	if Ays[0] == N:
		return f'YES {N + 1}'
	redsum = sum(Ays) - N * (N + 1) // 2
	res = [False] * (N + 1)
	while Ays[-1] <= N:
		res[Ays.pop()] = True
	X_lim = Ays[-1] - 1
	if X_lim == N:
		return 'NO'
	possm = get_facs(redsum, prs, X_lim)
	for m in possm:
		if m <= N:
			continue
		elif m > X_lim:
			break
		if check_opt(Ays, m, N, res.copy()):
			return f'YES {m}'
	return 'NO'
prs = makePr(1000000)
T = int(inp())
for tx in range(T):
	print(is_mod_perm(prs))


from sys import stdin
from bisect import bisect_left
inp = stdin.readline

def check_opt(Ays, m, n):
	res = set()
	for a in Ays:
		am = a % m
		if am > n or am == 0 or am in res:
			return False
		res.add(am)
	return True

def is_mod_perm():
	N = int(inp())
	if N == 1:
		v = int(inp())
		if v == 1:
			v = 3
		return f'YES {v - 1}'
	Ays = sorted(map(int, inp().split()))
	if len(set(Ays)) < N:
		return 'NO'
	if Ays[-1] == N:
		return f'YES {N + 1}'
	X_lim = Ays[bisect_left(Ays, N + 1)] - 1
	if X_lim == N:
		return 'NO'
	redsum = sum(Ays) - N * (N + 1) // 2
	hilo = int((redsum + 1) ** 0.5)
	if X_lim > hilo:
		min_cof = max(1, redsum // X_lim)
		for cnd in range(min_cof, hilo + 1):
			if redsum % cnd == 0:
				f = redsum // cnd
				if check_opt(Ays, f, N):
					return f'YES {f}'
	for cnd in range(N + 1, hilo + 1):
		if redsum % cnd == 0:
			if check_opt(Ays, cnd, N):
				return f'YES {cnd}'
	return 'NO'
T = int(inp())
for tx in range(T):
	print(is_mod_perm())


def check_valid(a, x):
	visit = set()
	for i in a:
		ok = i % x
		if ok > n or ok == 0 or ok in visit:
			return 0
		visit.add(ok)
	return 1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	total = sum(a)
	total -= n * (n + 1) // 2
	flag = 0
	for i in range(1, int(total ** 0.5) + 1):
		if total % i == 0:
			if check_valid(a, i):
				flag = 1
				result = i
				break
			if check_valid(a, total // i):
				flag = 1
				result = total // i
				break
	visit = set()
	for i in a:
		if i >= 1 and i <= n:
			visit.add(i)
	if len(visit) == n:
		flag = 1
		result = n + 1
	if flag:
		print('YES', result)
	else:
		print('NO')


def divisors(n):
	i = 1
	d = []
	while i * i <= n:
		if n % i == 0:
			d.append(i)
			if i * i != n:
				d.append(n // i)
		i += 1
	return sorted(d)
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if sorted(a) == [j for j in range(1, n + 1)]:
		print('YES', n + 1)
	else:
		s = sum(a)
		sn = n * (n + 1) // 2
		rs = s - sn
		f = 0
		if rs < 0:
			print('NO')
		else:
			d = divisors(rs)
			for i in d:
				if i > n:
					b = [x % i for x in a]
					if sorted(b) == [j for j in range(1, n + 1)]:
						f = 1
						ans = i
						break
			if f:
				print('YES', ans)
			else:
				print('NO')


def factor(x):
	f = []
	for i in range(1, int(x ** 0.5) + 1):
		if x % i == 0:
			f.extend([i, x // i])
	return f
for _ in range(int(input())):
	N = int(input())
	A = [int(x) for x in input().split()]
	P = set(list(range(1, N + 1)))
	sA = set(A)
	for a in A:
		if a in P:
			P.remove(a)
			sA.remove(a)
	S = sum((x for x in A))
	Q = S - N * (N + 1) // 2
	if not Q:
		print('YES', N + 1)
		continue
	factors = [x for x in factor(Q) if x > N]
	for f in factors:
		PP = set()
		for a in sA:
			if a % f in P:
				PP.add(a % f)
		if PP == P:
			print('YES', f)
			break
	else:
		print('NO')


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

def li():
	return list(mi())

def ni():
	return int(input())

def si():
	return str(input())

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
for t in range(ni()):
	N = ni()
	A = li()
	A.sort()
	if A == list(range(1, N + 1)):
		print('YES', N + 1)
		continue
	summ = sum(A) - N * (N + 1) // 2
	if summ < 0:
		print('NO')
		continue
	f = all_factors(summ)
	found = False
	for i in f:
		if i > 2 * 10 ** 7 or i < 1:
			break
		new = []
		for j in A:
			new.append(j % i)
		new.sort()
		if new == list(range(1, N + 1)):
			print('YES', i)
			found = True
			break
	if not found:
		print('NO')


from numpy import diff
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = set([i for i in range(1, n + 1)])
	ans = 0

	def check(i):
		return i >= n + 1 and set([x % i for x in a]) == p
	if set(a) == p:
		print('YES', n + 1)
	else:
		diff = sum(a) - n * (n + 1) // 2
		i = 1
		while i * i <= diff:
			if not diff % i:
				if check(i):
					ans = i
					break
				elif i != diff // i and check(diff // i):
					ans = diff // i
					break
			i += 1
		if ans:
			print('YES', ans)
		else:
			print('NO')


import sys
readline = sys.stdin.readline

def Divisors(N):
	divisors = []
	for i in range(1, N + 1):
		if i ** 2 >= N:
			break
		elif N % i == 0:
			divisors.append(i)
	if i ** 2 == N:
		divisors += [i] + [N // i for i in divisors[::-1]]
	else:
		divisors += [N // i for i in divisors[::-1]]
	return divisors

def main(N, A):
	X = sum(A) - (1 + N) * N // 2
	if X < 0:
		print('NO')
		return
	if len(set(A)) < N:
		print('NO')
		return
	if X == 0:
		print('YES', N + 1)
		return
	for d in Divisors(X):
		used = [False] * N
		for a in A:
			a %= d
			if 1 <= a <= N:
				used[a - 1] = True
		if used.count(True) == N:
			print('YES', d)
			return
	else:
		print('NO')
T = int(readline())
for _ in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	main(N, A)


from math import inf
from collections import *
import math, os, sys, heapq, bisect, random
from functools import lru_cache
from itertools import *

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def inpu():
	return int(inp())

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

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())
(M, M1) = (1000000007, 998244353)

def check(arr, n, mid):
	visited = [False] * (n + 1)
	for i in range(n):
		if arr[i] % mid == 0 or arr[i] % mid > n or visited[arr[i] % mid]:
			return False
		visited[arr[i] % mid] = True
	return True

def fact(x):
	res = set()
	for i in range(1, int(math.sqrt(x)) + 1):
		if x % i == 0:
			res.add(i)
			res.add(x // i)
	return res

def main():
	how_much_noob_I_am = 1
	how_much_noob_I_am = inpu()
	for __ in range(how_much_noob_I_am):
		n = inpu()
		arr = lis()
		s = sum(arr)
		p = n * (n + 1) // 2
		diff = s - p
		if diff == 0:
			print('YES', 2 * 10 ** 7)
		elif diff < 0:
			print('NO')
		else:
			factor = fact(diff)
			f = []
			for i in factor:
				if i < n:
					continue
				f.append(i)
			for mid in f:
				if check(arr, n, mid):
					print('YES', mid)
					break
			else:
				print('NO')
main()


import sys
import math
input = lambda : sys.stdin.readline().rstrip('\r\n')

def check(x):
	memo = {i: False for i in range(1, n + 1)}
	for i in arr:
		memo[i % x] = True
	for i in range(1, n + 1):
		if not memo[i]:
			return False
	return True

def factors(num):
	fact = []
	for i in range(1, int(math.sqrt(num)) + 1):
		if num % i == 0:
			fact.append(i)
			fact.append(num // i)
	return fact
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) != n:
		print('NO')
	else:
		to_use = []
		avail = set(arr)
		for i in arr:
			if i > n:
				to_use.append(i)
		remain = []
		for i in range(1, n + 1):
			if i not in avail:
				remain.append(i)
		if to_use:
			y = min(to_use)
			flag = False
			num = sum(arr) - n * (n + 1) // 2
			fact = factors(num)
			for f in fact:
				if check(f):
					print('YES', f)
					flag = True
					break
			if not flag:
				print('NO')
		else:
			print('YES', n + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	if len(set(s)) != n:
		print('NO')
	else:
		sum1 = sum(s) - n * (n + 1) // 2
		flag = 0
		i = 1
		if sum1 == 0:
			print('YES', n + 1)
			continue
		b = [x for x in range(1, n + 1)]
		while i * i <= sum1:
			if sum1 % i == 0:
				if sorted([x % i for x in s]) == b:
					flag = 1
					print('YES', i)
					break
				elif sorted([x % (sum1 // i) for x in s]) == b:
					flag = 1
					print('YES', sum1 // i)
					break
			i += 1
		if flag == 0:
			print('NO')


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	if len(s) != n:
		print('NO')
		continue
	su = sum(a) - n * (n + 1) // 2
	if su == 0:
		print('YES', n + 1)
		continue
	factors = set()
	i = 1
	while i * i <= su:
		if su % i == 0:
			if i > n and i <= 20000000:
				factors.add(i)
			if su // i > n and su // i <= 20000000:
				factors.add(su // i)
		i += 1
	for x in factors:
		dummy = set()
		for i in range(n):
			if a[i] % x == 0 or a[i] % x > n or a[i] % x in dummy:
				break
			dummy.add(a[i] % x)
		else:
			print('YES', x)
			break
	else:
		print('NO')


from sys import stdin, stdout
input = stdin.readline

def check(i):
	return set([j % i for j in a]) == perm

def f():
	i = 1
	while i * i <= diff:
		if diff % i == 0:
			if check(i):
				return i
			if diff // i != i and check(diff // i):
				return diff // i
		i += 1
	return 0
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	perm = set([i + 1 for i in range(n)])
	if set(a) == perm:
		print('YES', n + 1)
		continue
	diff = sum(a) - n * (n + 1) // 2
	ans = f()
	if ans:
		print('YES', ans)
	else:
		print('NO')


import math

def check(arr, num, n):
	visit = [0] * (n + 1)
	for e in arr:
		if e % num == 0 or e % num > n or visit[e % num]:
			return 0
		visit[e % num] = 1
	return 1

def fact(n):
	factor = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			factor.append(i)
			if n // i != i:
				factor.append(n // i)
	return factor
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arrsum = sum(arr)
	t = n * (n + 1) // 2
	diff = arrsum - t
	if diff == 0:
		print('YES', n + 1)
	elif diff < 0:
		print('NO')
	else:
		factor = fact(diff)
		f = []
		factor.sort(reverse=1)
		for e in factor:
			if e <= n:
				break
			if e <= 2 * 10 ** 7:
				f.append(e)
		for e in f:
			if check(arr, e, n):
				print('YES', e)
				break
		else:
			print('NO')


def div(n):
	i = 1
	d = []
	while i * i <= n:
		if n % i == 0:
			if i <= 2 * 10 ** 7:
				d.append(i)
			if i * i != n:
				if n // i <= 2 * 10 ** 7:
					d.append(n // i)
		i += 1
	return d
t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	a = [int(x) for x in a]
	b = [i for i in range(1, n + 1)]
	a.sort()
	if a == b:
		print('YES', n + 1)
	else:
		s = sum(a) - n * (n + 1) // 2
		if s < 0:
			print('NO')
		else:
			flag = 0
			d = div(s)
			d.sort()
			for i in d:
				if sorted([x % i for x in a]) == b:
					flag = 1
					ans = i
					break
			if flag == 1:
				print('YES', ans)
			else:
				print('NO')


from math import ceil, log, sqrt

def check(lst, var, n):
	visited = [0] * (n + 1)
	for x in lst:
		if x % var == 0 or x % var > n or visited[x % var]:
			return 0
		visited[x % var] = 1
	return 1

def factors(x):
	fact = []
	for y in range(1, int(sqrt(x) + 1)):
		if x % y == 0:
			fact.append(y)
			if x // y != y:
				fact.append(x // y)
	return fact
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	sm = sum(lst)
	total = n * (n + 1) // 2
	c = sm - total
	if c == 0:
		print('YES', n + 1)
	elif c < 0:
		print('NO')
	else:
		factor = factors(c)
		fctrs = []
		factor.sort(reverse=1)
		for x in factor:
			if x <= n:
				break
			if x <= 2 * 10 ** 7:
				fctrs.append(x)
		for x in fctrs:
			if check(lst, x, n):
				print('YES', x)
				break
		else:
			print('NO')


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
gp = []
ans = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def flip(a, l, r):
	for i in range(l, r):
		a[i] = '0' if a[i] == '1' else '1'
	return

def hnbhai(tc):
	n = sb()
	a = sd()
	d = {}
	mx = 0
	b = a.copy()
	b.sort()
	c = [i for i in range(1, n + 1)]
	if b == c:
		print('YES', 2 * 10 ** 7)
		return
	for i in a:
		d[i] = d.get(i, 0) + 1
		mx = max(mx, d[i])
	if mx > 1:
		print('NO')
		return
	sm = sum(a)
	tot = 0
	mn = float('inf')
	for i in a:
		if i > n:
			mn = min(mn, i)
	for i in range(1, n + 1):
		if d.get(i) is not None:
			sm -= i
			continue
		sm -= i
	x = 1
	for i in range(1, sm + 1):
		if i * i > sm:
			break
		if sm % i == 0:
			x = i
			e = {}
			b = a.copy()
			for j in range(n):
				b[j] %= x
				if b[j] > 0 and b[j] <= n:
					e[b[j]] = 1
			if len(e) == n:
				print('YES', x)
				return
			x = sm // i
			e = {}
			b = a.copy()
			for j in range(n):
				b[j] %= x
				if b[j] > 0 and b[j] <= n:
					e[b[j]] = 1
			if len(e) == n:
				print('YES', x)
				return
	print('NO')
for _ in range(sb()):
	hnbhai(_ + 1)


def divisors(m):
	result = set()
	for i in range(1, int(m ** 0.5) + 1):
		if m % i == 0:
			result.add(i)
			result.add(m // i)
	return sorted(result)

def solve(n, a):
	if len(set(a)) != n:
		return 'NO'
	perm = set(range(1, n + 1))
	m = sum(a) - n * (n + 1) // 2
	if m == 0:
		return 'YES ' + str(n + 1)
	divs = [d for d in divisors(m) if d > n]
	for div in divs:
		if set((x % div for x in a)) == perm:
			return 'YES ' + str(div)
	return 'NO'
T = int(input())
for _ in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	result = solve(n, a)
	print(result)


import sys
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue as pq
from math import gcd
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
lii = lambda : list(map(int, list(ip())))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
mod = 10 ** 9 + 7
mod1 = 998244353
for _ in range(ii()):
	n = ii()
	a = il()
	b = [i for i in range(1, n + 1)]
	if sorted(a) == b:
		print('YES', n + 1)
		continue
	d = {}
	mx = 0
	for i in a:
		d[i] = d.get(i, 0) + 1
		mx = max(mx, d[i])
	if mx > 1:
		print('NO')
		continue
	if a.count(n + 1):
		print('NO')
		continue
	d = {}
	b1 = []
	for i in range(n):
		if a[i] >= 1 and a[i] <= n:
			d[a[i]] = 1
		else:
			b1.append(a[i])
	b = []
	for i in range(1, n + 1):
		if not d.get(i):
			b.append(i)
	t = 0
	if len(b) == 1:
		x = b1[0] - b[0]
		if x > n:
			print('YES', x)
		else:
			print('NO')
		continue
	t = sum(b1) - sum(b)
	b1.sort()
	p = 2
	fl = 0
	ans = -1
	while p * p <= t:
		if t % p == 0:
			p1 = t // p
			if p > n and p < b1[0] and (p1 >= len(b1)):
				e = {}
				b = a.copy()
				for j in range(n):
					b[j] %= p
					if b[j] > 0 and b[j] <= n:
						e[b[j]] = 1
				if len(e) == n:
					fl = 1
					ans = p
					break
			(p1, p) = (p, p1)
			if p > n and p < b1[0] and (p1 >= len(b1)):
				e = {}
				b = a.copy()
				for j in range(n):
					b[j] %= p
					if b[j] > 0 and b[j] <= n:
						e[b[j]] = 1
				if len(e) == n:
					fl = 1
					ans = p
					break
			(p1, p) = (p, p1)
		p += 1
	if fl:
		print('YES', ans)
	else:
		print('NO')


def solve(arr, val, n):
	st = set()
	for item in arr:
		ans = item % val
		if ans > n or ans == 0 or ans in st:
			return False
		st.add(ans)
	return True
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	sm = sum(arr) - n * (n + 1) // 2
	i = 1
	temp = 0
	while i * i <= sm:
		if sm % i != 0:
			pass
		elif solve(arr, i, n):
			temp = 1
			ans = i
			break
		elif solve(arr, sm // i, n):
			temp = 1
			ans = sm // i
			break
		i += 1
	visited = set()
	for item in arr:
		if item >= 1 and item <= n:
			visited.add(item)
	if len(visited) == n:
		temp = 1
		ans = n + 1
	if temp:
		print('YES', ans)
	else:
		print('NO')
	t -= 1