You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements.

Your goal is to obtain the set of numbers $\{b_1, b_2, \dots, b_n\}$ as the result of taking elements from the pairs.

What is the number of different $x$-s ($0 \le x \le n$) such that it's possible to obtain the set $b$ if for each $x$ you can choose how to distribute numbers into pairs and from which $x$ pairs choose minimum elements?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The first line of each test case contains the integer $n$ ($1 \le n \le 2 \cdot 10^5$).

The second line of each test case contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_1 < b_2 < \dots < b_n \le 2n$) — the set you'd like to get.

It's guaranteed that the sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print one number — the number of different $x$-s such that it's possible to obtain the set $b$.


-----Examples-----

Input
3
1
1
5
1 4 5 9 10
2
3 4
Output
1
3
1


-----Note-----

In the first test case, $x = 1$ is the only option: you have one pair $(1, 2)$ and choose the minimum from this pair.

In the second test case, there are three possible $x$-s. If $x = 1$, then you can form the following pairs: $(1, 6)$, $(2, 4)$, $(3, 5)$, $(7, 9)$, $(8, 10)$. You can take minimum from $(1, 6)$ (equal to $1$) and the maximum elements from all other pairs to get set $b$.

If $x = 2$, you can form pairs $(1, 2)$, $(3, 4)$, $(5, 6)$, $(7, 9)$, $(8, 10)$ and take the minimum elements from $(1, 2)$, $(5, 6)$ and the maximum elements from the other pairs.

If $x = 3$, you can form pairs $(1, 3)$, $(4, 6)$, $(5, 7)$, $(2, 9)$, $(8, 10)$ and take the minimum elements from $(1, 3)$, $(4, 6)$, $(5, 7)$.

In the third test case, $x = 0$ is the only option: you can form pairs $(1, 3)$, $(2, 4)$ and take the maximum elements from both of them.

Difficulty: HARD
Tags: Sorting

Constructive algorithms

Amortized analysis

Greedy algorithms
Skill types: Sorting

Amortized analysis

Greedy algorithms

Starter code:

Solutions:
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	b = [0] + list(map(int, input().split())) + [2 * n + 1]
	bb = []
	interval = []
	for i in range(n + 1):
		interval.append(b[i + 1] - b[i] - 1)
	min_x = 0
	rem = 0
	for e in interval[n - 1::-1]:
		rem += 1
		if e < rem:
			rem -= e
		else:
			rem = 0
	min_x = rem
	max_x = 0
	rem = 0
	for e in interval[1:]:
		rem += 1
		if e < rem:
			rem -= e
		else:
			rem = 0
	max_x = n - rem
	print(max_x - min_x + 1)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	t = int(input())
	ans_a = [''] * t
	for ti in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		empty = [1] * (2 * n + 1)
		ok = [0] + [1] * (2 * n)
		for x in a:
			empty[x] = 0
		for iter in (range(1, 2 * n + 1), range(2 * n, 0, -1)):
			rem = 0
			for i in iter:
				if empty[i]:
					ok[i] = 0
					rem += 1
				elif rem > 0:
					rem -= 1
				else:
					ok[i] = 0
		ans_a[ti] = str(sum(ok) + 1)
	output(*ans_a)
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		b = list(map(int, input().split()))
		b.append(2 * n + 1)
		rem = []
		nex = 1
		for i in b:
			while nex != i:
				rem.append(nex)
				nex += 1
			nex += 1
		l = 0
		r = n + 1
		while r - 1 != l:
			m = (l + r) // 2
			flag = True
			for i in range(m):
				if b[m - 1 - i] > rem[n - 1 - i]:
					flag = False
					break
			if flag:
				l = m
			else:
				r = m
		maxx = l
		l = 0
		r = n + 1
		while r - l != 1:
			m = (l + r) // 2
			flag = True
			for i in range(m):
				if rem[m - 1 - i] >= b[n - 1 - i]:
					flag = False
					break
			if flag:
				l = m
			else:
				r = m
		minx = n - l
		yield max(0, maxx - minx + 1)
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
for ti in range(t):
	(n,) = map(int, input().strip().split(' '))
	b = list(map(int, input().strip().split(' ')))
	a = []
	ptr = 0
	for i in range(1, n * 2 + 1):
		if ptr < n and i == b[ptr]:
			ptr += 1
		else:
			a.append(i)
	ptr = 0
	mmi = 0
	for i in range(n):
		while ptr < n and a[ptr] < b[i]:
			ptr += 1
		if ptr >= n:
			break
		else:
			mmi += 1
			ptr += 1
	ptr = n - 1
	mmx = 0
	for i in range(n):
		i = n - 1 - i
		while ptr >= 0 and a[ptr] > b[i]:
			ptr -= 1
		if ptr < 0:
			break
		else:
			mmx += 1
			ptr -= 1
	ans = mmi + mmx - n + 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	b = [int(x) for x in input().split()]
	(j, count) = (0, 0)
	(bad_left, bad_right) = (0, 0)
	for i in range(1, 2 * n + 1):
		if j < n and b[j] == i:
			j += 1
			if count == 0:
				bad_left += 1
			else:
				count -= 1
		else:
			count += 1
	(j, count) = (n - 1, 0)
	for i in range(2 * n, 0, -1):
		if j > -1 and b[j] == i:
			j -= 1
			if count == 0:
				bad_right += 1
			else:
				count -= 1
		else:
			count += 1
	print(n + 1 - bad_left - bad_right)


from collections import deque
ansl = []
for _ in range(int(input())):
	n = int(input())
	bl = list(map(int, input().split()))
	bset = set(bl)
	rems = []
	for i in range(1, 2 * n + 1):
		if i not in bset:
			rems.append(i)
	(ok, ng) = (0, n + 1)
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		res = True
		for i in range(mid):
			if bl[i] > rems[n - mid + i]:
				res = False
				break
		if res:
			ok = mid
		else:
			ng = mid
	left_ok = min(ok, n)
	(ok, ng) = (0, n + 1)
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		res = True
		for i in range(mid):
			if bl[n - mid + i] < rems[i]:
				res = False
				break
		if res:
			ok = mid
		else:
			ng = mid
	right_ok = n - ok
	ans = left_ok - right_ok + 1
	ans = max(0, ans)
	ansl.append(ans)
for a in ansl:
	print(a)


(T,) = map(int, input().split())
for _ in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	Y = [0] * (2 * N + 1)
	for x in X:
		Y[x] = 1
	(u, v) = (0, 0)
	r = 0
	rr = 0
	for i in range(1, 2 * N + 1):
		if Y[i]:
			u += 1
			if u > v:
				rr = max(rr, u - v)
		else:
			v += 1
			if v > u:
				r = max(r, v - u)
	print(N + 1 - r - rr)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	S = set(arr)
	exc = cnt1 = 0
	for i in range(1, 2 * n + 1):
		if i not in S:
			exc += 1
			continue
		if exc:
			cnt1 += 1
			exc -= 1
	f = n - cnt1
	exc = cnt2 = 0
	for i in range(2 * n, 0, -1):
		if i not in S:
			exc += 1
			continue
		if exc:
			cnt2 += 1
			exc -= 1
	b = cnt2
	return b - f + 1
for _ in range(int(input())):
	print(solve())


