Athenaeus has just finished creating his latest musical composition and will present it tomorrow to the people of Athens. Unfortunately, the melody is rather dull and highly likely won't be met with a warm reception.

His song consists of $n$ notes, which we will treat as positive integers. The diversity of a song is the number of different notes it contains. As a patron of music, Euterpe watches over composers and guides them throughout the process of creating new melodies. She decided to help Athenaeus by changing his song to make it more diverse.

Being a minor goddess, she cannot arbitrarily change the song. Instead, for each of the $n$ notes in the song, she can either leave it as it is or increase it by $1$.

Given the song as a sequence of integers describing the notes, find out the maximal, achievable diversity.


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10000$) — the number of test cases. Then $t$ test cases follow, each one is described in two lines.

In the first line of each test case there is a single integer $n$ ($1 \leq n \leq 10^5$) denoting the length of the song. The next line contains a sequence of $n$ integers $x_1, x_2, \ldots, x_n$ $(1 \leq x_1 \leq x_2 \leq \ldots \leq x_n \leq 2 \cdot n)$, describing the song.

The sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case, you should output a single line containing precisely one integer, the maximal diversity of the song, i.e. the maximal possible number of different elements in the final sequence.


-----Examples-----

Input
5
6
1 2 2 2 5 6
2
4 4
6
1 1 3 4 4 5
1
1
6
1 1 1 2 2 2
Output
5
2
6
1
3


-----Note-----

In the first test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence $1, \underline{3}, 2, 2, \underline{6}, \underline{7}$, which has $5$ different elements (increased elements are underlined).

In the second test case, Euterpe can increase the first element to obtain the sequence $\underline{5}, 4$, which has $2$ different elements.

In the third test case, Euterpe can increase the second, fifth and sixth element to obtain the sequence $1, \underline{2}, 3, 4, \underline{5}, \underline{6}$, which has $6$ different elements.

Difficulty: EASY
Tags: Dynamic programming

Greedy algorithms
Skill types: Dynamic programming

Greedy algorithms

Starter code:

Solutions:
from sys import stdin
input = stdin.readline

def lastmin(arr):
	curr = None
	cnt = [0] * (max(arr) + 3)
	for i in arr:
		cnt[i] += 1
	for i in range(len(arr)):
		if arr[i] != curr:
			curr = arr[i]
			if cnt[arr[i]] > 1:
				arr[i] += 1
				cnt[arr[i]] += 1
	return len(set(arr))
for i in range(int(input())):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(lastmin(lst))


def solve(n, d):
	d.sort()
	u = set()
	for i in d:
		if i not in u:
			u.add(i)
		else:
			u.add(i + 1)
	print(len(u))

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		d = input()
		d = [int(i) for i in d.split()]
		solve(n, d)
main()


for _ in range(int(input())):
	n = int(input())
	x = sorted(list(map(int, input().split(' '))))
	s = set()
	for i in x:
		if i in s:
			s.add(i + 1)
		else:
			s.add(i)
	print(len(s))


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	l[-1] += 1
	for i in range(n - 2, -1, -1):
		if l[i + 1] - l[i] > 1:
			l[i] += 1
	s = set(l)
	print(len(s))
	t -= 1


def solve(arr):
	n = len(arr)
	dp = [[1, arr[0]]] + [None for i in range(n - 1)]
	for i in range(1, n):
		(ans, M) = dp[i - 1]
		if arr[i] > M:
			dp[i] = [ans + 1, arr[i]]
		elif arr[i] == M:
			dp[i] = [ans + 1, arr[i] + 1]
		else:
			dp[i] = [ans, M]
	return dp[-1][0]
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	ans.append(solve(arr))
for i in ans:
	print(i)


import collections as cc
import math as mt
import sys
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	ar = I()
	ans = len(set(ar))
	te = set()
	for i in range(1, n):
		if ar[i] == ar[i - 1] or ar[i] in te:
			ar[i] += 1
		te.add(ar[i])
	print(len(set(ar)))


from collections import defaultdict
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 func(arr):
	d1 = defaultdict(int)
	for i in arr:
		d1[i] += 1
	for i in arr:
		if d1[i] == 1:
			continue
		d1[i + 1] += 1
		d1[i] -= 1
	return len(d1)

def main():
	for _ in range(int(input())):
		_ = int(input())
		arr = list(map(int, input().split()))
		print(func(arr))
	return
main()


for k in range(int(input())):
	input()
	a = list(map(int, input().split()))
	co = 1
	cu = a[0]
	for r in a[1:]:
		if cu < r:
			co += 1
			cu = r
		elif cu == r:
			co += 1
			cu = r + 1
	print(co)


for i in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	s = set()
	for j in nums:
		if j in s:
			s.add(j + 1)
		else:
			s.add(j)
	print(len(s))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	l1 = set()
	for i in l:
		if i not in l1:
			l1.add(i)
		else:
			l1.add(i + 1)
	print(len(l1))


cases = int(input())
while cases:
	n = input()
	arr = map(int, input().split())
	cases -= 1
	seen = set()
	for i in arr:
		if i in seen and i + 1 not in seen:
			seen.add(i + 1)
		elif i not in seen:
			seen.add(i)
	print(len(seen))


for i in range(int(input())):
	input()
	x = list(map(int, input().split()))
	se = set()
	for _ in x:
		if _ in se:
			se.add(_ + 1)
		else:
			se.add(_)
	print(len(se))


t = int(input())
for tcs in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	if n < 3:
		print(n)
	else:
		for i in range(1, n - 1):
			if l[i] > l[i - 1] and l[i] < l[i + 1]:
				c += 1
			elif l[i] < l[i + 1]:
				l[i] += 1
		if l[n - 2] == l[n - 1]:
			l[n - 1] += 1
		print(len(set(l)))


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	prev = -1
	ans = 0
	for i in range(n):
		if arr[i] <= prev:
			arr[i] = arr[i] + 1
		if arr[i] > prev:
			prev = arr[i]
			ans += 1
	print(ans)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	li = [int(z) for z in input().split()]
	arr = []
	for i in range(max(li) + 3):
		arr.append(0)
	for i in range(n):
		arr[li[i]] += 1
	cnt = 0
	for i in range(len(arr) - 1):
		if arr[i] > 1:
			arr[i + 1] += 1
	for i in range(len(arr)):
		if arr[i] > 0:
			cnt += 1
	print(cnt)


for i in range(int(input())):
	n = int(input())
	nlist = list(map(int, input().split()))
	nlist.sort()
	for i in range(1, n):
		if nlist[i] <= nlist[i - 1]:
			nlist[i] += 1
	print(len(set(nlist)))


t = int(input())
for Z in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = set()
	for i in l:
		if i not in s:
			s.add(i)
		elif i + 1 not in s:
			s.add(i + 1)
	print(len(s))


def NO():
	return print('NO')

def YES():
	return print('YES')

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

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

def STR():
	return input()

def MAP():
	return map(int, input().split())
for _ in range(INT()):
	n = INT()
	x = LIST()
	d = {}
	for y in range(n):
		if x[y] not in d:
			d[x[y]] = 1
		else:
			d[x[y] + 1] = 1
	print(len(d.keys()))


res = ''
for _ in range(int(input())):
	n = int(input())
	arr = tuple(map(int, input().split()))
	s = set()
	ans = 0
	for i in arr:
		if i in s:
			if i + 1 not in s:
				s.add(i + 1)
				ans += 1
		else:
			s.add(i)
			ans += 1
	res += '%d\n' % ans
print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().strip().split()))
	li.reverse()
	li[0] = li[0] + 1
	for i in range(1, n):
		if li[i - 1] != li[i] and li[i - 1] != li[i] + 1:
			li[i] = li[i] + 1
	s = set(li)
	print(len(s))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	last_note = -1
	result = 0
	for el in a:
		if el > last_note:
			result += 1
			last_note = el
		elif el == last_note:
			result += 1
			last_note += 1
	print(result)


for i in range(int(input())):
	n = int(input())
	s = [int(i) for i in input().split()]
	for j in range(n - 1):
		if s[j] >= s[j + 1]:
			s[j + 1] += 1
	print(len(set(s)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[i] <= a[i - 1]:
			a[i] += 1
	print(len(set(a)))


from sys import stdin
from collections import Counter
from math import pow, sqrt, factorial, log10, log
from itertools import permutations, combinations, combinations_with_replacement
input = stdin.readline

def solve(n, a):
	prv = 0
	res = 0
	ok = 0
	for i in a:
		res += i != prv
		ok |= i == prv
		if prv + 1 < i:
			res += ok
			ok = 0
		prv = i
	res += ok
	print(res)
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	solve(n, a)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	mas = [0] * (2 * n + 10)
	inp = list(map(int, input().split()))
	for j in range(n):
		mas[inp[j]] += 1
	res = 0
	for j in range(2 * n + 10):
		if mas[j] > 0:
			res += 1
		if mas[j] > 1:
			mas[j] -= 1
			mas[j + 1] += 1
	if mas[-1] > 0:
		res += 1
	ans.append(res)
for i in ans:
	print(i)


import collections
t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	s = collections.Counter(l)
	c = 0
	k = list(s.keys())
	for i in k:
		if s[i] > 1:
			if i + 1 in s:
				s[i + 1] += 1
			else:
				c += 1
	print(len(s.keys()) + c)


t = int(input())
for _ in range(t):
	n = int(input())
	x = [int(e) for e in input().split()]
	a = set()
	for i in range(n - 1, -1, -1):
		if x[i] + 1 not in a:
			a.add(x[i] + 1)
		elif x[i] not in a:
			a.add(x[i])
	print(len(a))


T = int(input())
for __ in range(T):
	N = int(input())
	listi = list(map(int, input().split()))
	seti = set()
	for i in range(N):
		if listi[i] in seti:
			listi[i] += 1
			seti.add(listi[i])
		else:
			seti.add(listi[i])
	print(len(seti))


import sys
import math, bisect
(inf, mod) = (float('inf'), 10 ** 9 + 7)
sys.setrecursionlimit(10 ** 6)
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 = I()
	A = Neo()
	d = defaultdict(int)
	Ans = 0
	for i in sorted(A):
		if i in d:
			if i + 1 in d:
				continue
			Ans += 1
			d[i + 1] = 1
		else:
			Ans += 1
			d[i] = 1
	print(Ans)


t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split(' ')))
	s = set()
	for a in x:
		if a not in s:
			s.add(a)
		else:
			s.add(a + 1)
	print(len(s))


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = [0] * (2 * n + 2)
	for i in a:
		count[i] += 1
	for i in range(len(a) - 1, -1, -1):
		if count[a[i] + 1] == 0:
			count[a[i] + 1] += 1
			count[a[i]] -= 1
			a[i] += 1
	print(len(set(a)))


tt = int(input())
for x in range(tt):
	n = input()
	lis = list(map(int, input().split()))
	ans = set()
	for y in lis:
		if y in ans:
			if y + 1 not in ans:
				ans.add(y + 1)
		else:
			ans.add(y)
	print(len(ans))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	st = set()
	for x in map(int, input().split()):
		if x in st:
			x += 1
		st.add(x)
	print(len(st))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = set()
	for i in range(n):
		if l[i] in s:
			s.add(l[i] + 1)
		else:
			s.add(l[i])
	print(len(s))


T = int(input())
for i in range(T):
	n = int(input())
	L = list(map(int, input().split()))
	l = set()
	for i in range(n):
		if L[i] in l:
			L[i] += 1
		l.add(L[i])
	print(len(l))


t = int(input())
result = []
for i in range(0, t):
	n = int(input())
	a = [int(s) for s in input().split()]
	b = [a[0]]
	for j in range(1, n - 1):
		if a[j - 1] == a[j] and a[j] != a[j + 1]:
			a[j] += 1
	if a[-1] in a[:-1]:
		a[-1] += 1
	an = set(a)
	result.append(str(len(an)))
print('\n'.join(result))


for _ in range(int(input())):
	n = int(input())
	song = [int(i) for i in input().split()]
	song.sort(reverse=True)
	n = set()
	for i in song:
		if i + 1 not in n:
			n.add(i + 1)
		else:
			n.add(i)
	print(len(n))


for _ in range(int(input())):
	n = int(input())
	A = [int(x) for x in input().split()]
	S = set()
	for a in A:
		if a not in S:
			S.add(a)
		else:
			S.add(a + 1)
	print(len(S))


import sys
import math
from bisect import bisect_left
from collections import defaultdict

def get_lcp(s, suffix_array):
	s = s + '$'
	n = len(s)
	lcp = [0] * n
	pos = [0] * n
	for i in range(n - 1):
		pos[suffix_array[i]] = i
	k = 0
	for i in range(n - 1):
		if k > 0:
			k -= 1
		if pos[i] == n - 1:
			lcp[n - 1] = -1
			k = 0
			continue
		else:
			j = suffix_array[pos[i] + 1]
			while max([i + k, j + k]) < n and s[i + k] == s[j + k]:
				k += 1
			lcp[pos[i]] = k
	return lcp