for ct in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	x = y = 0
	for (i, v) in enumerate(b):
		x = max(x, 2 * (i + 1) - v)
		y = max(y, v - 2 * (i + 1) + 1)
	print(n - x - y + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	max_force = 0
	min_force = 0
	legacy = 0
	possibility = 0
	for i in b:
		jump = i - legacy - 1
		possibility += jump
		if possibility > 0:
			possibility -= 1
		else:
			min_force += 1
		legacy = i
	possibility = 0
	legacy = 2 * n + 1
	for i in reversed(b):
		jump = legacy - i - 1
		possibility += jump
		if possibility > 0:
			possibility -= 1
		else:
			max_force += 1
		legacy = i
	print(n - max_force - min_force + 1)


t = int(input())
for g in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	a = []
	j = 0
	for i in range(1, 2 * n + 1):
		if j < n and i == b[j]:
			j += 1
		else:
			a.append(i)
	i = 0
	j = 0
	l = 0
	while i < n and j < n:
		if a[i] < b[j]:
			while a[i] < b[j] and i < n - 1:
				i += 1
		if a[i] > b[j]:
			l += 1
		i += 1
		j += 1
	i = n - 1
	j = n - 1
	r = 0
	while i > -1 and j > -1:
		if a[i] > b[j]:
			while a[i] > b[j] and i > 0:
				i -= 1
		if a[i] < b[j]:
			r += 1
		i -= 1
		j -= 1
	print(l - (n - r) + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [0 for i in range(2 * n)]
	l = list(map(int, input().split()))
	for i in range(n):
		arr[l[i] - 1] = 1
	arr1 = []
	arr2 = []
	for i in range(2 * n):
		if arr[i] == 1:
			arr1.append(i + 1)
		else:
			arr2.append(i + 1)
	sm = 0
	la = 0
	count = 0
	while sm < n and la < n:
		if arr2[la] < arr1[sm]:
			count += 1
			sm += 1
			la += 1
		else:
			sm += 1
	x = n - count
	sm = 0
	la = 0
	count2 = 0
	while sm < n and la < n:
		if arr2[la] > arr1[sm]:
			count2 += 1
			sm += 1
			la += 1
		else:
			la += 1
	print(max(x, count2) - min(x, count2) + 1)


t = int(input())

def check_first_x(x):
	i = x - 1
	j = n - 1
	while i >= 0:
		if arr[i] > left[j]:
			return False
		i -= 1
		j -= 1
	return True

def check_last_x(x):
	i = n - 1
	j = x - 1
	while j >= 0:
		if arr[i] < left[j]:
			return False
		i -= 1
		j -= 1
	return True
while t > 0:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	left = []
	check = set(arr)
	for i in range(1, 2 * n + 1):
		if i not in check:
			left.append(i)
	a1 = [False for x in range(n + 1)]
	a2 = [False for x in range(n + 1)]
	start = 0
	end = n
	index = None
	while start <= end:
		if start == end:
			if check_first_x(end) == True:
				index = start
		mid = (start + end) // 2
		if check_first_x(mid) == True:
			index = mid
			start = mid + 1
		else:
			end = mid - 1
	if index != None:
		for i in range(index + 1):
			a1[i] = True
	start = 0
	end = n
	index = None
	while start <= end:
		if start == end:
			if check_last_x(end) == True:
				index = start
		mid = (start + end) // 2
		if check_last_x(mid) == True:
			index = mid
			start = mid + 1
		else:
			end = mid - 1
	if index != None:
		for i in range(index + 1):
			a2[i] = True
	count = 0
	for i in range(n + 1):
		if a1[i] and a2[n - i]:
			count += 1
	print(count)


def main(n, d):
	o = []
	i = 0
	c = d[0]
	for j in range(1, 2 * n + 1):
		if i < n and c == j:
			i += 1
			if i == n:
				continue
			c = d[i]
		else:
			o.append(j)
	(f, e) = (0, 0)
	i = 0
	c = o[i]
	for j in d:
		if c < j:
			i += 1
			if i == n:
				break
			c = o[i]
		else:
			f += 1
	i = n - 1
	c = o[i]
	for j in range(n - 1, -1, -1):
		if c > d[j]:
			i -= 1
			if i < 0:
				break
			c = o[i]
		else:
			e += 1
	return n - e - f + 1
t = int(input())
for i in range(t):
	n = int(input())
	(*d,) = map(int, input().split())
	print(main(n, d))


import os
import sys
from io import BytesIO, IOBase

def check(mid, b):
	(n, a, j) = (len(b), set(b), 2 * len(b))
	for i in range(mid - 1, -1, -1):
		while j > 0 and j in a:
			j -= 1
		if j < b[i]:
			return 1
		a.add(j)
	j = 1
	for i in range(mid, n):
		while j <= 2 * n and j in a:
			j += 1
		if j > b[i]:
			return 2
		a.add(j)
	return 3

def main():
	for _ in range(int(input())):
		n = int(input())
		b = list(map(int, input().split()))
		(lo, hi, mi) = (0, n, 0)
		while lo <= hi:
			mid = (lo + hi) // 2
			zz = check(mid, b)
			if zz == 3:
				mi = mid
				hi = mid - 1
			elif zz == 1:
				hi = mid - 1
			else:
				lo = mid + 1
		(lo, hi, ma) = (0, n, 0)
		while lo <= hi:
			mid = (lo + hi) // 2
			zz = check(mid, b)
			if zz == 3:
				ma = mid
				lo = mid + 1
			elif zz == 1:
				hi = mid - 1
			else:
				lo = mid + 1
		print(ma - mi + 1)
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 math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

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

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		L = l.copy()
		if n == 1:
			print(1)
			return
		if l[0] != 1:
			l.insert(0, 0)
		q = []
		for i in range(len(l) - 1):
			for j in range(l[i] + 1, l[i + 1]):
				q.append(j)
		if l[-1] != 2 * n:
			for j in range(l[-1] + 1, 2 * n + 1):
				q.append(j)
		cnt = 0
		(a, b) = ([1], [1])
		i = 0
		cn1 = 0
		for j in range(n):
			while i < n:
				if q[i] > L[j]:
					break
				i += 1
			if i >= n:
				for k in range(n - j):
					a.append(0)
				break
			elif q[i] > L[j]:
				a.append(1)
				i += 1
			else:
				for k in range(n - j):
					a.append(0)
				break
		i = n - 1
		for j in range(n - 1, -1, -1):
			while i >= 0:
				if q[i] < L[j]:
					break
				i -= 1
			if i < 0:
				for k in range(j + 1):
					b.append(0)
				break
			elif q[i] < L[j]:
				b.append(1)
				i -= 1
			else:
				for k in range(j + 1):
					b.append(0)
				break
		b = b[::-1]
		for i in range(n + 1):
			if b[i] + a[i] == 2:
				cnt += 1
		print(cnt)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
import math
while t > 0:
	t -= 1
	n = [int(op) for op in input().split()][0]
	ar = [int(op) for op in input().split()]
	mi = 0
	mnr = [0]
	kn = 0
	for a in ar:
		if max(0, a - mi - 1 + mnr[-1]) == 0:
			kn += 1
		mnr.append(max(0, a - mi - 1 + mnr[-1] - 1))
		mi = a
	mi = 2 * n + 1
	km = 0
	mnr.append(0)
	for a in reversed(ar):
		if max(0, -a + mi - 1 + mnr[-1]) == 0:
			km += 1
		mnr.append(max(0, -a + mi - 1 + mnr[-1] - 1))
		mi = a
	print(1 + max(0, n - (km + kn)))


for _ in range(int(input())):
	n = int(input())
	a = [-1] * (2 * n)
	arr = [int(x) for x in input().split()]
	for x in arr:
		a[x - 1] = 1
	mx = -float('inf')
	mn = -mx
	t = 0
	for i in range(2 * n):
		t += a[i]
		mx = max(mx, t)
	t = 0
	for i in range(2 * n - 1, -1, -1):
		t += a[i]
		mn = min(mn, n - t)
	print(mn - mx + 1)


tests = int(input())
for t in range(tests):
	n = int(input())
	ls = list(map(int, input().split()))
	if min(ls) == n + 1 or max(ls) == n:
		print(1)
	else:
		mini = 0
		curr = 2 * n
		idx = n - 1
		remain = 0
		while idx >= 0:
			remain += curr - ls[idx]
			if remain > 0:
				remain -= 1
				mini += 1
			curr = ls[idx] - 1
			idx -= 1
		maxi = 0
		curr = 1
		idx = 0
		remain = 0
		while idx < n:
			remain += ls[idx] - curr
			if remain > 0:
				remain -= 1
				maxi += 1
			curr = ls[idx] + 1
			idx += 1
		print(mini - (n - maxi) + 1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	mark = [0] * (2 * n + 1)
	b = [int(x) for x in input().split()]
	for x in b:
		mark[x] = 1
	a = []
	for x in range(1, 2 * n + 1):
		if mark[x] == 0:
			a.append(x)
	(lo, hi) = (0, n)
	while lo < hi:
		mid = (lo + hi + 1) // 2
		possible = True
		for i in range(mid):
			possible &= b[i] < a[n - mid + i]
		if possible == True:
			lo = mid
		else:
			hi = mid - 1
	(lo2, hi2) = (0, n)
	while lo2 < hi2:
		mid = (lo2 + hi2 + 1) // 2
		possible = True
		for i in range(mid):
			possible &= b[n - mid + i] > a[i]
		if possible == True:
			lo2 = mid
		else:
			hi2 = mid - 1
	ans = 0
	for i in range(n + 1):
		ans += int(lo >= i and lo2 >= n - i)
	print(ans)


from sys import stdin
q = int(input())
for j in range(q):
	n = int(input())
	b = list(map(int, input().split()))
	used = [0] * 2 * n
	for i in range(n):
		used[b[i] - 1] = 1
	free = 0
	ma = 0
	for i in range(n * 2):
		if used[i]:
			if free > 0:
				ma += 1
				free -= 1
		else:
			free += 1
	used.reverse()
	maxim = ma
	free = 0
	ma = 0
	for i in range(n * 2):
		if used[i]:
			if free > 0:
				ma += 1
				free -= 1
		else:
			free += 1
	print(abs(n - maxim - ma) + 1)


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

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

def ts():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
f = []

def factMod(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fact(n):
	global f
	f = [1 for i in range(n)]
	for i in range(1, n):
		f[i] = f[i - 1] * i

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncrMod(n, r, m):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def ncr(n, r):
	if r == 0:
		return 1
	if n < r:
		return 0
	return f[n] / (f[r] * f[n - r])

def nc2(n):
	return n * (n - 1) / 2

def main():
	D()

def A():
	t = pi()
	while t:
		t -= 1
		a = ti()
		s = a[0] + a[1] + a[2]
		x = math.floor(s / 9)
		if s < 7 or a[0] < x or a[1] < x or (a[2] < x):
			print('NO')
			continue
		if s % 9 == 0:
			print('YES')
		else:
			print('NO')

def B():
	t = pi()
	while t:
		t -= 1
		n = pi()
		a = ti()
		b = [0 for i in range(n)]
		s = s1 = s2 = 0
		for i in range(n):
			s += a[i]
			if i % 2 == 0:
				s1 += a[i]
			else:
				s2 += a[i]
		if s1 > s / 2:
			for i in range(n):
				if i % 2 != 0:
					b[i] = 1
				else:
					b[i] = a[i]
		else:
			for i in range(n):
				if i % 2 != 0:
					b[i] = a[i]
				else:
					b[i] = 1
		print(*b, sep=' ')

def C():
	t = pi()
	while t:
		t -= 1
		n = pi()
		a = []
		for i in range(n):
			[x, y] = ti()
			a.append([x, y])
		pre = 0
		dir = 1 if a[0][1] >= 0 else -1
		curr = 0
		count = 0
		for i in range(1, n):
			d = dir * (a[i][0] - a[i - 1][0])
			if dir > 0 and pre + d < a[curr][1] or (dir < 0 and pre + d > a[curr][1]):
				nxt = pre + dir * (a[i][0] - a[i - 1][0])
				if dir == 1:
					if a[i - 1][1] >= pre and a[i - 1][1] <= nxt:
						count += 1
				elif a[i - 1][1] <= pre and a[i - 1][1] >= nxt:
					count += 1
				pre += d
			else:
				nxt = a[curr][1]
				if dir == 1:
					if a[i - 1][1] >= pre and a[i - 1][1] <= nxt:
						count += 1
				elif a[i - 1][1] <= pre and a[i - 1][1] >= nxt:
					count += 1
				curr = i
				dir = 1 if a[curr][1] > pre else -1
				pre = nxt
		if curr == n - 1:
			count += 1
		print(count)

def D():
	t = pi()
	while t:
		t -= 1
		(n, b) = (pi(), ti())
		a = [0 for i in range(1, 2 * n + 2)]
		x = [0 for i in range(1, 2 * n + 2)]
		for i in range(n):
			a[b[i]] = 1
			x[b[i]] = 1
		mn = [0 for i in range(n + 1)]
		mx = [0 for i in range(n + 1)]
		p = 0
		mn[0] = mx[0] = 1
		for i in range(n):
			while p <= 2 * n and (p <= b[i] or a[p] == 1):
				p += 1
			if p <= 2 * n:
				a[p] = 1
				mn[i + 1] = 1
		p = 2 * n
		for i in range(n - 1, -1, -1):
			while p >= 1 and (p >= b[i] or x[p] == 1):
				p -= 1
			if p >= 1:
				x[p] = 1
				mx[n - i] = 1
		res = 0
		for i in range(n + 1):
			if mn[i] and mx[n - i]:
				res += 1
		print(res)
main()


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	B = list(map(int, input().split()))
	SETB = set(B)
	MINOK = [0] * n
	MAXOK = [0] * n
	minpair = 0
	for i in range(n):
		b = B[i]
		while minpair <= b or minpair in SETB:
			minpair += 1
		MINOK[i] = minpair
		minpair += 1
	maxpair = n * 2
	for i in range(n - 1, -1, -1):
		b = B[i]
		while maxpair >= b or maxpair in SETB:
			maxpair -= 1
		MAXOK[i] = maxpair
		maxpair -= 1
	for i in range(n):
		if 1 <= MINOK[i] <= n * 2:
			MINOK[i] = 1
		else:
			MINOK[i] = 0
		if 1 <= MAXOK[i] <= n * 2:
			MAXOK[i] = 1
		else:
			MAXOK[i] = 0
	ANS = 0
	if MAXOK[0] == 1:
		ANS += 1
	for i in range(n - 1):
		if MINOK[i] == 1 and MAXOK[i + 1] == 1:
			ANS += 1
	if MINOK[-1] == 1:
		ANS += 1
	print(ANS)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	b = [int(x) for x in input().split()]
	b.sort()
	a = []
	j = 0
	for i in range(1, n * 2 + 1):
		if j < n and i == b[j]:
			j += 1
		else:
			a.append(i)
	maxX = 0
	i = 0
	j = 0
	while i < n:
		if a[i] < b[j]:
			i += 1
		else:
			maxX += 1
			i += 1
			j += 1
	minX = n
	i = n - 1
	j = n - 1
	while i >= 0:
		if a[i] > b[j]:
			i -= 1
		else:
			minX -= 1
			i -= 1
			j -= 1
	ans = maxX - minX + 1
	print(ans)


for q in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	(mx, mi, ind, pos) = (0, 0, 0, 0)
	for i in range(n):
		ind -= b[i] - pos - 1
		mi = min(mi, ind)
		ind += 1
		mx = max(mx, ind)
		pos = b[i]
	print(n - mx + mi + 1)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	b = sorted([int(x) for x in input().split()])
	y = 0
	z = 0
	for i in range(n):
		y += b[i] - (i + 1) - y > 0
		z += 2 * n - b[n - i - 1] - i - z > 0
	y = n - y
	print(z - y + 1)


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

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

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

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from collections import deque as dq
for _ in range(N()):
	n = N()
	a = RLL()
	aa = set(a)
	b = [i for i in range(1, 2 * n + 1) if i not in aa]
	l = 0
	bb = dq(b)
	for v in a:
		if bb[0] > v:
			bb.pop()
			l += 1
		else:
			bb.popleft()
	r = 0
	bb = dq(b)
	for v in a[::-1]:
		if bb[-1] < v:
			bb.popleft()
			r += 1
		else:
			bb.pop()
	r = n - r
	print(r - l + 1)


def solve():
	n = int(input())
	b = list(map(int, input().split()))
	cnt = 0
	cur = 0
	mx = 0
	for i in range(n):
		cnt += b[i] - cur - 1
		cur = b[i]
		if cnt > 0:
			cnt -= 1
			mx += 1
	cnt = 0
	cur = 2 * n + 1
	mn = 0
	for i in range(n - 1, -1, -1):
		cnt += cur - b[i] - 1
		cur = b[i]
		if cnt > 0:
			cnt -= 1
			mn += 1
	ans = mx - (n - mn) + 1
	return ans
ans = []
for _ in range(int(input())):
	ans.append(solve())
print('\n'.join(map(str, ans)))


T = int(input())
ans = []
for t in range(T):
	n = int(input())
	b = list(map(int, input().split()))
	a = []
	cersol = 0
	for i in range(1, 2 * n + 1):
		if cersol < n and b[cersol] == i:
			cersol += 1
			continue
		else:
			a.append(i)
	mi = 0
	cersol = 0
	for i in range(n):
		for j in range(cersol, n):
			cersol = j
			if a[j] > b[i]:
				cersol += 1
				mi += 1
				break
	ma = 0
	cersol = n - 1
	for i in range(n - 1, -1, -1):
		for j in range(cersol, -1, -1):
			cersol = j
			if a[j] < b[i]:
				cersol -= 1
				ma += 1
				break
	ma = n - ma
	ans.append(mi - ma + 1)
for t in range(T):
	print(ans[t])


t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	s = set(b)
	arr = [1] * (2 * n)
	pos = 0
	mini = 0
	for i in range(n):
		pos = max(pos, b[i])
		temp = pos
		for j in range(pos, 2 * n):
			if j + 1 not in s and arr[j] == 1:
				mini += 1
				arr[j] = 0
				arr[b[i] - 1] = 0
				pos = j + 1
				break
		if pos == temp:
			pos = 2 * n
	arr = [1] * (2 * n)
	pos = 2 * n - 1
	maxi = 0
	for i in range(n - 1, -1, -1):
		pos = min(pos, b[i] - 2)
		temp = pos
		for j in range(pos, -1, -1):
			if j + 1 not in s and arr[j] == 1:
				maxi += 1
				arr[j] = 0
				arr[b[i] - 1] = 0
				pos = j - 1
				break
		if pos == temp:
			pos = -1
	maxi = n - maxi
	print(mini - maxi + 1)


import sys
input = sys.stdin.readline
import math
import copy
for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	b.sort()
	bank = 0
	current = 0
	nummins = 0
	for i in range(1, 2 * n + 1):
		if current < n and i == b[current]:
			bank += 1
			current += 1
		elif bank > 0:
			bank -= 1
			nummins += 1
	nummaxs = 0
	bank = 0
	current = n - 1
	for i in range(2 * n, 0, -1):
		if current >= 0 and i == b[current]:
			bank += 1
			current -= 1
		elif bank > 0:
			bank -= 1
			nummaxs += 1
	small = n - nummaxs
	big = nummins
	ans = big - small + 1
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	flag = [0] * (2 * n + 1)
	for a in A:
		flag[a] = 1
	cnt = 0
	j = 0
	for i in range(1, 2 * n + 1):
		if flag[i]:
			cnt -= 1
			if cnt < 0:
				cnt += 1
				j += 1
		else:
			cnt += 1
	cnt = 0
	k = n
	for i in range(2 * n, 0, -1):
		if flag[i]:
			cnt -= 1
			if cnt < 0:
				cnt += 1
				k -= 1
		else:
			cnt += 1
	print(k - j + 1)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

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

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
sys.setrecursionlimit(100000)
INF = float('inf')
mod = 10 ** 9 + 7
for _ in range(int(data())):
	n = int(data())
	b = mdata()
	(l, s, ol, os) = (0, 0, 0, 0)
	for i in range(n):
		if b[i] - i - 1 > ol:
			ol += 1
			l += 1
		if 2 * n - b[n - i - 1] - i > os:
			os += 1
			s += 1
	out(os - n + ol + 1)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		b = list(map(int, input().split()))
		(ans, x) = (int(b[0] != 1), max(0, b[0] - 2))
		for i in range(1, n):
			r = b[i] - b[i - 1] - 1
			if r:
				ans += 1
				x += r - 1
			elif x:
				x -= 1
				ans += 1
		(ans1, x1) = (int(b[-1] != 2 * n), max(0, 2 * n - b[-1] - 1))
		for i in range(n - 2, -1, -1):
			r = b[i + 1] - b[i] - 1
			if r:
				ans1 += 1
				x1 += r - 1
			elif x1:
				x1 -= 1
				ans1 += 1
		ans1 = n - ans1
		print(ans - ans1 + 1)
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

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

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

def check(a, b, x):
	for i in range(x):
		if a[i] > b[len(b) - x + i]:
			return 0
	return 1

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = []
		for j in range(1, a[0]):
			b.append(j)
		for i in range(1, n):
			for j in range(a[i - 1] + 1, a[i]):
				b.append(j)
		for j in range(a[n - 1] + 1, 2 * n + 1):
			b.append(j)
		l = 0
		r = n
		ans = -1
		while l < r:
			mid = l + (-l + r + 1) // 2
			if check(a, b, mid):
				l = mid
			else:
				r = mid - 1
		ans1 = max(ans, l)
		(a, b) = (b, a)
		l = 0
		r = n
		while l < r:
			mid = l + (-l + r + 1) // 2
			if check(a, b, mid):
				l = mid
			else:
				r = mid - 1
		ans2 = n - l
		print(max(0, ans1 - ans2 + 1))
	return
main()


T = int(input())
r = 1
while r <= T:
	n = int(input())
	b = list(map(int, input().split()))
	ans = 0
	occu = [False] * (2 * n + 2)
	for i in range(n):
		occu[b[i]] = True
	s = 1
	l = 2 * n
	maxbig = 0
	minbig = n
	for i in range(n):
		while occu[s]:
			s += 1
		if b[i] > s:
			maxbig += 1
			s += 1
		else:
			while occu[l]:
				l -= 1
			l -= 1
	s = 1
	l = 2 * n
	for i in range(n - 1, -1, -1):
		while occu[l]:
			l -= 1
		if b[i] < l:
			minbig -= 1
			l -= 1
		else:
			while occu[s]:
				s += 1
			s += 1
	print(maxbig - minbig + 1)
	r += 1


from sys import stdin
T = int(stdin.readline().strip())
for caso in range(T):
	n = int(stdin.readline().strip())
	s = list(map(int, stdin.readline().strip().split()))
	s.sort()
	ind = 0
	acum = 0
	xmin = 0
	for i in range(1, 2 * n + 1):
		if s[ind] == i:
			if acum == 0:
				xmin += 1
			else:
				acum -= 1
			ind += 1
			if ind == n:
				break
		else:
			acum += 1
	s = s[::-1]
	xmax = n
	ind = 0
	acum = 0
	for i in range(2 * n, 0, -1):
		if s[ind] == i:
			if acum == 0:
				xmax -= 1
			else:
				acum -= 1
			ind += 1
			if ind == n:
				break
		else:
			acum += 1
	print(max(xmax - xmin + 1, 0))


t = int(input())
for _ in range(t):
	n = int(input())
	come_out = list(map(int, input().split()))
	stay_in = []
	i = 0
	for j in range(1, 2 * n + 1):
		while i < n and come_out[i] < j:
			i += 1
		if i == n or (i < n and come_out[i] > j):
			stay_in.append(j)
	j = 0
	max_min = 0
	for i in range(n):
		while j < n and stay_in[j] < come_out[i]:
			j += 1
		if j < n:
			max_min += 1
			j += 1
		else:
			break
	j = n - 1
	max_max = 0
	for i in range(n - 1, -1, -1):
		while j >= 0 and stay_in[j] > come_out[i]:
			j -= 1
		if j >= 0:
			max_max += 1
			j -= 1
		else:
			break
	print(max_min - (n - max_max) + 1)


from sys import stdin, stdout
from collections import defaultdict
import math
from bisect import bisect_right

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		cnt = 0
		charge = 0
		prev = 0
		for a in arr:
			dist = a - prev - 1
			charge += dist
			prev = a
			if charge == 0:
				cnt += 1
				continue
			charge -= 1
		mx = n - cnt
		cnt = 0
		charge = 0
		prev = 2 * n + 1
		for a in reversed(arr):
			dist = prev - a - 1
			charge += dist
			prev = a
			if charge == 0:
				cnt += 1
				continue
			charge -= 1
		mn = cnt
		ans = mx - mn + 1
		stdout.write(str(ans) + '\n')
main()


for _ in range(int(input())):
	n = int(input())
	(*b,) = map(int, input().split())
	b.sort()
	lres = 0
	rres = 0
	can_be_max = [-1] * n
	can_be_min = [-1] * n
	for i in range(n):
		if b[i] < 2 * i + 2 - lres:
			can_be_max[i] = 0
			lres += 1
		else:
			can_be_max[i] = 1
		if b[n - i - 1] > 2 * n - 2 * i - 1 + rres:
			can_be_min[n - i - 1] = 0
			rres += 1
		else:
			can_be_min[n - i - 1] = 1
	ans = n + 1
	for i in range(n):
		if not can_be_min[i]:
			ans -= 1
		elif not can_be_max[i]:
			ans -= 1
	print(ans)


def binarySearch(A, B, n):
	(low, high) = (0, n)
	while low < high:
		mid = low + (high - low + 1) // 2
		flag = 1
		for index in range(mid):
			if A[index] > B[n + index - mid]:
				flag = 0
		if flag == 0:
			high = mid - 1
		else:
			low = mid
	return low
test = int(input())
for _ in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	num = 1
	b = []
	for em in a:
		if em == num:
			num += 1
			continue
		else:
			for i in range(num, em):
				b.append(i)
			num = em + 1
	for i in range(num, 2 * n + 1):
		b.append(i)
	index1 = binarySearch(a, b, n)
	index2 = n - binarySearch(b, a, n)
	print(max(0, index1 - index2 + 1))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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 as dd, deque as dq, Counter as dc
import math, string
start_time = time.time()

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def isInt(s):
	return '0' <= s[0] <= '9'
MOD = 998244353

def solve():
	N = getInt()
	B = set(getInts())
	queue = []
	ans = 0
	for i in range(1, 2 * N + 1):
		if i in B:
			if not queue:
				continue
			ans += 1
			queue.pop()
		else:
			queue.append(i)
	minX = N - ans
	queue = []
	ans = 0
	for i in range(2 * N, 0, -1):
		if i in B:
			if not queue:
				continue
			ans += 1
			queue.pop()
		else:
			queue.append(i)
	maxX = ans
	return maxX - minX + 1
for _ in range(getInt()):
	print(solve())


import sys, os, getpass
import heapq as hq
import math, random, functools, itertools
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
OFFLINE_TEST = getpass.getuser() == 'hkmac'

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

def solve_(k, lst):
	if k == 1:
		return 1
	sett = set(lst)
	maxable = 0
	minable = 0
	spaces = 0
	for i in range(1, k * 2 + 1):
		if i in sett:
			if spaces > 0:
				maxable += 1
				spaces -= 1
		else:
			spaces += 1
	spaces = 0
	for i in range(k * 2, 0, -1):
		if i in sett:
			if spaces > 0:
				minable += 1
				spaces -= 1
		else:
			spaces += 1
	log(maxable, minable)
	return minable - (k - maxable) + 1

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

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

def read_strings(rows):
	return [input().strip() for _ in range(rows)]
for case_num in range(int(input())):
	k = int(input())
	lst = list(map(int, input().split()))
	res = solve(k, lst)
	print(res)


for z in range(int(input())):
	n = int(input())
	a = [1] * (2 * n)
	for i in map(int, input().split()):
		a[i - 1] = -1
	x = 0
	s = 0
	for i in a:
		if i < 0:
			if s > 0:
				x += 1
				s -= 1
		else:
			s += 1
	x = n - x
	y = 0
	s = 0
	for j in range(2 * n - 1, -1, -1):
		if a[j] < 0:
			if s > 0:
				y += 1
				s -= 1
		else:
			s += 1
	print(abs(x - y) + 1)


import sys
from bisect import bisect_left
input = sys.stdin.buffer.readline
T = int(input())
for _ in range(T):
	(n, b) = (int(input()), list(map(int, input().split())))
	setb = set(b)
	rb = [u for u in range(1, 2 * n + 1) if not u in setb]
	sm = [0] * (n + 2)
	for (i, u) in enumerate(rb):
		p = bisect_left(b, u)
		(p1, p2) = (max(p - i, 0), n - 1 - i)
		(p3, p4) = (0 + n - i, min(p - 1 + n - i, n))
		if p1 <= p2:
			sm[p1] += 1
			sm[p2 + 1] -= 1
		if p3 <= p4:
			sm[p3] += 1
			sm[p4 + 1] -= 1
	for u in range(1, n + 2):
		sm[u] += sm[u - 1]
	cc = sum([1 for u in sm if u == n])
	print(cc)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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 RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

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

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

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

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

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

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

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

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

@bootstrap
def gdfs(r, p):
	if len(g[r]) == 1 and p != -1:
		yield None
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None
t = N()
for i in range(t):
	n = N()
	b = RLL()
	b.sort()
	mi = [0] * n
	blank = 0
	if b[-1] < 2 * n:
		mi[-1] = 1
		blank = 2 * n - b[-1] - 1
	for i in range(n - 2, -1, -1):
		if b[i] == b[i + 1] - 1:
			if not blank:
				mi[i] = mi[i + 1]
			else:
				blank -= 1
				mi[i] = mi[i + 1] + 1
		else:
			mi[i] = mi[i + 1] + 1
			blank += b[i + 1] - b[i] - 2
	ma = [0] * n
	blank = 0
	if b[0] > 1:
		ma[0] = 1
		blank = b[0] - 2
	for i in range(1, n):
		if b[i] == b[i - 1] + 1:
			if not blank:
				ma[i] = ma[i - 1]
			else:
				ma[i] = ma[i - 1] + 1
				blank -= 1
		else:
			ma[i] = ma[i - 1] + 1
			blank += b[i] - b[i - 1] - 2
	ans = mi[0] - (n - ma[-1]) + 1
	print(ans)


from sys import stdin
import sys
tt = int(input())
for loop in range(tt):
	n = int(stdin.readline())
	b = list(map(int, stdin.readline().split()))
	b.append(2 * n + 1)
	rem = []
	nex = 1
	for i in b:
		while nex != i:
			rem.append(nex)
			nex += 1
		nex += 1
	l = 0
	r = n + 1
	while r - l != 1:
		m = (l + r) // 2
		flag = True
		for i in range(m):
			if b[m - 1 - i] > rem[n - 1 - i]:
				flag = False
				break
		if flag:
			l = m
		else:
			r = m
	maxx = l
	l = 0
	r = n + 1
	while r - l != 1:
		m = (l + r) // 2
		flag = True
		for i in range(m):
			if rem[m - 1 - i] >= b[n - 1 - i]:
				flag = False
				break
		if flag:
			l = m
		else:
			r = m
	minx = n - l
	print(max(0, maxx - minx + 1))


import math
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque

def f(n, b):
	a = [[i + 1, 0] for i in range(2 * n)]
	nex = 0
	for i in range(2 * n):
		if a[i][0] == b[nex]:
			a[i][1] = 1
			nex += 1
			if nex >= n:
				break
	i = 0
	j = 0
	minpos = [0 for i in range(n + 1)]
	mipos = 0
	maxpos = [0 for i in range(n + 1)]
	mapos = 0
	minpos[mipos] = 1
	maxpos[mapos] = 1
	mipos += 1
	mapos += 1
	while i < 2 * n and j < 2 * n:
		if not a[i][1]:
			i += 1
			if j < i:
				j = i
		else:
			while j < 2 * n:
				if a[i][0] < a[j][0] and (not a[j][1]):
					break
				j += 1
			if j < 2 * n:
				minpos[mipos] = 1
				mipos += 1
				i += 1
				j += 1
			else:
				break
	i = 2 * n - 1
	j = 2 * n - 1
	while i >= 0 and j >= 0:
		if not a[i][1]:
			i -= 1
			if j > i:
				j = i
		else:
			while j >= 0:
				if a[i][0] > a[j][0] and (not a[j][1]):
					break
				j -= 1
			if j >= 0:
				maxpos[mapos] = 1
				mapos += 1
				i -= 1
				j -= 1
			else:
				break
	maxpos = maxpos[::-1]
	ans = 0
	for i in range(n + 1):
		ans += minpos[i] & maxpos[i]
	return ans
t = int(input())
result = []
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	result.append(f(n, b))
for i in range(t):
	print(result[i])


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	c = 0
	s = set(arr)
	ans = 0
	for i in range(n):
		c = max(c, arr[i])
		while c in s:
			c += 1
		s.add(c)
		if c <= 2 * n:
			ans += 1
	c = 2 * n + 1
	s = set(arr)
	bns = 0
	for i in range(n - 1, -1, -1):
		c = min(c, arr[i])
		while c in s:
			c -= 1
		s.add(c)
		if c > 0:
			bns += 1
	print(ans + bns + 1 - n)


import sys
for _ in range(int(sys.stdin.readline().strip())):
	n = int(sys.stdin.readline().strip())
	a = list(map(int, sys.stdin.readline().strip().split(' ')))
	ind = 0
	võimalused = 0
	minc = 0
	for i in range(1, 2 * n + 1, 1):
		if ind < n and a[ind] == i:
			võimalused += 1
			ind += 1
		elif võimalused > 0:
			võimalused -= 1
			minc += 1
	võimalused = 0
	axc = 0
	ind -= 1
	for i in range(2 * n, 0, -1):
		if ind > -1 and a[ind] == i:
			ind -= 1
			võimalused += 1
		elif võimalused > 0:
			võimalused -= 1
			axc += 1
	print(minc + axc - n + 1)


from collections import deque

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	In_a = [False] * (2 * n + 1)
	for v in a:
		In_a[v] = True
	b = []
	for v in range(2 * n, 0, -1):
		if In_a[v] == False:
			b.append(v)

	def possible(K):
		tmpa = a[:K]
		tmpb = b[:K][::-1]
		return all((av < bv for (av, bv) in zip(tmpa, tmpb)))
	l = 0
	r = n + 1
	while r - l > 1:
		med = (r + l) // 2
		if possible(med) == False:
			r = med
		else:
			l = med
	a.reverse()
	b.reverse()

	def possible(K):
		tmpb = b[:K]
		tmpa = a[:K][::-1]
		return all((av > bv for (av, bv) in zip(tmpa, tmpb)))
	l2 = 0
	r2 = n + 1
	while r2 - l2 > 1:
		med = (r2 + l2) // 2
		if possible(med) == False:
			r2 = med
		else:
			l2 = med
	print(l - n + l2 + 1)

def main():
	testcase = int(input())
	for i in range(testcase):
		solve()
	return
main()


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

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

def si():
	return input().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	for _ in range(ii()):
		n = ii()
		a = li()
		f = [0] * (2 * n + 1)
		for i in a:
			f[i] = 1
		x = []
		for i in range(1, 2 * n + 1):
			if f[i] == 0:
				x.append(i)

		def check_left(mid):
			for i in range(mid):
				if a[i] > x[n - mid + i]:
					return 0
			return 1

		def check_right(mid):
			for i in range(mid, n):
				if a[i] < x[i - mid]:
					return 0
			return 1
		l = 0
		r = n
		(left, right) = (n, 0)
		while l <= r:
			mid = l + r >> 1
			if check_left(mid):
				right = mid
				l = mid + 1
			else:
				r = mid - 1
		(l, r) = (0, n)
		while l <= r:
			mid = l + r >> 1
			if check_right(mid):
				left = mid
				r = mid - 1
			else:
				l = mid + 1
		print(right - left + 1)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
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()
inf = 10 ** 16
md = 10 ** 9 + 7
from bisect import bisect
for _ in range(II()):
	n = II()
	bb = LI()
	inb = [False] * (2 * n + 1)
	for b in bb:
		inb[b] = True
	aa = []
	for a in range(1, 2 * n + 1):
		if inb[a]:
			continue
		aa.append(a)
	dd = []
	for (i, b) in enumerate(bb):
		j = bisect(aa, b)
		d = i - j
		dd.append(d)
	mx = max(dd)
	mn = min(dd)
	ans = n + 1
	if mx >= 0:
		ans -= mx + 1
	if mn < 0:
		ans += mn
	print(ans)


import sys
import math

def read_generator():
	while True:
		tokens = sys.stdin.readline().rstrip().split(' ')
		for t in tokens:
			yield t
reader = read_generator()

def readword():
	return next(reader)

def readint():
	return int(next(reader))

def readfloat():
	return float(next(reader))

def readline():
	return input()

def readlistint(n):
	return [readint() for _ in range(n)]

def readliststr(n):
	return [readword() for _ in range(n)]

def readlistfloat(n):
	return [readfloat() for _ in range(n)]

def solve(n, b):
	j = 0
	a = []
	for i in range(1, 2 * n + 1):
		if j == n or b[j] > i:
			a.append(i)
		else:
			j += 1
	j = 0
	for i in range(n):
		if j < n and a[i] > b[j]:
			j += 1
	mx = n - j
	a = list(reversed(a))
	b = list(reversed(b))
	j = 0
	for i in range(n):
		if j < n and a[i] < b[j]:
			j += 1
	return abs(mx - j) + 1
tests = readint()
for test in range(tests):
	n = readint()
	b = list(sorted(readlistint(n)))
	print(solve(n, b))


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split(' ')))
	a = 1
	y = []
	for i in range(n + 1):
		for a in range(a, t[i % n] if n - i > 0 else n * 2 + 1):
			y.append(a)
		a = t[i % n] + 1 if n - i > 0 else t[i - 1] + 1
	k = 0
	ans2 = 0
	ans1 = 0
	while k < 2:
		ans1 = ans2
		ans2 = 0
		(lo, hi) = (0, n - 1)
		while hi >= lo:
			i = (lo + hi) // 2
			j = 0
			test = True
			while test and j <= i:
				if t[j] > y[n - 1 - i + j]:
					test = False
				j = j + 1
			if test:
				ans2 = i + 1
				lo = i + 1
			else:
				hi = i - 1
		(t, y) = (y, t)
		k = k + 1
	print(ans1 - (n - ans2) + 1)


for t in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	isIn = [False] * (2 * n)
	for elem in b:
		isIn[elem - 1] = True
	minCnt = 0
	maxCnt = 0
	cnt = 0
	for elem in isIn:
		cnt += elem * 2 - 1
		if cnt < minCnt:
			minCnt = cnt
		if cnt > maxCnt:
			maxCnt = cnt
	print(n + 1 - (maxCnt - minCnt))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	e = [1] * (2 * n + 1)
	e[0] = 0
	for i in range(n):
		e[l[i]] = 0
	s = SegmentTree(e)
	ans = [0] * (n + 1)
	ans[0] = 1
	ans1 = [0] * (n + 1)
	ans1[0] = 1
	t = 1
	re = 0
	cur = 0
	for i in range(1, n + 1):
		if s.query(l[i - 1] + 1, 2 * n) >= re + 1:
			ans[i] = 1
		if i < n:
			cur += l[i] - l[i - 1] - 1
			cur = min(t, cur)
			re = max(0, t - cur)
		t += 1
	t = 1
	re = 0
	cur = 0
	for i in range(n, 0, -1):
		if s.query(0, l[i - 1] - 1) >= re + 1:
			ans1[n - i + 1] = 1
		if i > 1:
			cur += l[i - 1] - l[i - 2] - 1
			cur = min(t, cur)
			re = max(0, t - cur)
		t += 1
	fi = 0
	for i in range(n + 1):
		if ans[i] == ans1[n - i] == 1:
			fi += 1
	print(fi)


from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(input())
	bb = [int(a) for a in input().split()]
	mxy = 0
	gaps = 0
	last = 0
	for b in bb:
		gaps += b - last - 1
		if gaps >= 1:
			mxy += 1
			gaps -= 1
		last = b
	mnx = n - mxy
	mxx = 0
	gaps = 0
	last = n * 2 + 1
	for b in bb[::-1]:
		gaps += last - b - 1
		if gaps >= 1:
			mxx += 1
			gaps -= 1
		last = b
	print(mxx - mnx + 1)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	arr = [False] * (2 * n)
	for x in input().split():
		arr[int(x) - 1] = True
	left = 0
	available = 0
	for x in arr:
		if x:
			available += 1
		elif available:
			available -= 1
			left += 1
	right = 0
	available = 0
	for x in reversed(arr):
		if x:
			available += 1
		elif available:
			available -= 1
			right += 1
	print(left - n + right + 1)


from sys import stdin, stdout

def pairs(n, b_a):
	x_a = []
	b_s = set(b_a)
	for i in range(1, 2 * n + 1):
		if i not in b_s:
			x_a.append(i)
	idx = 0
	x = 0
	for b in b_a:
		while idx < n and x_a[idx] < b:
			idx += 1
		if idx >= n:
			break
		x += 1
		idx += 1
	idx = n - 1
	y = 0
	for i in range(n - 1, -1, -1):
		while idx >= 0 and x_a[idx] > b_a[i]:
			idx -= 1
		if idx < 0:
			break
		y += 1
		idx -= 1
	return x + 1 - (n - y)
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	b_a = list(map(int, stdin.readline().split()))
	r = pairs(n, b_a)
	stdout.write(str(r) + '\n')


import sys
import math
from collections import defaultdict, Counter, deque
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	s1 = set(b)
	low = 0
	high = 0
	s = deque()
	end = 2 * n
	prev = 1
	for j in range(n):
		s += range(prev, b[j])
		if s:
			s.popleft()
			low += 1
		else:
			while True:
				if end in s1:
					end -= 1
				else:
					end -= 1
					break
		prev = b[j] + 1
	low = n - low
	s.clear()
	prev = 2 * n
	start = 1
	for j in range(n - 1, -1, -1):
		s += range(prev, b[j], -1)
		if s:
			high += 1
			s.popleft()
		else:
			while True:
				if start in s1:
					start += 1
				else:
					start += 1
					break
		prev = b[j] - 1
	print(high - low + 1)


import sys
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

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

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
uu = t
while t > 0:
	t -= 1
	n = fi()
	a = li()
	pre = []
	suf = []
	vis = {}
	for i in a:
		vis[i] = 1
	mex = 2 * n
	c = 1
	for i in range(n - 1, -1, -1):
		if i < n - 1 and suf[-1] == 0:
			suf.append(0)
			continue
		while mex in vis or mex >= a[i]:
			mex -= 1
		if mex >= 1:
			suf.append(1)
			vis[mex] = 1
		else:
			suf.append(0)
	vis = {}
	for i in a:
		vis[i] = 1
	mex = 1
	for i in range(n):
		if i > 0 and pre[-1] == 0:
			pre.append(0)
			continue
		while mex in vis or mex <= a[i]:
			mex += 1
		if mex <= 2 * n:
			pre.append(1)
			vis[mex] = 1
		else:
			pre.append(0)
	suf = [1] + suf[::-1] + [1]
	pre = [1] + pre + [1]
	ans = 0
	for i in range(n + 1):
		if pre[i] & suf[i + 1]:
			ans += 1
	print(ans)


import sys
from bisect import bisect_right

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	B = LIST()
	C = [0] * (N * 2 + 1)
	for b in B:
		C[b] += 1
	A = []
	for i in range(1, N * 2 + 1):
		if not C[i]:
			A.append(i)
	i = 0
	cnt1 = 0
	for b in B:
		i = bisect_right(A, b, lo=i) + 1
		if i > N:
			break
		cnt1 += 1
	i = 0
	cnt2 = 0
	for a in A:
		i = bisect_right(B, a, lo=i) + 1
		if i > N:
			break
		cnt2 += 1
	ans = cnt1 - (N - cnt2) + 1
	print(ans)


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 math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	(x1, x2) = (n, 0)
	num = 0
	a = [0] + a
	for i in range(1, n + 1):
		num += a[i] - a[i - 1] - 1
		if num:
			x1 -= 1
			num -= 1
	a = a[1:] + [2 * n + 1]
	num = 0
	for i in range(n - 1, -1, -1):
		num += a[i + 1] - a[i] - 1
		if num:
			num -= 1
			x2 += 1
	print(x2 - x1 + 1)


for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	sa = set(a)
	b = []
	for i in range(1, 2 * n + 1):
		if i not in sa:
			b.append(i)
	sb = set(b)
	arr = []
	for i in range(1, 2 * n + 1):
		if i in sb:
			arr.append(1)
		else:
			arr.append(-1)
	ans = [0]
	for i in arr:
		ans.append(ans[-1] + i)
	print(n + 1 - max(ans) + min(ans))


n = int(input())
for _ in range(n):
	m = int(input())
	lst = list(map(int, input().split()))
	used = 0
	smallest = m
	for num in lst:
		if num - 1 > used:
			smallest -= 1
			used += 2
		else:
			used += 1
	used = 0
	greatest = 0
	for num in lst[::-1]:
		if 2 * m - num > used:
			greatest += 1
			used += 2
		else:
			used += 1
	print(greatest - smallest + 1)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		N = int(input())
		B = set(map(int, input().split()))
		ma = 0
		small = 0
		for i in range(1, 2 * N + 1):
			if i in B:
				small += 1
			elif small > 0:
				small -= 1
				ma += 1
		mi = N
		big = 0
		for i in range(2 * N, 0, -1):
			if i in B:
				big += 1
			elif big > 0:
				big -= 1
				mi -= 1
		print(ma - mi + 1)
main()


def main():
	cases = int(input())
	ans_list = []
	for _ in range(cases):
		n = int(input())
		b = list(map(int, input().split(' ')))
		(min_queries, max_queries) = (0, 0)
		for (i, val) in enumerate(b):
			available_maxes = val - 2 * i + min_queries - 1
			if available_maxes <= 0:
				min_queries += 1
		for (i, val) in enumerate(reversed(b)):
			available_mins = 2 * n - val - 2 * i + max_queries
			if available_mins <= 0:
				max_queries += 1
		ans_list.append(n - max_queries - min_queries + 1)
	print('\n'.join(map(str, ans_list)))
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')
main()


from sys import stdin
t = int(stdin.readline())
for case in range(t):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	need = set(a)
	missing = []
	for x in range(1, n * 2 + 1):
		if not x in need:
			missing.append(x)
	reverse = missing[::-1]
	maxD = float('inf')
	far = {}
	for x in a:
		low = 0
		high = n - 1
		while low <= high:
			mid = (low + high) // 2
			if x < reverse[mid]:
				low = mid + 1
			else:
				high = mid - 1
		far[x] = high
	aInd2 = 0
	mInd = 0
	rInd = 0
	good = True
	while good and aInd2 < n:
		if missing[mInd] < a[aInd2]:
			aInd2 += 1
			mInd += 1
		else:
			good = False
	total = 0
	if good:
		total += 1
	a.append(float('inf'))
	for (i, x) in enumerate(a[:-1]):
		maxD = min(maxD, i + far[x])
		if rInd <= maxD:
			rInd += 1
			if x == a[aInd2]:
				aInd2 += 1
			else:
				mInd -= 1
			good = True
			while good and aInd2 < n:
				if missing[mInd] < a[aInd2]:
					aInd2 += 1
					mInd += 1
				else:
					good = False
			if good:
				total += 1
		else:
			break
	print(total)


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 deque
for j in range(int(input())):
	n = int(input())
	vals = set(map(int, input().split()))
	nb = []
	b = []
	for s in range(1, 2 * n + 1):
		if s in vals:
			b.append(s)
		else:
			nb.append(s)
	lower = 0
	upper = 0
	tnb = nb.copy()
	tb = b.copy()
	count = 0
	while len(tnb) > 0:
		v0 = tnb.pop()
		if v0 < tb[-1]:
			count += 1
			tb.pop()
	lower = n - count
	tnb = deque(nb)
	tb = b.copy()
	tb.reverse()
	while len(tnb) > 0:
		v0 = tnb.popleft()
		if v0 > tb[-1]:
			upper += 1
			tb.pop()
	print(upper + 1 - lower)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
from copy import deepcopy
mod2 = 998244353

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

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

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	arr = l()
	j = 0
	new = []
	for i in range(1, 2 * n + 1):
		if j < n and arr[j] == i:
			j += 1
			continue
		new.append(i)
	cnt = 0
	for i in range(n):
		if cnt < n and new[i] > arr[cnt]:
			cnt += 1
	(arr, new) = (arr[::-1], new[::-1])
	j = 0
	for i in range(n):
		if j < n and new[i] < arr[j]:
			j += 1
	out(abs(n - cnt - j) + 1)


for t in range(int(input())):
	n = int(input())
	visited = [False for i in range(2 * n + 1)]
	b = list(map(int, input().split()))
	for i in range(n):
		visited[b[i]] = True
	i = 2 * n
	(store, w) = (0, n)
	para = 0
	while i > 0 and w > 0:
		if visited[i] == True:
			w -= 1
			store += 1
			para += 1
		elif store > 0:
			store -= 1
		else:
			w -= 1
		i -= 1
	aloo = n - para
	i = 1
	para = 0
	(store, w) = (0, n)
	while i > 0 and w > 0:
		if visited[i] == True:
			w -= 1
			store += 1
			para += 1
		elif store > 0:
			store -= 1
		else:
			w -= 1
		i += 1
	toast = para
	print(toast - aloo + 1)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
INF = 10 ** 9 + 1
t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	maxofmins = 0
	minofmaxs = 0
	maxofmaxs = 0
	minofmins = 0
	pointer = 1
	grid = [-1] * (2 * n)
	for i in b:
		grid[i - 1] = 1
	tmpmax = 0
	tmpmin = 0
	curr = 0
	for i in range(2 * n):
		curr += grid[i]
		tmpmax = max(tmpmax, curr)
		tmpmin = min(tmpmin, curr)
	print(n + tmpmin - tmpmax + 1)


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	used = [0] * (2 * n + 1)
	for x in b:
		used[x] = 1
	a = [x for x in range(1, 2 * n + 1) if used[x] == 0]
	max_ = 0
	(l, r) = (0, len(a) - 1)
	for x in b[::-1]:
		if x < a[r]:
			max_ += 1
			r -= 1
		else:
			l += 1
	min_ = 0
	(l, r) = (0, len(b) - 1)
	for x in a[::-1]:
		if x < b[r]:
			r -= 1
		else:
			min_ += 1
			l += 1
	print(max_ - min_ + 1)


import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
o = []
for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	p = f = v = w = 0
	for i in range(1, 2 * n + 1):
		if i == b[p]:
			p += 1
			if f:
				f -= 1
				v += 1
			if p == n:
				break
		else:
			f += 1
	f = 0
	p = n - 1
	for i in range(2 * n, 0, -1):
		if i == b[p]:
			p -= 1
			if f:
				f -= 1
				w += 1
			if p < 0:
				break
		else:
			f += 1
	o.append(str(w + v - n + 1))
print('\n'.join(o))


def find_forward(n, b):
	total = h = bank = 0
	z = 1
	while z <= 2 * n:
		if h != n and z == b[h]:
			if bank:
				bank -= 1
			else:
				total += 1
			h += 1
		else:
			bank += 1
		z += 1
	return total

def find_backward(n, b):
	z = 2 * n
	bank = total = 0
	h = n - 1
	while z:
		if h >= 0 and z == b[h]:
			if bank:
				bank -= 1
			else:
				total += 1
			h -= 1
		else:
			bank += 1
		z -= 1
	return total

def solve(n, b):
	forward = find_forward(n, b)
	backward = find_backward(n, b)
	return n + 1 - forward - backward

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		b = list(map(int, input().split()))
		print(solve(n, b))
main()


import sys
import math, bisect, operator
(inf, m) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 5)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
I = lambda : int(sys.stdin.readline())
neo = lambda : map(int, sys.stdin.readline().split())
Neo = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	n = int(input())
	arr = [False] * (2 * n)
	for x in input().split():
		arr[int(x) - 1] = True
	left = 0
	available = 0
	for x in arr:
		if x:
			available += 1
		elif available:
			available -= 1
			left += 1
	right = 0
	available = 0
	for x in reversed(arr):
		if x:
			available += 1
		elif available:
			available -= 1
			right += 1
	print(left - n + right + 1)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, B):
	B.sort()
	A = []
	setB = set(B)
	for x in range(1, 2 * N + 1):
		if x not in setB:
			A.append(x)
	smallestX = 0
	largestX = 0
	i = 0
	j = 0
	maxMatch = []
	while i < N and j < N:
		if A[i] < B[j]:
			maxMatch.append((A[i], B[j]))
			i += 1
			j += 1
		else:
			j += 1
	smallestX = N - len(maxMatch)
	minMatches = []
	i = 0
	j = 0
	while i < N and j < N:
		if A[i] > B[j]:
			minMatches.append((A[i], B[j]))
			i += 1
			j += 1
		else:
			i += 1
	largestX = len(minMatches)
	return largestX - smallestX + 1
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans = solve(N, B)
	print(ans)


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = [1 for i in range(2 * n)]
	for i in l:
		k[i - 1] = -1
	ans = n + 1
	cnt = 0
	mi = 0
	for i in range(2 * n):
		cnt += k[i]
		mi = max(mi, -cnt)
	ans -= mi
	cnt = 0
	mi = 0
	for i in range(2 * n - 1, -1, -1):
		cnt += k[i]
		mi = max(mi, -cnt)
	ans -= mi
	print(max(0, ans))