def get_suffix_array(word):
	suffix_array = [('', len(word))]
	for position in range(len(word)):
		sliced = word[len(word) - position - 1:]
		suffix_array.append((sliced, len(word) - position - 1))
	suffix_array.sort(key=lambda x: x[0])
	return [item[1] for item in suffix_array]

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

def bin_search(collection, element):
	i = bisect_left(collection, element)
	if i != len(collection) and collection[i] == element:
		return i
	else:
		return -1

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		x = list(map(int, input().split()))
		x.sort(reverse=True)
		cnt = defaultdict(int)
		used = defaultdict(lambda : False)
		for i in range(n):
			cnt[x[i]] += 1
		for j in range(3):
			for i in range(n):
				if not used[i] and cnt[x[i]] >= 1 and (cnt[x[i] + 1] == 0):
					used[i] = True
					cnt[x[i]] -= 1
					cnt[x[i] + 1] += 1
					x[i] += 1
		s = set()
		for i in range(n):
			s.add(x[i])
		print(len(s))
main()


for s in [*open(0)][2::2]:
	p = -1
	r = f = 0
	t = []
	for x in [*map(int, s.split()), 300000.0]:
		if x - p > 1:
			l = len({*t})
			r += l + (l < len(t))
			t = [x]
		else:
			t += (x,)
		p = x
	print(r)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = [0] * (2 * n + 1)
	for i in l:
		a[i] += 1
	c = 0
	for i in range(1, 2 * n):
		if a[i] > 1 and a[i + 1] == 0:
			a[i + 1] = 1
		elif a[i] > 1:
			a[i + 1] += 1
	for i in a:
		if i:
			c += 1
	if a[-1] > 1:
		c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	li = set()
	c = 0
	for i in lis:
		if i in li:
			li.add(i + 1)
		else:
			li.add(i)
	print(len(li))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = dict(Counter(l))
	l.sort()
	m = list(c.keys())
	for key in c.keys():
		if c[key] > 1:
			if key + 1 not in c.keys():
				m.append(key + 1)
			else:
				c[key + 1] += 1
	print(len(m))


for _ in range(int(input())):
	n = int(input())
	c = set()
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] not in c:
			c.add(a[i])
		else:
			c.add(a[i] + 1)
	print(len(c))


result = []
for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	before = l[0]
	cnt = 1
	for i in range(1, n, 1):
		if l[i] > before:
			before = l[i]
			cnt += 1
		elif l[i] == before:
			before += 1
			cnt += 1
	result.append(cnt)
print(*result, sep='\n')


for i in [*open(0)][2::2]:
	l = [*map(int, i.split())]
	s = set()
	for i in range(len(l)):
		if l[i] in s:
			s.add(l[i] + 1)
		else:
			s.add(l[i])
	print(len(s))


cases = int(input())
for i in range(cases):
	length = int(input())
	song = [int(word) for word in input().split()]
	for note in range(len(song) - 1):
		if song[note] >= song[note + 1]:
			song[note + 1] += 1
	counter = len(set(song))
	print(counter)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(0, n):
		if i > 0 and i < n - 1:
			if arr[i - 1] == arr[i] and arr[i] != arr[i + 1]:
				arr[i] += 1
		if i == n - 1:
			if arr[i - 1] == arr[i]:
				arr[i] += 1
	print(len(list(set(arr))))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		x = list(map(int, input().split()))
		for i in range(1, n):
			if x[i] <= x[i - 1]:
				x[i] += 1
		prev = total = 0
		for j in range(n):
			if x[j] != prev:
				total += 1
			prev = x[j]
		print(total)
main()


def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	s = set()
	for x in a:
		if x in s:
			s.add(x + 1)
		else:
			s.add(x)
	print(len(s))
t = int(input())
for _ in range(t):
	solve()


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	d = dd(int)
	cou = 0
	for i in range(n - 1, -1, -1):
		if d[l[i] + 1] == 0:
			d[l[i] + 1] = 1
			cou += 1
		elif d[l[i]] == 0:
			cou += 1
			d[l[i]] = 1
	print(cou)
	t -= 1


for test in range(int(input())):
	(n, a) = (int(input()), list(map(int, input().split())))
	a.sort()
	p = 0
	d = {}
	for i in range(n):
		if d.get(a[i]):
			if d.get(a[i] + 1):
				continue
			else:
				d[a[i] + 1] = 1
				p += 1
		else:
			d[a[i]] = 1
			p += 1
	print(p)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	s = sorted(list(map(int, input().split(' '))))
	s2 = set()
	for i in s:
		s2.add(i + 1 if i in s2 else i)
	print(len(s2))


t = int(input())
for i in range(t):
	n = int(input())
	s = set()
	num = map(int, input().split())
	for j in num:
		if j in s:
			s.add(j + 1)
		else:
			s.add(j)
	print(len(s))


import sys
input = sys.stdin.readline
import math
from collections import *
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr = arr[::-1]
	h = Counter()
	for i in range(n):
		if h[arr[i] + 1] != 1:
			arr[i] += 1
			h[arr[i]] = 1
		else:
			h[arr[i]] = 1
	print(len(set(arr)))


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

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

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

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

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

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 6 + 1
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == 1000000000.0:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return

def prime(n, d):
	prm = set()
	while n != 1:
		prm.add(spf[n])
		n = n // spf[n]
	for ele in prm:
		d[ele] = d.get(ele, 0) + 1
	return
mod = 998244353

def solve():
	n = II()
	a = L()
	d = {}
	for ele in a:
		d[ele] = d.get(ele, 0) + 1
	st = list(set(a))
	st.sort()
	for ele in st:
		if d.get(ele, 0) > 1:
			d[ele + 1] = d.get(ele + 1, 0) + (d[ele] - 1)
	cnt = 0
	for ele in d:
		if d.get(ele, 0) > 0:
			cnt += 1
	print(cnt)
	return
t = II()
for i in range(t):
	solve()


for i in range(int(input())):
	a = int(input())
	listing2 = list(map(int, input().split()))
	slovar = {}
	for x in listing2:
		if x in slovar:
			if x + 1 in slovar:
				pass
			else:
				slovar[x + 1] = 1
		else:
			slovar[x] = 1
	print(len(slovar))


def notes(arr):
	mydict = {}
	for i in range(0, len(arr)):
		if arr[i] in mydict:
			mydict[arr[i]] += 1
		else:
			mydict[arr[i]] = 1
	count = 0
	for i in mydict:
		if mydict[i] >= 2:
			j = i + 1
			if j in mydict:
				mydict[j] += 1
				count += 1
			else:
				count += 2
		else:
			count += 1
	print(count)
t = int(input())
for i in range(0, t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	notes(arr)


import sys
input = sys.stdin.readline
inputLines = sys.stdin.readlines

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

def readStrList():
	return list(map(lambda x: x.strip(), inputLines()))

def indexOf(l: list, elem: int):
	return l.index(elem) if elem in l else -1

def lastIndexOf(l: list, elem: int):
	indexes = [idx for (idx, val) in enumerate(l) if val == elem]
	return max(indexes) if len(indexes) > 0 else -1

def solution():
	for _ in range(int(input())):
		n = int(input())
		arr = readIntList()
		for i in range(1, n):
			if arr[i - 1] == arr[i] and (i == n - 1 or arr[i] < arr[i + 1]):
				arr[i] += 1
		print(len(set(arr)))
solution()


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	arr = [0 for i in range(2 * n + 5)]
	for i in li:
		arr[i] += 1
	for i in range(2 * n + 4):
		if arr[i] >= 2:
			arr[i] -= 1
			arr[i + 1] += 1
	count = 0
	for i in arr:
		if i:
			count += 1
	print(count)


def calculate(myList):
	distinct = set()
	for i in myList:
		if i not in distinct:
			distinct.add(i)
		elif i + 1 not in distinct:
			distinct.add(i + 1)
	return len(distinct)
t = int(input())
answer = []
for i in range(t):
	n = int(input())
	l = map(int, input().split())
	answer.append(calculate(l))
for i in answer:
	print(i)


T = int(input())
for i in range(0, T):
	n = int(input())
	array = input().split(' ')
	for i in range(0, len(array)):
		array[i] = int(array[i])
	seen = [False] * (2 * n + 2)
	for i in range(0, len(array)):
		if not seen[array[i]]:
			seen[array[i]] = True
		else:
			array[i] += 1
			seen[array[i]] = True
	totalValues = 0
	for i in range(0, len(array)):
		if i == 0 or (i != 0 and array[i] != array[i - 1]):
			totalValues += 1
	print(totalValues)


from collections import Counter
for i in range(int(input())):
	x = int(input())
	y = list(map(int, input().split()))
	for j in range(len(y) - 1):
		if y[j] != y[j + 1] and y[j - 1] == y[j]:
			y[j] += 1
	if y[len(y) - 1] == y[len(y) - 2]:
		y[len(y) - 1] += 1
	z = Counter(y)
	print(len(z))


from collections import Counter
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	count = Counter(arr)
	keys = list(count.keys())
	Dict = defaultdict(int)
	for i in keys:
		if count[i] > 1:
			Dict[i + 1] += 1
			Dict[i] += 1
		elif Dict[i] > 0:
			Dict[i + 1] += 1
		else:
			Dict[i] += 1
	ans = len(list(Dict.keys()))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	seen = set()
	for el in arr:
		if el in seen and el + 1 in seen:
			continue
		elif el in seen:
			seen.add(el + 1)
		else:
			seen.add(el)
	print(len(seen))


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	x_count = Counter(x)
	modified_x = list()
	for xi in x:
		if x_count[xi] > 1 and x_count.get(xi + 1, 0) <= 1:
			modified_x.append(xi + 1)
			x_count[xi + 1] += 1
			x_count[xi] -= 1
		else:
			modified_x.append(xi)
	print(len(set(modified_x)))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	prev = l[0]
	ch = 0
	ans = 1
	for i in range(1, n):
		if l[i] == prev:
			ans += 1 - ch
			ch = 1
		else:
			if ch != 1 or l[i] - prev != 1:
				ans += 1
				ch = 0
			else:
				ans += 1
				ch = 1
			prev = l[i]
	print(ans)


import sys
input = sys.stdin.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		x = list(map(int, input().split())) + [10 ** 9]
		ans = len(set(x)) - 1
		has_repeat = 0
		for i in range(1, n + 1):
			if x[i] == x[i - 1]:
				has_repeat = 1
			if x[i] >= x[i - 1] + 2 and has_repeat:
				ans += 1
				has_repeat = 0
		print(ans)
prog()


for _ in [0] * int(input()):
	n = int(input())
	r = list(map(int, input().split()))
	for i in range(n - 1):
		if r[i] >= r[i + 1]:
			r[i + 1] += 1
	print(len(set(r)))


for j in range(int(input())):
	n = int(input())
	s = set()
	a = [int(i) for i in input().split()]
	for i in a:
		if i in s:
			s.add(i + 1)
		else:
			s.add(i)
	print(len(s))


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	st = set()
	st.add(arr[0])
	for i in arr[1:]:
		if i in st:
			st.add(i + 1)
		else:
			st.add(i)
	print(len(st))


result = []
for t in range(int(input())):
	n = int(input())
	nos = list(map(int, input().split()))
	h = set()
	for i in nos:
		if i in h:
			if i + 1 not in h:
				h.add(i + 1)
		else:
			h.add(i)
	result.append(str(len(h)))
print('\n'.join(result))


for t in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	temp = set()
	for i in arr:
		if i in temp:
			temp.add(i + 1)
		else:
			temp.add(i)
	print(len(temp))


from math import *
from sys import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	d = {}
	ans = 0
	for i in range(2 * n + 2):
		d[i] = 0
	for i in range(n):
		if d[a[i]] == 0:
			d[a[i]] += 1
			ans += 1
		elif d[a[i]] == 1 and d[a[i] + 1] == 0:
			ans += 1
			d[a[i] + 1] = 1
	print(ans)


import sys
tc = int(input())
for _ in range(tc):
	e = int(input())
	rn = ans = 0
	for n in list(map(int, input().split())):
		if rn <= n:
			rn = rn + 1 if rn == n else n
			ans = ans + 1
	print(ans)


def debug():
	for i in range(10):
		pass

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

def pw(a, b, c):
	ans = 1
	a = a % c
	if a == 0:
		return 0
	while b > 0:
		if b & 1:
			ans = ans * a % c
		b = b >> 1
		a = a * a % c
	return ans
try:
	for _ in range(int(input())):
		n = int(input())
		arr = [int(i) for i in input().split()]
		mp = {}
		ss = set()
		for i in arr:
			ss.add(i)
		x = len(ss)
		for i in arr:
			mp[i] = mp.get(i, 0) + 1
		ans = 0
		for i in range(n):
			if mp[arr[i]] > 1:
				ss.add(arr[i] + 1)
				mp[arr[i]] -= 1
				try:
					mp[arr[i] + 1] += 1
				except:
					mp[arr[i] + 1] = 1
		print(len(ss))
except EOFError as e:
	print(e)


def printList(n, totalList):
	if n == 1:
		print(1)
		return
	totalList1 = totalList
	for i in range(1, len(totalList)):
		if totalList1[i - 1] == totalList1[i] and (i == len(totalList1) - 1 or (i < len(totalList1) - 1 and totalList1[i] != totalList1[i + 1])):
			totalList1[i] += 1
	print(max(len(set(totalList)), len(set(totalList1))))
t = int(input())
for _ in range(t):
	n = int(input())
	totalList = list(map(int, input().split()))
	printList(n, totalList)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	dict1 = {}
	dict1[a[0]] = 1
	for i in range(1, n):
		if a[i] in dict1:
			dict1[a[i] + 1] = 1
		else:
			dict1[a[i]] = 1
	print(len(dict1))


t = int(input())
for _ in range(t):
	n = int(input())
	notes = list(map(int, input().strip().split()))
	seen_notes = set()
	notes.sort()
	for j in range(len(notes)):
		if notes[j] in seen_notes:
			notes[j] += 1
		seen_notes.add(notes[j])
	print(len(set(notes)))


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	arr.sort()
	s = set()
	for i in range(n):
		if arr[i] in s:
			s.add(arr[i] + 1)
		else:
			s.add(arr[i])
	print(len(s))


def solve(arr):
	res = [arr[0]]
	for e in arr[1:]:
		last_e = res[-1]
		if last_e == e:
			e += 1
		if last_e < e:
			res.append(e)
	print(len(res))
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(arr)


t = int(input())
for k in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	x = set()
	for i in range(n):
		if arr[i] in x and arr[i] + 1 not in x:
			x.add(arr[i] + 1)
		else:
			x.add(arr[i])
	print(len(x))


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
t = ri()
for _ in range(t):
	n = ri()
	a = ris()
	ans = 1
	a[-1] += 1
	for i in range(n - 2, -1, -1):
		if a[i] == a[i + 1]:
			continue
		ans += 1
		if a[i] + 1 < a[i + 1]:
			a[i] += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = set()
	ans = 0
	for i in l:
		if i in s:
			i += 1
			if i not in s:
				s.add(i)
				ans += 1
		else:
			ans += 1
			s.add(i)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	l = len(lst)
	for j in range(1, l):
		if j < l - 1:
			if lst[j] - lst[j - 1] == 0 and lst[j + 1] - lst[j - 1] >= 1:
				lst[j] += 1
		elif lst[j] - lst[j - 1] == 0:
			lst[j] += 1
	print(len(set(lst)))


t = int(input())
for test in range(0, t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	a = list(set(arr))
	dicta = {}
	for i in a:
		dicta[i] = 0
	for i in arr:
		dicta[i] = dicta[i] + 1
	k = len(a)
	for i in sorted(dicta.keys()):
		if dicta[i] == 1:
			pass
		elif dicta[i] > 1:
			if i + 1 not in dicta:
				dicta[i] = dicta[i] - 1
				dicta[i + 1] = 1
			else:
				dicta[i] = dicta[i] - 1
				dicta[i + 1] = dicta[i + 1] + 1
	print(len(dicta))


from sys import stdin
ip = stdin.readline
for _ in range(int(ip())):
	n = int(ip())
	a = list(map(int, ip().split()))
	ans = set()
	for i in a:
		if i in ans:
			ans.add(i + 1)
		else:
			ans.add(i)
	print(len(ans))


from sys import stdin

def function(list):
	list.sort()
	for i in range(len(list) - 1):
		if list[i] == list[i - 1] and list[i] != list[i + 1]:
			list[i] += 1
	if len(list) > 1:
		if list[-1] == list[-2]:
			list[-1] += 1
	return len(set(list))
n = int(input())
for i in range(n):
	stdin.readline()
	print(function([int(x) for x in stdin.readline().split()]))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	G = {}
	for i in A:
		G[i] = 0
		G[i + 1] = 0
	ans = 0
	for i in range(n):
		if G[A[i]] == 0:
			ans = ans + 1
			G[A[i]] = 1
		elif G[A[i] + 1] == 0:
			ans = ans + 1
			G[A[i] + 1] = 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = set()
	for j in range(n):
		b = a[j]
		if b not in l:
			l.add(b)
		else:
			a[j] = a[j] + 1
			l.add(b + 1)
	print(len(l))


def get_ans(notes):
	freq = {}
	ans = 0
	for i in notes:
		if i not in freq:
			freq[i] = 1
			ans += 1
		elif i + 1 not in freq:
			ans += 1
			freq[i + 1] = 1
		else:
			freq[i + 1] += 1
	return ans
t = int(input())
answers = []
for _ in range(t):
	n = int(input())
	notes = list(map(int, input().split()))
	answers.append(get_ans(notes))
for ans in answers:
	print(ans)


def hill_valley(array, i):
	if i == 0 or i == len(array) - 1:
		return 0
	if array[i + 1] > array[i] and array[i - 1] > array[i] or (array[i + 1] < array[i] and array[i - 1] < array[i]):
		return 1
	return 0

def main():
	n = int(input())
	array = list(map(int, input().split()))
	s = set()
	for i in range(n):
		if array[i] in s:
			s.add(array[i] + 1)
		else:
			s.add(array[i])
	return len(s)
case = int(input())
for i in range(case):
	print(main())


t = int(input())
for _ in range(t):
	n = int(input())
	notes = list(map(int, input().split()))
	s = set()
	for note in notes:
		if note not in s:
			s.add(note)
		elif note + 1 not in s:
			s.add(note + 1)
	print(len(s))


for i1 in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	end = l[-1]
	ref = [0 for i in range(0, end + 3)]
	for i in l:
		ref[i] += 1
	for i in range(len(ref)):
		if ref[i] > 1:
			ref[i + 1] += 1
			ref[i] -= 1
	ans = 0
	for i in ref:
		if i != 0:
			ans += 1
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def iterative(f, stack=[]):

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

class SortedList:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	def __len__(self):
		return self._len

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

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

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

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

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

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

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

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

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

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

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

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

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

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

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

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

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

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

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def arr1d(n, v):
	return [v] * n

def arr2d(n, m, v):
	return [[v] * m for _ in range(n)]

def arr3d(n, m, p, v):
	return [[[v] * p for _ in range(m)] for i in range(n)]

def solve():
	n = N()
	ar = lis()
	ar.sort()
	s = set()
	for i in range(n):
		if ar[i] not in s:
			s.add(ar[i])
			continue
		s.add(ar[i] + 1)
	print(len(s))
testcase(int(inp()))


for _ in range(int(input())):
	n = int(input())
	melody = map(int, input().split())
	final = set()
	for note in melody:
		if note in final:
			note += 1
		final.add(note)
	print(len(final))


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = defaultdict(lambda : 0)
	ar = set()
	for el in input().split():
		arr[int(el)] += 1
		ar.add(int(el))
	prev = None
	ans = set()
	for el in ar:
		ans.add(el)
		if arr[el] > 1:
			ans.add(el + 1)
			arr[el + 1] += 1
		prev = el
	if arr[prev] > 1:
		ans.add(prev + 1)
	print(len(ans))


import sys
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	for i in range(1, n):
		if x[i] <= x[i - 1]:
			x[i] += 1
	print(len(set(x)))


t = int(input())
while t:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	ans = {}
	for x in a:
		if x in ans:
			if x + 1 not in ans:
				ans[x + 1] = 1
		else:
			ans[x] = 1
	print(len(ans))


t = int(input())
res = []
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	check = [0 for j in range(2 * n + 1)]
	count = 0
	for j in range(n):
		if check[arr[j] - 1] == 0:
			check[arr[j] - 1] = 1
			count = count + 1
		elif check[arr[j]] == 0:
			check[arr[j]] = 1
			count = count + 1
	res.append(count)
for i in range(len(res)):
	print(res[i])


from collections import defaultdict
for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		d[a[i]] += 1
	s = set()
	a = list(set(a))
	n = len(a)
	for i in range(n):
		if d[a[i]] > 1:
			s.add(a[i] + 1)
			d[a[i] + 1] += 1
		s.add(a[i])
	print(len(s))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr[-1] += 1
	for i in range(n - 2, -1, -1):
		if arr[i + 1] > arr[i] + 1:
			arr[i] += 1
	print(len(set(arr)))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	res = set()
	for i in l:
		if i in res:
			res.add(i + 1)
		else:
			res.add(i)
	print(len(res))


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in [wtf[i:i + 2] for i in range(1, len(wtf), 2)]:
	n = int(t[0])
	X = list(map(int, t[1].split()))
	tmp = []
	for i in range(1, n):
		if X[i - 1] == X[i] and (i + 1 < n and X[i + 1] != X[i] or i + 1 == n):
			X[i] += 1
	print(len(set(X)))


for s in [*open(0)][2::2]:
	t = set()
	for x in map(int, s.split()):
		t |= {x + (x in t)}
	print(len(t))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	ans = 0
	for i in range(n):
		if a[i] not in d:
			ans += 1
			d[a[i]] = 1
		elif a[i] + 1 not in d:
			ans += 1
			d[a[i] + 1] = 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	yolo = set()
	for i in range(n):
		if x[i] in yolo:
			if x[i] + 1 in yolo:
				pass
			else:
				yolo.add(x[i] + 1)
		else:
			yolo.add(x[i])
	print(len(yolo))


def solve(n, nums):
	hash = {}
	ans = 0
	for num in nums:
		if num not in hash:
			hash[num] = 1
			ans += 1
		elif num + 1 not in hash:
			hash[num + 1] = 1
			ans += 1
	return ans
t = int(input())
while t:
	n = int(input())
	nums = list(map(int, input().split()))
	print(solve(n, nums))
	t -= 1


def msc(size):
	lista = list(map(int, input().split()))
	new = []
	tar1 = 0
	tar2 = 0
	for i in range(size):
		if tar1 == lista[i] and tar2 != lista[i]:
			new.append(lista[i] + 1)
			(tar1, tar2) = (lista[i] + 1, tar1)
		if tar1 != lista[i] and tar2 != lista[i]:
			new.append(lista[i])
			(tar1, tar2) = (lista[i], tar1)
	return len(new)

def main():
	case = int(input())
	resp = [0] * case
	for i in range(case):
		size = int(input())
		resp[i] = msc(size)
	for i in range(case):
		print(resp[i])
main()


def solve():
	n = int(input())
	A = [int(x) for x in input().split()]
	cnt = [0 for x in range(max(A) + 3)]
	for x in A:
		cnt[x] = cnt[x] + 1
	ans = 0
	for i in range(max(A) + 2):
		if cnt[i] > 1:
			cnt[i + 1] = cnt[i + 1] + 1
		if cnt[i]:
			ans = ans + 1
	print(ans)
import sys
T = int(input())
for i in range(T):
	solve()


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

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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	a.sort()
	have = set()
	for i in range(n):
		if a[i] in have:
			a[i] += 1
		have.add(a[i])
	print(len(set(a)))


def func(n, a):
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	di = {}
	for i in d:
		if d[i] == 1:
			if i not in di:
				di[i] = 1
			elif i + 1 not in d:
				di[i + 1] = 1
			else:
				di[i + 1] = 1 + d[i + 1]
			continue
		di[i] = d[i] - 1
		if i + 1 not in d:
			di[i + 1] = 1
		else:
			di[i + 1] = 1 + d[i + 1]
	return len(di)
t = int(input())
l = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l.append([n, a])
for i in range(len(l)):
	print(func(l[i][0], l[i][1]))


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from array import array
from collections import Counter as ctr
from collections import deque as dq
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])