t = int(input())
while t:
	t -= 1
	n = int(input())
	b = list(map(int, input().split()))
	cnt = 0
	last = 0
	nans = 0
	for i in b:
		cnt += i - last - 1
		if cnt > 0:
			nans += 1
			cnt -= 1
		last = i
	b.reverse()
	xans = 0
	cnt = 0
	last = 2 * n + 1
	for i in b:
		cnt += last - i - 1
		if cnt > 0:
			xans += 1
			cnt -= 1
		last = i
	xans = n - xans
	print(abs(nans - xans) + 1)


import sys
t = int(sys.stdin.readline())
for ti in range(t):
	n = int(sys.stdin.readline())
	b = [int(a) for a in sys.stdin.readline().split()]
	max_min = -1
	min_max = n
	prev = 0
	E = n
	U = 0
	for i in range(n):
		leaved = b[i] - prev - 1
		prev = b[i]
		U = max(0, U - leaved) + 1
		E = E - leaved
		if E > U:
			max_min = i
		elif E == U:
			max_min = i
			break
		elif E < U:
			break
	E = n
	U = 0
	prev = 2 * n + 1
	for i in range(n):
		leaved = prev - b[n - i - 1] - 1
		prev = b[n - i - 1]
		U = max(0, U - leaved) + 1
		E = E - leaved
		if E > U:
			min_max = n - i - 1
		elif E == U:
			min_max = n - i - 1
			break
		elif E < U:
			break
	print(max_min - min_max + 2)