def temp():
	for _ in range(int(input())):
		n = int(input())
		a = arr(li())
		b = set()
		if n == 1:
			print(1)
		else:
			for i in a:
				if i in b:
					b.add(i + 1)
				else:
					b.add(i)
			print(len(b))

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = li()
		a.sort(reverse=True)
		a = arr(a)
		b = arr(list(set(a)))
		c = len(b)
		print(c)
temp()


L = []

def solve(t):
	for i in range(t):
		n = int(input())
		arr = set()
		for i in map(int, input().split()):
			if i in arr:
				i += 1
			arr.add(i)
		L.append(len(arr))
t = int(input())
solve(t)
for i in L:
	print(i)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = Counter(l)
	c = 0
	for i in range(2 * n + 1, 0, -1):
		if d[i] > 0:
			c += 1
	for j in range(2 * n + 1, 0, -1):
		if d[j] == 1 and d[j + 1] == 0:
			d[j + 1] = 1
			d[j] -= 1
		elif d[j] > 1 and d[j + 1] == 0:
			c += 1
			d[j + 1] = 1
			d[j] -= 1
	print(c)


def handle(notes):
	i = 1
	while i < len(notes):
		notes[i] += 1
		try:
			if notes[i] - 1 == notes[i + 1]:
				notes[i] -= 1
			elif notes[i] - 1 > notes[i - 1]:
				notes[i] -= 1
		except:
			pass
		i += 1
	return len(set(notes))