import sys

def main():

	def modst(a, s):
		ret = 1
		while s:
			if s % 2:
				ret = ret * a % mod
			a = a * a % mod
			s //= 2
		return ret

	def Cnk(n, k):
		return (k <= n and n >= 0) * (f[n] * modst(f[k] * f[n - k] % mod, mod - 2) % mod)
	n = int(sys.stdin.readline().strip())
	q = list(map(int, sys.stdin.readline().split()))
	s = set(q)
	(f, ans, res, l, r) = (2 * n, 0, 0, 0, 0)
	for i in range(1, f + 1):
		if i in s:
			if l:
				l -= 1
				ans += 1
		else:
			l += 1
	for i in range(f, 0, -1):
		if i in s:
			if r:
				r -= 1
				res += 1
		else:
			r += 1
	print(abs(ans + res - n) + 1)
for i in range(int(input())):
	main()


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	n = I()
	a = L()
	v = [1] * (n * 2 + 1)
	v[0] = 0
	for i in a:
		v[i] = 0
	v = [i for i in range(2 * n + 1) if v[i]]
	l = 0
	r = n - 1
	x = 0
	y = n - 1
	p1 = p2 = 0
	for i in range(n):
		if a[i] > v[l]:
			l += 1
		else:
			r -= 1
			p1 += 1
		if a[-1 - i] < v[y]:
			y -= 1
			p2 += 1
		else:
			x += 1
	print(p2 - p1 + 1)


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	(maxi, mini, t, pos) = (0, 0, 0, 0)
	for i in range(0, n):
		t -= b[i] - pos - 1
		mini = min(mini, t)
		t += 1
		maxi = max(maxi, t)
		pos = b[i]
	print(n - maxi + mini + 1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
r = 1
while r <= T:
	n = int(input())
	b = list(map(int, input().split()))
	ans = 0
	occu = [False] * (2 * n + 2)
	for i in range(n):
		occu[b[i]] = True
	s = 1
	l = 2 * n
	maxbig = 0
	minbig = n
	for i in range(n):
		while occu[s]:
			s += 1
		if b[i] > s:
			maxbig += 1
			s += 1
		else:
			while occu[l]:
				l -= 1
			l -= 1
	s = 1
	l = 2 * n
	for i in range(n - 1, -1, -1):
		while occu[l]:
			l -= 1
		if b[i] < l:
			minbig -= 1
			l -= 1
		else:
			while occu[s]:
				s += 1
			s += 1
	print(maxbig - minbig + 1)
	r += 1


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
import functools
from operator import ixor
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	x = 0
	y = 0
	w = 1
	for i in range(1, n):
		if a[i] == a[i - 1] + 1:
			w += 1
		elif w > a[i] - a[i - 1] - 1:
			x += a[i] - a[i - 1] - 1
			w -= a[i] - a[i - 1] - 2
		else:
			x += w
			w = 1
	if a[-1] != 2 * n:
		if w > 2 * n - a[-1]:
			x += 2 * n - a[-1]
			w -= 2 * n - a[-1]
		else:
			x += w
			w = 0
	y = n - w
	a = a[::-1]
	w = 1
	for i in range(1, n):
		if a[i] == a[i - 1] - 1:
			w += 1
		elif w > abs(a[i - 1] - a[i] - 1):
			x += abs(a[i - 1] - a[i] - 1)
			w -= abs(a[i - 1] - a[i] - 2)
		else:
			x += w
			w = 1
	if a[-1] != 1:
		if w > a[-1] - 1:
			x += a[-1] - 1
			w -= a[-1] - 1
		else:
			x += w
			w = 0
	x = w
	print(y - x + 1)


from collections import defaultdict, deque
import sys
import bisect
input = sys.stdin.readline
mod = 1000000007
t = int(input())
for ii in range(t):
	n = int(input())
	b = [int(i) for i in input().split() if i != '\n']
	ind = [0] * (2 * n)
	for i in b:
		ind[i - 1] = 1
	(present, absent, maxa) = (0, 0, 0)
	for i in range(2 * n):
		if ind[i] == 1:
			present += 1
		else:
			absent += 1
		if present > 0 and absent == 0:
			present = 0
		else:
			maxa = min(present, absent)
			present = maxa
	(present, absent, mina) = (0, 0, 0)
	for i in range(2 * n - 1, -1, -1):
		if ind[i] == 1:
			present += 1
		else:
			absent += 1
		if present > 0 and absent == 0:
			present = 0
		else:
			mina = min(present, absent)
			present = mina
	mina = n - mina
	print(abs(maxa - mina) + 1)


def binary(a, c, n):
	(ans, low, high) = (0, 0, n - 1)
	while low <= high:
		k = (low + high) // 2
		flag = 1
		for i in range(k + 1):
			if a[i] > c[n - 1 - k + i]:
				flag = 0
		if flag:
			ans = k + 1
			low = k + 1
		else:
			high = k - 1
	return ans
for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	H = [0] * (2 * n)
	for i in b:
		H[i - 1] = 1
	a = []
	c = []
	for i in range(2 * n):
		if H[i] == 0:
			a.append(i)
		else:
			c.append(i)
	n1 = binary(a, c, n)
	n2 = n - binary(c, a, n)
	print(max(0, n1 - n2 + 1))


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr = sorted(arr)
	val = arr[0]
	s = set(arr)
	q = [i for i in range(1, 2 * n + 1)]
	m = 0
	counter = 0
	for i in arr:
		while 1:
			if q[counter] in s:
				counter += 1
			else:
				break
		if i > q[counter]:
			m += 1
			counter += 1
	mini = n - m
	maxi = n
	q = [i for i in range(1, 2 * n + 1)][::-1]
	m = 0
	counter = 0
	for i in arr[::-1]:
		while 1:
			if q[counter] in s:
				counter += 1
			else:
				break
		if i < q[counter]:
			m += 1
			counter += 1
	mini1 = 0
	maxi1 = m
	ans = min(maxi1, maxi) - max(mini, mini1) + 1
	print(max(0, ans))


import math
import sys
input = iter(sys.stdin.read().splitlines()).__next__

def solve():
	n = int(input())
	b = [int(i) - 1 for i in input().split()]
	b_set = [False] * (2 * n)
	for b_i in b:
		b_set[b_i] = True
	x_lower_bound = 0
	slack = 0
	for i in range(2 * n):
		if b_set[i]:
			if slack:
				slack -= 1
			else:
				x_lower_bound += 1
		else:
			slack += 1
	other_lower_bound = 0
	slack = 0
	for i in range(2 * n - 1, -1, -1):
		if b_set[i]:
			if slack:
				slack -= 1
			else:
				other_lower_bound += 1
		else:
			slack += 1
	return abs(x_lower_bound - (n - other_lower_bound)) + 1
t = int(input())
output = []
for _ in range(t):
	output.append(solve())
print(*output, sep='\n')


def solve():
	n = int(input())
	B = [int(t) - 1 for t in input().split()]
	exists = [0] * (2 * n)
	for x in B:
		exists[x] = 1

	def f(it):
		v = 0
		for i in it:
			if exists[i]:
				v += 1
			else:
				v = max(0, v - 1)
		return v
	R = n - f(range(2 * n))
	L = f(reversed(range(2 * n)))
	ans = R - L + 1
	print(ans)
import sys, os, io
input = lambda : sys.stdin.readline().rstrip('\r\n')
stdout = io.BytesIO()
sys.stdout.write = lambda s: stdout.write(s.encode('ascii'))
for _ in range(int(input())):
	solve()
os.write(1, stdout.getvalue())