t = int(input().strip())
for case in range(t):
	n = int(input().strip())
	notes = [int(x) for x in input().strip().split()]
	print(handle(notes))


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	n = ini()
	a = sorted(inl())
	b = [0] * (2 * n + 2)
	ans = 0
	for i in a:
		if b[i] == 0:
			ans += 1
			b[i] = 1
		elif b[i + 1] == 0:
			ans += 1
			b[i + 1] = 1
	print(ans)


n = int(input())
for _ in range(n):
	x = int(input())
	dic = {}
	lis = list(map(int, input().split()))
	for i in lis:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	temp = list(dic.keys())
	for d in temp:
		if dic[d] > 1:
			if d + 1 not in dic:
				dic[d + 1] = 1
			else:
				dic[d] -= 1
				dic[d + 1] += 1
	print(len(dic))


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	for i in range(1, n):
		if x[i - 1] >= x[i]:
			x[i] += 1
	print(len(set(x)))


def fun(ls, num):
	count = 0
	set1 = set()
	for i in range(num):
		if ls[i] in set1:
			if ls[i] + 1 in set1:
				continue
			else:
				set1.add(ls[i] + 1)
				count += 1
		else:
			set1.add(ls[i])
			count += 1
	print(count)
ipt = int(input())
for i in range(ipt):
	num = int(input())
	ls = input().split()
	ls = list(map(int, ls))
	fun(ls, num)


t = int(input())
for rep in range(t):
	n = int(input())
	input1 = input()
	l = list(map(int, input1.split(' ')))
	l.sort()
	k = int(l[0])
	i = 1
	while i < n:
		if k >= l[i]:
			l[i] += 1
		k = l[i]
		i += 1
	a_set = set(l)
	number_of_unique_values = len(a_set)
	print(number_of_unique_values)


for ii in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set()
	for jj in range(n):
		if a[jj] not in b:
			b.add(a[jj])
		elif a[jj] + 1 not in b:
			b.add(a[jj] + 1)
	print(len(b))


t = int(input())
for _ in range(t):
	sett = set()
	n = int(input())
	lst = [int(x) for x in input().split()]
	for i in range(n):
		if lst[i] not in sett:
			sett.add(lst[i])
		elif lst[i] + 1 not in sett:
			sett.add(lst[i] + 1)
	print(len(sett))


t = int(input())
for k in range(t):
	n = int(input())
	prev = 0
	cnt = 0
	for cur in map(int, input().split()):
		if cur == prev:
			cur += 1
			cnt += 1
		elif cur < prev:
			cur = prev
		else:
			cnt += 1
		prev = cur
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	x = [int(i) for i in input().split()]
	ans = set()
	x[len(x) - 1] += 1
	ans.add(x[len(x) - 1])
	for i in range(len(x) - 2, -1, -1):
		if x[i + 1] - x[i] > 1:
			x[i] += 1
		ans.add(x[i])
	print(len(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	s = set()
	ans = 0
	li = [int(i) for i in input().split()]
	for i in li:
		if i in s:
			if i + 1 not in s:
				s.add(i + 1)
				ans += 1
		else:
			s.add(i)
			ans += 1
	print(ans)


for _ in range(int(input())):
	input()
	song = [int(x) for x in input().split()]
	song.sort(reverse=True)
	diversity = 0
	previous = float('inf')
	for i in song:
		if i + 1 < previous:
			previous = i + 1
			diversity += 1
		elif i < previous:
			previous = i
			diversity += 1
	print(diversity)


from sys import stdin, stdout
n = int(stdin.readline())
for _ in range(n):
	ll = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	s = set()
	for x in l:
		if x not in s:
			s.add(x)
		else:
			s.add(x + 1)
	print(len(s))


for _ in range(int(input())):
	n = int(input())
	note = list(map(int, input().rstrip().split()))
	if n == 1:
		print('1')
	else:
		if note[1] == note[0]:
			note[1] += 1
		for i in range(2, n):
			if note[i] == note[i - 1] or note[i] == note[i - 2]:
				note[i] += 1
		print(len(set(note)))


from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	c = Counter(l)
	t = defaultdict(int)
	ans = 0
	for x in c:
		if c[x] == 1:
			t[x] = t[x - 1]
			ans += 1
		else:
			t[x] = 1
			ans += 2 if t[x - 1] == 0 else 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))[::-1]
	x[0] += 1
	m = x[0]
	for i in range(1, n):
		if x[i] + 1 < m:
			x[i] += 1
		m = x[i]
	print(len(set(x)))


import sys
for test in range(int(input())):
	n = int(input())
	arr = list(map(int, sys.stdin.readline().split()))
	arr.sort()
	arr1 = {}
	for i in arr:
		arr1[i] = 0
	for i in arr:
		arr1[i] += 1
	for i in arr:
		if arr1[i] > 1:
			if i + 1 in arr1:
				arr1[i + 1] += 1
			else:
				arr1[i + 1] = 1
	print(len(arr1))


tst = int(input())
for i in range(tst):
	n = int(input())
	lst2 = []
	stt = input()
	lst = stt.split()
	lst[0] = int(lst[0])
	for k in range(n - 1):
		if int(lst[k + 1]) <= int(lst[k]):
			lst[k + 1] = int(lst[k + 1]) + 1
		else:
			lst[k + 1] = int(lst[k + 1])
	st = set(lst)
	print(len(st))


from math import *
from collections import *
for y in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	ans = 0
	i = n - 1
	gt = lst[-1]
	while i >= 0:
		temp = lst[i]
		i -= 1
		cnt = 1
		while i >= 0 and lst[i] == temp:
			i -= 1
			cnt += 1
		if cnt == 1:
			ans += 1
			if gt == temp + 1:
				gt = temp
			else:
				gt = temp + 1
		else:
			if gt == temp + 1:
				ans += 1
			else:
				ans += 2
			gt = temp
	print(ans)


n = int(input())
for _ in range(n):
	m = int(input())
	arr = list(map(int, input().split()))
	dct = {}
	so = 0
	tong = 0
	for i in arr:
		if i == so:
			tong += 1
			so += 1
		elif i > so:
			tong += 1
			so = i
	print(tong)


import sys

def main():
	res = ''
	input = sys.stdin.readline
	print = sys.stdout.write
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		osn = set()
		for i in range(n):
			cur = a[i]
			if cur in osn:
				osn.add(cur + 1)
			osn.add(cur)
		sub_res = str(len(osn)) + '\n'
		res += sub_res
	print(res)
main()


for _ in range(int(input())):
	input()
	s = [int(i) for i in input().split()]
	for i in range(1, len(s)):
		if s[i] <= s[i - 1]:
			s[i] += 1
	print(len(set(s)))


from collections import defaultdict
maxi = 0

def maximise(l, pos):
	pass

def solve():
	n = int(input())
	l = [int(x) for x in input().split()]
	s = set()
	for i in l:
		a = i
		if a in s:
			a += 1
		s.add(a)
	print(len(s))
for _ in range(int(input())):
	solve()


import collections
import math
from heapq import *
for t in range(1, int(input()) + 1):
	n = int(input())
	nums = list(map(int, input().split()))
	nums.sort()
	out = set([])
	while nums:
		val = nums.pop()
		if val + 1 not in out:
			out.add(val + 1)
		else:
			out.add(val)
	print(len(out))


import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import gcd, log
MOD = int(1000000000.0 + 7)
INF = int(1e+20)
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
n = int(input())
for _ in range(n):
	m = int(input())
	vis = set()
	arr = li()
	for i in arr:
		if i not in vis:
			vis.add(i)
		else:
			vis.add(i + 1)
	print(len(vis))


N = int(input())
for _ in range(N):
	n = int(input())
	notes = list(map(int, input().split()))[::-1]
	contain = [0 for i in range(max(notes) + 2)]
	for note in notes:
		contain[note] += 1
	for note in notes:
		used = False
		try:
			if contain[note + 1] == 0:
				contain[note + 1] += 1
				contain[note] -= 1
		except IndexError:
			continue
	ans = 0
	for i in contain:
		if i:
			ans += 1
	print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdmap = lambda : map(int, stdstr().split())
stdarr = lambda : list(map(int, stdstr().split()))
mod = 1000000007
for _ in range(stdint()):
	n = stdint()
	arr = stdarr()
	c = Counter()
	for i in range(n):
		if arr[i] in c:
			arr[i] += 1
			c[arr[i]] = 1
		else:
			c[arr[i]] = 1
	res = len(set(arr))
	print(res)


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split())) + [1000000000]
	count = len(set(a)) - 1
	s = 0
	for i in range(1, n + 1):
		if a[i] == a[i - 1]:
			s = 1
		if a[i] >= a[i - 1] + 2 and s > 0:
			count += 1
			s = 0
	print(count)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sp = [0] * (max(a) + 2)
	for i in range(len(a) - 1, -1, -1):
		if sp[a[i] + 1] == 0:
			sp[a[i] + 1] = 1
		elif sp[a[i]] == 0:
			sp[a[i]] = 1
	ans.append(sp.count(1))
for i in ans:
	print(i)


innum = lambda : int(input())
inmul = lambda : map(int.input().split())
instr = lambda : str(input())
inarr = lambda : list(map(int, input().split()))

def solve():
	n = innum()
	a = inarr()
	d = {}
	for i in a:
		if i in d:
			d[i + 1] = d.get(i + 1, 0) + 1
		else:
			d[i] = 1
	print(len(d))

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


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	freq = [[0, 0] for i in range(2 * n + 2)]
	for i in arr:
		freq[i][0] += 1
	for i in range(2 * n + 2):
		if freq[i][0] > 1:
			freq[i + 1][1] += freq[i][0] - 1
			freq[i][0] = 1
		elif freq[i][0] >= 1 and freq[i][0] + freq[i][1] > 1:
			freq[i + 1][1] += freq[i][0]
			freq[i][0] = 0
	ans = 0
	for i in freq:
		if i[0] + i[1] > 0:
			ans += 1
	print(ans)


for tc in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	book = {}
	for i in l:
		if i not in book:
			book[i] = 1
		elif i in book and i + 1 not in book:
			book[i + 1] = 1
	print(len(book))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	k = int(sys.stdin.readline())
	r = set()
	l = list(map(int, sys.stdin.readline().split(' ')))
	for i in l[:]:
		if i not in r:
			r.add(i)
		else:
			r.add(i + 1)
	sys.stdout.write(str(len(set(r))) + '\n')


import sys, os
from math import sqrt, gcd, ceil, log, floor
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def l(s):
	c = 0
	for i in s:
		if i == '(':
			c += 1
		else:
			c -= 1
		if c < 0:
			return -1
	return c

def r(s):
	c = 0
	for i in s[::-1]:
		if i == ')':
			c += 1
		else:
			c -= 1
		if c < 0:
			return -1
	return c

def main():
	ans_ = []
	for _ in range(int(input())):
		n = int(input())
		arr = Counter(read())
		c = 0
		for i in range(1, 2 * n + 2):
			if arr[i] > 1:
				c += 1
				arr[i + 1] += 1
			elif arr[i] == 1:
				c += 1
		ans_.append(c)
	for i in ans_:
		print(i)
main()


t = int(input())
for q in range(t):
	n = int(input())
	mass = [int(x) for x in input().split()]
	f = False
	answer = 0
	last = -1
	local = 0
	for i in range(n):
		if last < mass[i]:
			if last + 1 < mass[i]:
				if f:
					answer += 1
				f = False
			last = mass[i]
			local = 1
		else:
			local += 1
			f = True
	if f:
		answer += 1
	print(answer + len(set(mass)))


t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	seen = set()
	for i in range(len(nums)):
		if nums[i] not in seen:
			seen.add(nums[i])
		elif nums[i] + 1 not in seen:
			seen.add(nums[i] + 1)
	print(len(seen))


for _ in range(int(input())):
	n = int(input())
	ar = [int(t) for t in input().split()]
	has = [0] * (2 * n + 10)
	for x in ar:
		if not has[x]:
			has[x] = 1
		else:
			has[x + 1] = 1
	print(sum(has))


def get_variety(n, notes):
	if n == 1:
		return 1
	notes = list(map(int, notes.split()))
	change = False
	variety = 0
	for i in range(n - 1):
		if notes[i] == notes[i + 1]:
			if not change:
				variety += 1
			change = True
		elif change:
			notes[i] += 1
			variety += 1
			change = notes[i] == notes[i + 1]
		else:
			variety += 1
	return variety + 1
for _ in range(int(input())):
	n = int(input())
	print(get_variety(n, input()))