Ehab loves number theory, but for some reason he hates the number $x$. Given an array $a$, find the length of its longest subarray such that the sum of its elements isn't divisible by $x$, or determine that such subarray doesn't exist.

An array $a$ is a subarray of an array $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.


-----Input-----

The first line contains an integer $t$ $(1 \le t \le 5)$ — the number of test cases you need to solve. The description of the test cases follows.

The first line of each test case contains 2 integers $n$ and $x$ ($1 \le n \le 10^5$, $1 \le x \le 10^4$) — the number of elements in the array $a$ and the number that Ehab hates.

The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i \le 10^4$) — the elements of the array $a$.


-----Output-----

For each testcase, print the length of the longest subarray whose sum isn't divisible by $x$. If there's no such subarray, print $-1$.


-----Example-----
Input
3
3 3
1 2 3
3 4
1 2 3
2 2
0 6

Output
2
3
-1



-----Note-----

In the first test case, the subarray $[2,3]$ has sum of elements $5$, which isn't divisible by $3$.

In the second test case, the sum of elements of the whole array is $6$, which isn't divisible by $4$.

In the third test case, all subarrays have an even sum, so the answer is $-1$.

Difficulty: EASY
Tags: Number theory

Data structures

Amortized analysis

Complete search
Skill types: Amortized analysis

Data structures

Complete search

Starter code:

Solutions:
for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	(total_sum, flag) = (0, 0)
	(first_index, last_index) = (-1, 0)
	for j in range(n):
		total_sum += a[j]
		if a[j] % x != 0:
			flag = 1
			if first_index == -1:
				first_index = j + 1
			last_index = j
	if flag == 0:
		print(-1)
	elif total_sum % x != 0:
		print(n)
	else:
		print(max(n - first_index, last_index))


t = int(input())
for i in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	print(len(set(m)))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = set(l)
	print(len(p))


for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	print(len(set(s)))


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	print(len(s))


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

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

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	m = set(arr)
	print(len(m))
t = int(input())
for _ in range(t):
	main()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	(j, k) = (0, 0)
	if sum(l) % m != 0:
		print(n)
	else:
		for i in range(n):
			if l[j] % m == 0:
				j += 1
			if l[n - k - 1] % m == 0:
				k += 1
		print(n - min(j, k) - 1)


t = int(input())
for _ in range(t):
	(n, x) = [int(x) for x in input().split()]
	s = list(map(int, input().split()))
	li = []
	for i in range(x):
		li.append([])
	li[0].append(-1)
	total = 0
	ans = -1
	for i in range(n):
		total += s[i]
		total = total % x
		li[total].append(i)
		if total != 0:
			ans = max(ans, i + 1)
	for i in range(n - 1, -1, -1):
		total += s[i]
		total = total % x
		li[total].append(i)
		if total != 0:
			ans = max(ans, n - 1 - i + 1)
	print(ans)


t = int(input())
while t > 0:
	s = input()
	num = {0}
	a = input().split()
	for k in a:
		num.add(int(k))
	print(len(num) - 1)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	As = list(map(int, input().split()))
	print(len(set(As)))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	subsum = 0
	ans = -1
	if s % x != 0:
		print(n)
	else:
		f = True
		for i in range(n):
			subsum += a[i]
			if (s - subsum) % x != 0:
				f = False
				ans = max(ans, n - 1 - i)
				break
		subsum = 0
		for i in range(n - 1, -1, -1):
			subsum += a[i]
			if (s - subsum) % x != 0:
				f = False
				ans = max(ans, i)
				break
		if f:
			print(-1)
		else:
			print(ans)


for tin in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = list(set(a))
	print(len(s))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	if sum(lst) % x == 0:
		i = 0
		while i < len(lst) and lst[i] % x == 0:
			i += 1
		j = len(lst) - 1
		while j >= 0 and lst[j] % x == 0:
			j -= 1
		if j == -1:
			print(j)
		else:
			print(max([len(lst) - i - 1, i, j, len(lst) - j - 1]))
	else:
		print(len(lst))


T = int(input())
for _ in range(1, T + 1):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(len(set(arr)))


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

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

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

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	for t in range(I()):
		(n, x) = In()
		arr = L()
		(sm1, sm2) = (sum(arr), sum(arr))
		if sm1 % x != 0:
			print(n)
		else:
			flag = 0
			for i in range(n):
				sm1 -= arr[i]
				sm2 -= arr[n - i - 1]
				if sm1 % x != 0 or sm2 % x != 0:
					flag = 1
					break
			if flag:
				print(n - i - 1)
			else:
				print(-1)
main()


def a():
	t = int(input())
	for _ in range(t):
		(n, k) = (int(x) for x in input().split())
		arr = [int(x) for x in input().split()]

		def psum(ar):
			ps = [0]
			for x in ar:
				ps.append(x + ps[-1])
			return ps

		def solve(ln, x, ps):
			for i in range(ln, 0, -1):
				if ps[i] % x != 0:
					return i
			return -1
		prefsum = psum(arr)
		ans = solve(n, k, prefsum)
		prefsum = psum(arr[::-1])
		ans = max(ans, solve(n, k, prefsum))
		print(ans)
a()


from sys import stdin

def solve(a):
	a = list(set(a))
	return len(a)

def main():
	t = int(stdin.readline().strip())
	for _ in range(t):
		stdin.readline()
		a = [int(x) for x in stdin.readline().strip().split()]
		print(solve(a))
main()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(len(Counter(a).keys()))


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	strt = a[0]
	count = 1
	for j in range(1, n):
		if a[j] > strt:
			strt = a[j]
			count += 1
	print(count)


def fun(n, l):
	l = set(l)
	print(len(l))
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	fun(n, l)


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	v = list(map(int, input().split()))
	l = 0
	su = 0
	r = n - 1
	for values in v:
		su += values
	if su % x != 0:
		print(n)
	else:
		for values in v:
			if values == 0 or values % x == 0:
				l = l + 1
			else:
				break
		v.reverse()
		for values in v:
			if values == 0 or values % x == 0:
				r = r - 1
			else:
				break
		if l == n:
			print('-1')
		else:
			r = r - 1
			l = l + 1
			if n - l >= r + 1:
				print(n - l)
			else:
				print(r + 1)
	t = t - 1


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

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

def oint():
	return int(input())
t = oint()
for _ in range(t):
	(n, x) = rint()
	a = list(rint())
	s = sum(a)
	if s % x:
		print(n)
		continue
	i1 = -1
	i2 = -1
	for i in range(n):
		if a[i] % x:
			i1 = i + 1
			break
	for i in range(n):
		if a[n - i - 1] % x:
			i2 = i + 1
			break
	if i1 == -1 and i2 == -1:
		print(-1)
		continue
	print(n - min(i1, i2))


def Sol(A, x):
	if sum(A) % x != 0:
		return len(A)
	(r, l) = (0, 0)
	Fin = False
	for i in range(len(A)):
		if A[i] % x != 0:
			r = i + 1
			Fin = True
		if A[-i - 1] % x != 0:
			l = i + 1
			Fin = True
		if Fin:
			return min(len(A) - r, len(A) - l)
	if not Fin:
		return -1
i = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, x) = i()
	A = list(i())
	print(Sol(A, x))


T = int(input())
for t_itr in range(T):
	(N, X) = map(int, input().rstrip().split())
	A = list(map(int, input().rstrip().split()))
	first = -1
	result = -1
	prefix_sum = 0
	for (i, x) in enumerate(A):
		prefix_sum += x
		if prefix_sum % X != 0:
			if result < i + 1:
				result = i + 1
			if first == -1:
				first = i
		elif first != -1:
			if result < i - first:
				result = i - first
	print(result)


n = int(input())
for g in range(n):
	k = int(input())
	l = list(map(int, input().split()))
	l.sort()
	c = 0
	for i in range(k - 1):
		if l[i] == l[i + 1]:
			c = c + 1
	print(k - c)


for _ in range(int(input())):
	n = int(input())
	print(len(set(map(int, input().split()))))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
		continue
	left = n
	right = -1
	for i in range(n):
		if a[i] % x != 0:
			left = i
			break
	for i in reversed(range(n)):
		if a[i] % x != 0:
			right = i
			break
	if left < right:
		print(n - min(left + 1, n - right))
	elif left == right:
		print(1)
	else:
		print(-1)


t = int(input())
for T in range(t):
	n = int(input())
	x = input()
	a = []
	a = x.split(' ')
	for i in range(n):
		a[i] = int(a[i])
	a.sort()
	c = 0
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			c = c + 1
	c = c + 1
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	a = list(dict.fromkeys(a))
	print(len(a))
	t -= 1


for i in range(int(input())):
	b = int(input())
	x = [int(i) for i in input().strip().split()]
	myset = set(x)
	new = list(myset)
	print(len(new))


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(set(A))
	print(len(B))


for _ in range(int(input())):
	n = int(input())
	d = {}
	li = list(map(int, input().split()))
	for i in li:
		if i not in d:
			d[i] = 1
	print(len(d))


t = int(input())
for i in range(t):
	n = int(input())
	a = dict()
	b = input().split(' ')
	c = 0
	for ele in b:
		if ele not in a:
			a[ele] = 1
			c += 1
	print(c)


for i in range(int(input())):
	k = int(input())
	a = list(map(int, input().split()))[:k]
	a = set(a)
	print(len(a))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	flag = True
	for i in arr:
		if i % x != 0:
			flag = False
	su = sum(arr)
	if flag:
		print(-1)
	elif su % x != 0:
		print(n)
	else:
		total = su
		res = 0
		for i in range(n):
			total -= arr[i]
			if total % x != 0:
				res = max(res, n - i - 1)
				break
		total = su
		for i in range(n - 1, -1, -1):
			total -= arr[i]
			if total % x != 0:
				res = max(res, i)
				break
		print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = []
	print(len(set(a)))


from collections import Counter
from collections import defaultdict
import math
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	k = len(c.keys())
	print(k)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	p = list(set(a))
	print(len(p))


for _ in range(int(input().strip(' '))):
	k = int(input().strip(' '))
	array = list(map(int, input().strip(' ').split(' ')))
	e = set()
	for i in array:
		e.add(i)
	print(len(e))


from sys import stdin, stdout
import sys
from bisect import bisect_left, bisect_right
import heapq
from collections import Counter
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	arr = list(map(int, stdin.readline().strip().split(' ')))
	stdout.write(str(len(set(arr))) + '\n')


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	n = int(input())
	a = set(list(map(int, sys.stdin.readline().split(' '))))
	print(len(a))
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


import math
import sys
import collections
from collections import defaultdict
from sys import stdin, stdout
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	pref = [0] * n
	maxl = -1
	pref[0] = arr[0]
	if pref[0] % x != 0:
		maxl = 1
	for i in range(1, n):
		pref[i] = pref[i - 1] + arr[i]
		if pref[i] % x != 0:
			maxl = i + 1
	i = 1
	j = n - 1
	while i < j:
		if (pref[j] - pref[i - 1]) % x != 0:
			maxl = max(maxl, j - (i - 1))
		i += 1
	if maxl == -1:
		for i in range(n):
			if arr[i] % x != 0:
				print(1)
				exit(0)
		print(maxl)
	else:
		print(maxl)


from sys import stdin
import math

def inp():
	return stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, x) = [int(x) for x in inp().split()]
	ar = [int(x) for x in inp().split()]
	flag = False
	if sum(ar) % x != 0:
		print(len(ar))
	else:
		cStart = 0
		while True:
			if cStart >= len(ar):
				print(-1)
				flag = True
				break
			if ar[cStart] % x != 0:
				break
			else:
				cStart += 1
		if flag:
			continue
		cEnd = n - 1
		while True:
			if ar[cEnd] % x != 0:
				break
			else:
				cEnd -= 1
		cEnd = n - cEnd
		print(len(ar) - min(cEnd, cStart + 1))


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = defaultdict(lambda : 0)
	for i in a:
		count[i] += 1
	print(len(count.keys()))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	temp = list(set(arr))
	print(len(temp))


import math
import heapq, bisect
import sys
from collections import deque
from fractions import Fraction
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

class 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 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, k) = map(int, input().split())
	ind = -1
	ind1 = n
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] % k != 0:
			if ind == -1:
				ind = i
			ind1 = i
	ans = n
	if sum(l) % k == 0:
		ans = n - min(ind + 1, n - ind1)
	if ind == -1 and ind1 == n:
		ans = -1
	print(ans)


for _ in range(int(input())):
	a = int(input())
	l = set(map(int, input().split()))
	print(len(l))


import math
t = int(input())
for i in range(t):
	(n, x) = map(int, input().strip().split(' '))
	lst = list(map(int, input().strip().split(' ')))
	s = sum(lst)
	if s % x != 0:
		print(n)
	else:
		j1 = 0
		j2 = n - 1
		f1 = 0
		while j1 < j2:
			if lst[j1] % x != 0:
				f1 = 1
				break
			elif lst[j2] % x != 0:
				f1 = 1
				break
			else:
				j1 += 1
				j2 -= 1
		if f1 == 1:
			print(min(j2 + 1, n - j1 - 1))
		else:
			print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().strip().split()))
	print(len(set(ls)))


t = int(input())
for _ in range(t):
	n = int(input())
	a = map(int, input().split())
	S = set(a)
	print(len(S))


t = int(input())
for ti in range(t):
	n = int(input())
	a = input().split()
	for i in range(n):
		a[i] = int(a[i])
	print(len(list(dict.fromkeys(a))))


T = int(input())
for i in range(T):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = 0
	c = 0
	d = 0
	e = 0
	for j in range(n):
		if a[j] % x == 0:
			b = b + 1
		c = c + a[j]
	if b == n:
		print('-1')
	elif c % x != 0:
		print(n)
	else:
		for k in range(n):
			if a[k] % x != 0:
				d = k + 1
				break
		for k in range(n - 1, -1, -1):
			if a[k] % x != 0:
				e = n - k
				break
		print(n - min(d, e))


for _ in range(int(input())):
	n = int(input())
	s1 = list(map(int, input().split()))
	list.sort(s1)
	s1 = list(set(s1))
	print(len(s1))


t = int(input())
for j in range(0, t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	aa = [0] * n
	ab = [0] * n
	sum = 0
	for i in range(0, n):
		sum = sum + a[i]
		ab[i] = sum
	sum1 = 0
	b = -1
	max = 0
	max1 = 0
	for i in range(n - 1, -1, -1):
		b = b + 1
		sum1 = sum1 + a[i]
		aa[b] = sum1
	if sum % d != 0:
		max = n
	else:
		for i in range(0, n):
			if (sum - ab[i]) % d != 0:
				max = n - i - 1
				break
	if sum1 % d != 0:
		max1 = n
	else:
		for i in range(0, n):
			if (sum1 - aa[i]) % d != 0:
				max1 = n - i - 1
				break
	if max == 0 or max1 == 0:
		print('-1')
	elif max > max1:
		print(max)
	else:
		print(max1)


for ct in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(len(set(a)))


for _ in range(int(input())):
	input()
	k = set()
	l = list(map(int, input().split()))
	for i in l:
		k.add(i)
	print(len(k))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % x != 0:
		print(n)
	else:
		l = -1
		sum1 = 0
		for i in range(n):
			sum1 += arr[i]
			if sum1 % x != 0:
				l = max(l, max(i + 1, n - (i + 1)))
		print(l)


def copy():
	a = set(input().split())
	return len(a)
for i in range(int(input())):
	input()
	print(copy())


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	allx = True
	s = sum(a)
	for i in range(n):
		if a[i] % x != 0:
			allx = False
			break
	if allx:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		i = 0
		j = n - 1
		while a[i] % x == 0:
			i += 1
		while a[j] % x == 0:
			j -= 1
		print(max(n - i - 1, j))


import math
for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(list(set(l))))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split(' ')))
	m = set(arr)
	print(len(m))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	j = n - 1
	s = sum(l)
	sx = s
	if m == 1:
		print(-1)
		continue
	if s % m != 0:
		print(n)
	else:
		ans = 0
		i = -1
		while i < j and s % m == 0:
			i += 1
			s -= l[i]
		ans = j - i
		if i == j and l[i] % m == 0:
			print(-1)
			continue
		i = 0
		j = n
		while i < j and sx % m == 0:
			j -= 1
			sx -= l[j]
		if i == j and l[i] % m == 0:
			print(-1)
			continue
		print(max(ans, j - i))


import sys
import math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	ara = inara()
	st = set()
	for num in ara:
		st.add(num)
	print(len(st))


import os, io
from sys import stdout
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	mods = [0] * n
	prev = l[0]
	mods[0] = prev % x
	for i in range(1, n):
		mods[i] = (mods[i - 1] + l[i]) % x
		prev = prev + l[i]
	first = -1
	for i in range(n):
		if mods[i] != 0:
			first = i
			break
	result = -1
	if first == -1:
		print(-1)
	else:
		m = -1
		for i in range(first, n):
			if mods[i] != 0:
				m = i + 1
			else:
				m = i - first
			result = max(result, m)
		print(result)


from collections import Counter
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	print(len(Counter(a).keys()))
	t -= 1


t = int(input())
while t:
	n = int(input())
	li = [int(i) for i in input().split()]
	li1 = set(li)
	print(len(li1))
	t -= 1


a = int(input())
for i in range(a):
	(n, p) = [int(x) for x in input().split()]
	k = [int(x) for x in input().split()]
	summ = 0
	chk = 0
	leastn = -1
	mostn = -1
	for i in range(n):
		summ += k[i]
		if k[i] % p != 0:
			chk += 1
			if leastn == -1:
				leastn = i
			mostn = i
	if summ % p != 0:
		print(n)
	elif chk == 0:
		print(-1)
	else:
		print(max(n - leastn - 1, mostn))


def answer(n, x, a):
	if sum(a) % x != 0:
		return n
	lindx = -1
	rindx = -1
	for i in range(n):
		if a[i] % x != 0:
			lindx = i
			break
	for i in range(n - 1, lindx, -1):
		if a[i] % x != 0:
			rindx = i
			break
	if lindx == -1 or rindx == -1:
		return -1
	return max(n - (lindx + 1), rindx)

def main():
	t = int(input())
	while t:
		(n, x) = [int(i) for i in input().split()]
		a = [int(i) for i in input().split()]
		print(answer(n, x, a))
		t -= 1
	return
main()


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	start = -1
	end = -1
	s = 0
	f = False
	for i in range(n):
		s += arr[i]
		if arr[i] % m != 0:
			f = True
			if start == -1:
				start = i
			end = i
	if f == False:
		print('-1')
	elif s % m != 0:
		print(n)
	else:
		print(n - min(start + 1, n - end))


n = int(input())
while n != 0:
	repeat = int(input())
	lst1 = set([int(x) for x in input().split()])
	d = len(lst1)
	print(d)
	n = n - 1


INT_MAX = 10 ** 30 + 7
MOD = 10 ** 9 + 7

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

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def calc(n, x, A):
	sum = 0
	for i in range(n):
		sum += A[i]
	if sum == 0:
		return -1
	if sum % x != 0:
		return n
	count1 = 0
	count2 = 0
	for i in range(n):
		if A[i] != 0:
			count1 = i + 1
			break
	for i in range(n - 1, -1, -1):
		if A[i] != 0:
			count2 = n - i
			break
	return max(n - count1, n - count2)
for i in range(int(input())):
	(n, x) = INPUT()
	A = INPUT()
	B = LIST_1D_ARRAY(n)
	for i in range(n):
		B[i] = A[i] % x
	a = calc(n, x, B)
	if a == 0:
		print(-1)
	else:
		print(a)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	sm = 0
	ln1 = 0
	c = 0
	for i in range(n):
		c += 1
		sm += l[i]
		if sm % x != 0:
			ln1 = c
	sm = 0
	ln2 = 0
	c = 0
	for j in range(n - 1, -1, -1):
		c += 1
		sm += l[j]
		if sm % x != 0:
			ln2 = c
	if max(ln2, ln1) == 0:
		print(-1)
	else:
		print(max(ln2, ln1))


t = int(input())
for i in range(t):
	q = int(input())
	x = set(map(int, input().split()))
	print(len(x))


t = int(input())
while t > 0:
	n = int(input())
	A = list(set(map(int, input().split())))
	print(len(A))
	t -= 1


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	arr2 = list(dict.fromkeys(arr))
	print(len(arr2))


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(x, y):
	return f(x) // (f(y) * f(x - y))
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(set(l)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	for i in range(len(A)):
		A[i] = A[i] % x
	if sum(A) % x != 0:
		print(len(A))
	else:
		z = False
		z2 = False
		for i in range(len(A)):
			if A[i] != 0:
				z = True
				break
		for j in range(len(A) - 1, -1, -1):
			if A[j] != 0:
				z2 = True
				break
		if z and z2:
			print(max(len(A) - i - 1, j))
		else:
			print(-1)


t = int(input())
for _ in range(t):
	nx = input().split(' ')
	n = int(nx[0])
	x = int(nx[1])
	arr = list(map(int, input().split(' ')))
	sum = 0
	num_of_divisible = 0
	for i in arr:
		sum += i
		if i % x == 0:
			num_of_divisible += 1
	if sum % x != 0:
		print(n)
	elif num_of_divisible == n:
		print(-1)
	else:
		prefix = 0
		suffix = n - 1
		for (i, j) in enumerate(arr):
			if j % x != 0:
				prefix = i
				break
		for i in range(n - 1, -1, -1):
			if arr[i] % x != 0:
				suffix = i
				break
		print(max(n - prefix - 1, suffix))


from math import ceil, sqrt, gcd, log, floor
from collections import deque

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

def si():
	return input()

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

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

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		print(len(set(a)))
main()


def find(arr, x):
	for (i, a) in enumerate(arr):
		if a % x:
			return i

def solve(a, n, x):
	total = sum(a)
	if total == 0:
		return -1
	if total % x != 0:
		return n
	left = find(a, x)
	right = find(a[::-1], x)
	return n - min([left, right]) - 1
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) % x for i in input().split()]
	ans = solve(a, n, x)
	print(ans)


def func(n):
	for i in range(n):
		k = int(input())
		l = list(map(int, input().split()))
		print(len(set(l)))
n = int(input())
func(n)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	(n, x) = zz()
	l = [int(i) % x for i in z().split()]
	t = sum(l)
	if t == 0:
		print(-1)
		continue
	elif t % x != 0:
		print(n)
		continue
	li = [i for i in range(n) if l[i]]
	print(max(n - li[0] - 1, li[-1]))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = [0] * (n + 1)
	for i in range(n):
		s[i + 1] = s[i] + a[i]
	mis = [n + 1] * (x + 1)
	rs = [[] for _ in range(x + 1)]
	for i in range(n + 1):
		b = s[i] % x
		mis[b] = min(mis[b], i)
		rs[b].append(i)
	mi1 = sorted(mis)[0]
	mi2 = sorted(mis)[1]
	ans = -1
	for i in range(x):
		if not len(rs[i]):
			continue
		mi = mi1
		if mis[i] == mi1:
			mi = mi2
		ans = max(ans, rs[i][-1] - mi)
	print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = map(int, input().split())
	sum = 0
	left = 0
	right = 0
	i = 0
	for e in a:
		i = i + 1
		sum = sum + e
		sum = sum % x
		if not e % x == 0:
			if left == 0:
				left = i
			right = n + 1 - i
	if left == 0:
		print(-1)
	elif not sum == 0:
		print(n)
	else:
		print(max(n - left, n - right))


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = set(A)
	ans = len(B)
	print(ans)


ans = []
t = int(input())
for q in range(t):
	(n, x) = [int(f) for f in input().split()]
	d = []
	z = 0
	nums = []
	i = 1
	for f in input().split():
		c = int(f)
		z += c
		if c % x != 0:
			nums.append(i)
		i += 1
	if z % x != 0:
		ans.append(n)
	elif len(nums) == 0:
		ans.append(-1)
	else:
		minim = n - nums[0]
		maxim = nums[len(nums) - 1] - 1
		ans.append(max(minim, maxim))
for el in ans:
	print(el)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	list = [int(j) % x for j in input().split()][:n]
	z = sum(list)
	a = 0
	b = 1
	if z % x == 0:
		if z == 0:
			print(-1)
		else:
			for i in range(len(list)):
				a += 1
				if list[i] > 0 or list[-b] > 0:
					break
				b += 1
			print(len(list) - a)
	else:
		print(len(list))


k = int(input())
for i in range(k):
	a = int(input())
	b = list(map(int, input().split()))
	c = set(b)
	d = list(c)
	if len(d) <= a:
		d.sort()
		print(len(d))
	else:
		d.sort()
		print(len(d[:a - 1]))


def solve():
	(n, x) = [int(v) for v in input().split()]
	arr = [int(v) for v in input().split()]
	s = 0
	mx = -1
	firstnodivj = n
	for i in range(n):
		s += arr[i]
		if s % x != 0:
			mx = i + 1
			firstnodivj = min(firstnodivj, i)
		else:
			mx = max(mx, i - firstnodivj)
	print(mx)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
n = []
arr = []
for i in range(t):
	n.append(int(input()))
	arr.append(list(map(int, input().split())))
for i in range(t):
	print(len(set(arr[i])))


def longSubarrWthSumDivByK(arr, n, k):
	um = {i: 0 for i in range(8)}
	mod_arr = [0 for i in range(n)]
	max = 0
	curr_sum = 0
	for i in range(n):
		curr_sum += arr[i]
		mod_arr[i] = (curr_sum % k + k) % k
	for i in range(n):
		if mod_arr[i] != 0:
			max = i + 1
		elif mod_arr[i] in um:
			um[mod_arr[i]] = i
		elif max < i - um[mod_arr[i]]:
			max = i - um[mod_arr[i]]
	return max
t = int(input())
while t > 0:
	t -= 1
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	l = [0] * (n + 1)
	l[0] = 0
	for i in range(0, n + 1):
		l[i] = arr[i - 1]
		l[i] += l[i - 1]
	sum = 0
	for i in range(1, n + 1):
		if (l[i] - l[0]) % x != 0:
			if sum < i:
				sum = i
	for i in range(n, -1, -1):
		if (l[n] - l[i]) % x != 0:
			if sum < n - i:
				sum = n - i
	if sum == 0:
		print('-1')
	else:
		print(sum)


import sys
import math

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

def read():
	return int(input())

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

def input():
	return sys.stdin.readline().strip()
cas = read()
while cas:
	n = read()
	V = get_array()
	V.sort()
	res = 0
	for i in range(0, n):
		if i == 0 or V[i] != V[i - 1]:
			res += 1
	print(res)
	cas -= 1


def solve(n, x, a):
	f = True
	sum = 0
	for i in range(n):
		sum += a[i]
		if a[i] % x != 0:
			f = False
	if sum % x != 0:
		return n
	if f:
		return -1
	start = 0
	end = n - 1
	while a[start] % x == 0 or a[end] % x == 0:
		if a[start] % x == 0:
			start += 1
		elif a[end] % x == 0:
			end -= 1
	return max(n - start - 1, end)
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(n, x, a))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	u = list(map(int, input().split()))
	for i in range(n):
		if u[i] % x != 0:
			break
	else:
		print(-1)
		continue
	if sum(u) % x != 0:
		print(n)
		continue
	for i in range(n):
		if u[i] % x != 0:
			ind1 = i
			break
	for i in range(n - 1, -1, -1):
		if u[i] % x != 0:
			ind2 = i
			break
	print(n - min(ind1 + 1, n - ind2))


T = int(input())
for _ in range(T):
	n = int(input())
	s = set(map(int, input().split()))
	print(len(s), end='\n')


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	count = 0
	for i in arr:
		if i in d:
			continue
		d[i] = 1
		count += 1
	print(count)


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l = list(set(l))
	l.sort()
	print(len(l))


testcase = int(input())
for t in range(1, testcase + 1):
	size = int(input())
	elems = list(map(int, input().split(' ')))
	dct = {}
	for e in elems:
		dct[e] = 1
	print(len(dct))


from sys import stdin, stdout
import sys
import math
INF = 1000000000.0

def get_int():
	return int(stdin.readline().strip())

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

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

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
for _ in range(int(stdin.readline())):
	(n, x) = get_ints()
	a = get_array()
	sum = 0
	for i in a:
		sum = (sum + i) % x
	if sum:
		print(n)
		continue
	s = 0
	ans = -1
	for i in range(n):
		s = (s + a[i]) % x
		if s:
			ans = max(ans, i + 1)
			ans = max(ans, n - i - 1)
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(len(set(a)))


test_cases = int(input())
for z in range(test_cases):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	count = 0
	sum = 0
	index = []
	for i in range(len(a)):
		sum += a[i]
		if a[i] % x == 0:
			count += 1
		else:
			index.append(i + 1)
	if sum % x != 0:
		print(n)
	elif count == n:
		print(-1)
	else:
		d = min(index[0], n - index[-1] + 1)
		print(n - d)


import sys
import heapq

def main():
	t = int(input())
	for _ in range(t):
		(n, x) = map(int, sys.stdin.readline().split())
		nums = list(map(int, sys.stdin.readline().split()))
		sumVal = sum(nums)
		if sumVal % x:
			print(n)
			continue
		flag = False
		for i in nums:
			if i % x:
				flag = True
				break
		if not flag:
			print(-1)
			continue
		pFront = 0
		while nums[pFront] % x == 0:
			pFront += 1
		pRear = n - 1
		while nums[pRear] % x == 0:
			pRear -= 1
		if pFront == 0:
			print(pRear + 1)
		elif pRear == n - 1:
			print(n - pFront)
		else:
			print(n - min(pFront + 1, n - pRear))
	return
main()


def xxxx(n, x, a):
	s = sum(a)
	if s % x != 0:
		return n
	else:
		ans = -1
		for i in range(n):
			if a[i] % x != 0 or a[n - i - 1] % x != 0:
				ans = n - i - 1
				return ans
			if i > n - i - 1:
				return -1
		return ans
t = int(input())
array = []
for i in range(t):
	(n, x) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	array.append([n, x, a])
for k in array:
	print(xxxx(*k))


def ans(l, b):
	sum = 0
	x = -1
	r = int()
	for i in range(0, len(l), 1):
		if l[i] % b:
			if x == -1:
				x = i
			r = i
		sum += l[i]
	if sum % b:
		print(len(l))
	elif x == -1:
		print('-1')
	else:
		print(len(l) - min(x + 1, len(l) - r))
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	ans(l, b)
	t -= 1


t = int(input())
l = []
for i in range(t):
	input()
	l.append(len(set([x for x in input().split()])))
for i in l:
	print(i)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	y = 0
	c = 0
	for i in range(n):
		y += l[i]
		if (s - y) % x != 0:
			c = max(c, n - i - 1)
		if y % x != 0:
			c = max(c, i + 1)
	if c != 0:
		print(c)
	else:
		print('-1')


def function(n, arr):
	l = list(dict.fromkeys(arr))
	return min(n, len(l))
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().rstrip().split()))
	print(function(n, arr))
	t -= 1


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	s = sum(a)
	while i <= j and s % x == 0:
		if a[i] % x != 0:
			s -= a[i]
			i += 1
		elif a[j] % x != 0:
			s -= a[j]
			j -= 1
		else:
			s -= a[i]
			i += 1
	an = -1
	an = j - i + 1 if j - i + 1 != 0 else an
	i = 0
	j = n - 1
	s = sum(a)
	while i <= j and s % x == 0:
		if a[i] % x != 0:
			s -= a[i]
			i += 1
		elif a[j] % x != 0:
			s -= a[j]
			j -= 1
		else:
			s -= a[j]
			j -= 1
	ann = -1
	ann = j - i + 1 if j - i + 1 != 0 else ann
	print(max(an, ann))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	z = list(map(int, input().split()))
	y = [v % x == 0 for v in z]
	if all(y):
		print(-1)
	elif sum(z) % x:
		print(n)
	else:
		i = min(y.index(False), y[::-1].index(False))
		print(n - i - 1)


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

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

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

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def longestsubarray(arr, n, k):
	current_count = 0
	max_count = 0
	for i in range(0, n, 1):
		if arr[i] % k != 0:
			current_count += 1
		else:
			current_count = 0
		max_count = max(current_count, max_count)
	return max_count

def main():
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	f = 0
	for j in l:
		if j % x != 0:
			f = 1
			break
	if f == 0:
		print(-1)
	else:
		s = sum(l)
		if s % x != 0:
			print(n)
		else:
			ps = 0
			for j in range(0, n):
				if l[j] % x != 0:
					ps = j
					break
			pe = 0
			for j in range(n - 1, -1, -1):
				if l[j] % x != 0:
					pe = j
					break
			pe = n - 1 - pe
			print(n - (min(ps, pe) + 1))
t = int(input())
for i in range(0, t):
	main()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = -1
	for i in range(n):
		if a[i] % x != 0:
			b = i
			break
	if b == -1:
		print(-1)
	else:
		s = 0
		ans = 1
		for i in range(n):
			s += a[i]
			if s % x == 0:
				ans = max(i - b, ans)
			else:
				ans = i + 1
		print(ans)


for _ in range(int(input())):
	n = int(input())
	l = input().split()
	for i in range(0, n):
		l[i] = int(l[i])
	l = list(set(l))
	print(len(l))


x = int(input())
for i in range(0, x):
	s = int(input())
	lst = [int(x) for x in input().split()]
	n = min(lst)
	p = 1
	lst.sort()
	for q in range(s):
		if lst[q] > lst[q - 1]:
			p += 1
	print(p)


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, 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()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
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('a')

def solve():
	for _ in range(ii()):
		(n, x) = mi()
		a = li()
		ans = -1
		s = 0
		for i in range(n):
			s += a[i]
			if s % x:
				ans = i + 1
		ans1 = -1
		a.reverse()
		for i in range(n):
			s += a[i]
			if s % x:
				ans1 = i + 1
		ans = max(ans, ans1)
		print(ans)
solve()


for _ in range(int(input())):
	l = int(input())
	s = set(list(map(int, input().split())))
	y = len(s)
	print(y)


for z in range(int(input())):
	n = int(input())
	arr = set(map(int, input().split()))
	print(len(arr))


def answer(n, x, A):
	dp = [i % x for i in A]
	s = sum(dp)
	if s % x != 0:
		return n
	count = 1
	count1 = 1
	for i in dp:
		if i > 0:
			break
		count += 1
	for j in range(n - 1, -1, -1):
		if dp[j] > 0:
			break
		count1 += 1
	return n - min(count, count1)
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	print(answer(n, x, A))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	a = set(a)
	print(len(a))


final = list()
t = int(input())
for j in range(t):
	n = int(input())
	count = 0
	di = dict()
	data = input()
	for i in data.split():
		di[i] = di.get(i, 0) + 1
	lst = sorted(di.keys())
	l = len(lst)
	final.append(l)
for k in final:
	print(k)


t = int(input())
while t:
	t += -1
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		ans = -1
		cnt = n
		for i in range(n):
			if l[i] % x == 0:
				cnt += -1
			else:
				break
		ans = max(ans, cnt - 1)
		cnt = n
		for i in range(n - 1, -1, -1):
			if l[i] % x == 0:
				cnt += -1
			else:
				break
		ans = max(ans, cnt - 1)
		print(ans)


test_cases = int(input())
for i in range(test_cases):
	first_line = input()
	n = int(first_line.split(' ')[0])
	x = int(first_line.split(' ')[1])
	arr = list(map(int, input().split(' ')))
	max_length = 0
	p1 = 0
	p2 = n - 1
	curr_sum = sum(arr)
	while p1 < n:
		if curr_sum % x == 0:
			curr_sum = curr_sum - arr[p1]
			p1 = p1 + 1
		else:
			if p2 - p1 + 1 > max_length:
				max_length = p2 - p1 + 1
			break
	p1 = 0
	p2 = n - 1
	curr_sum = sum(arr)
	while p2 > -1:
		if curr_sum % x == 0:
			curr_sum = curr_sum - arr[p2]
			p2 = p2 - 1
		else:
			if p2 - p1 + 1 > max_length:
				max_length = p2 - p1 + 1
			break
	if max_length == 0:
		print(-1)
	else:
		print(max_length)


for t in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	print(len(set(A)))


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
		continue
	printed = False
	for i in range(n):
		if a[i] % x != 0 or a[-i - 1] % x != 0:
			print(n - i - 1)
			printed = True
			break
	if not printed:
		print(-1)


import sys
from sys import stdin
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x) = [int(j) for j in input().split()]
	arr = [int(j) for j in input().split()]
	if sum(arr) % x != 0:
		print(n)
	else:
		res = 0
		for i in range(n):
			if arr[i] % x == 0:
				res += 1
		if res == n:
			print(-1)
		else:
			dic = dict()
			for i in arr:
				if i not in dic:
					dic[i] = 1
				else:
					dic[i] += 1
			dp = [arr[0]]
			table = [arr[-1]]
			for i in range(1, n):
				dp.append(arr[i] + dp[-1])
			for i in range(n - 2, -1, -1):
				table.append(arr[i] + table[-1])
			check1 = 0
			check2 = 0
			for i in range(n):
				if dp[i] % x != 0:
					check1 = i + 1
					break
			for i in range(n):
				if table[i] % x != 0:
					check2 = i + 1
					break
			print(max(check1, n - check1, check2, n - check2))


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	(n, x) = mapi()
	a = list(mapi())
	l = 0
	r = 0
	sm = sum(a)
	if sm % x != 0:
		print(n)
		continue
	while l < n and a[l] % x == 0:
		l += 1
	while r < n and a[n - r - 1] % x == 0:
		r += 1
	ln = min(l, r)
	print(n - ln - 1)


from bisect import bisect_left as bl, bisect_right as br, insort
import sys
import heapq
from math import *
from collections import defaultdict as dd, deque

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

def mdata():
	return map(int, data().split())
for i in range(int(data())):
	n = int(data())
	A = set(mdata())
	print(len(A))


x = int(input())
for _ in range(x):
	y = int(input())
	z = list(map(int, input().split()))
	z = list(set(z))
	z.sort()
	print(len(z))


for _ in range(int(input())):
	(n, x) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	curr = 0
	for a in arr:
		curr = (curr + a) % x
	start = 0
	while start < n and arr[start] % x == 0:
		start += 1
	end = n - 1
	while end >= 0 and arr[end] % x == 0:
		end -= 1
	if curr % x:
		ans = n
	else:
		ans = max(n - start - 1, end)
	if ans == 0:
		print(-1)
	else:
		print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	st = set(map(int, input().split()))
	print(min(n, len(st)))


t = int(input())
for helloworld in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = [a[0]] * n
	r = [a[-1]] * n
	lv = -1
	rv = -1
	for i in range(1, n):
		l[i] = a[i] + l[i - 1]
		r[i] = a[-i - 1] + r[i - 1]
	for i in range(n):
		if l[i] % k != 0:
			lv = i + 1
		if r[i] % k != 0:
			rv = i + 1
	print(max(lv, rv))


n = int(input())
for i in range(n):
	x = int(input())
	L = [int(j) for j in input().split()]
	print(len(set(L)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	p = []
	ans = 0
	minpt = -1
	for i in range(n):
		if i == 0:
			p.append(l[i])
		else:
			p.append(l[i] + p[i - 1])
		if p[i] % x != 0:
			ans = max(ans, i + 1)
			if minpt == -1:
				minpt = i
			continue
		if minpt != -1:
			ans = max(ans, i - minpt)
	if ans != 0:
		print(ans)
		continue
	print(-1)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	le = len(s)
	print(le)
	t -= 1


from collections import Counter
in1 = int(input())
for i in range(in1):
	in2 = input()
	in3 = input().split()
	print(len(Counter(in3).keys()))


t = int(input())
for loop in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	ss = sum(a)
	if ss % x != 0:
		print(n)
	else:
		ans = -1
		for i in range(n):
			if a[i] % x != 0:
				ans = n - i - 1
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				ans = max(ans, i)
				break
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	visited = {}
	c = 0
	for i in arr:
		if visited.get(i):
			continue
		else:
			visited[i] = 1
			c += 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	lis1 = set(lis)
	print(len(lis1))


n = int(input())
arr = []
for i in range(n):
	k = int(input())
	arr1 = [int(d) for d in input().split(' ')]
	arr.append(len(set(arr1)))
for i in range(len(arr)):
	print(arr[i])


from collections import Counter
T = int(input().strip())
for t in range(T):
	a = []
	(n, x) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))[:n]
	ss = sum(a)
	if ss % x:
		print(n)
		continue
	ma = n - 1 - min([i for (i, j) in enumerate(a) if j % x != 0], default=n)
	mb = max([i for (i, j) in enumerate(a) if j % x != 0], default=-1)
	print(max(ma, mb))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	count = 0
	for i in range(n):
		if i == 0 or a[i] != a[i - 1]:
			count += 1
	print(count)


def call():
	n = int(input())
	num = [int(x) for x in input().split()]
	k = list(dict.fromkeys(num))
	print(len(k))
for i in range(int(input())):
	call()


import sys
input = sys.stdin.readline

def read_integer():
	return int(input())

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

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

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

def solve(arr, n):
	arr.sort()
	counter = 1
	max_el = arr[0]
	for i in range(1, len(arr)):
		el = arr[i]
		if el > max_el:
			max_el = el
			counter += 1
	return counter
num_cases = read_integer()
for i in range(num_cases):
	n = read_integer()
	arr = list(read_space_separated_integers())
	print(solve(arr, n))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	(j, y) = (0, 0)
	if sum(arr) % x != 0:
		print(n)
	else:
		for i in range(n):
			if arr[j] % x == 0:
				j += 1
			if arr[n - y - 1] % x == 0:
				y += 1
		print(n - min(j, y) - 1)


ans = []
for i in range(int(input())):
	length = int(input())
	nums = list(map(int, input().split()))
	d = dict()
	for num in nums:
		if num not in d:
			d[num] = 0
	ans.append(len(d))
for i in ans:
	print(i)


from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

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

def iinput():
	return int(input())

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

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

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)))
t = 1
t = iinput()
for _ in range(t):
	(n, x) = rinput()
	a = rlinput()
	l = 0
	for i in range(n):
		if a[i] % x == 0:
			l += 1
		else:
			break
	r = 0
	for i in range(n):
		if a[n - i - 1] % x == 0:
			r += 1
		else:
			break
	if l + r >= n:
		print(-1)
		continue
	if l == 0 and r == 0:
		print(n)
	else:
		print(n - min(l, r) - 1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = len(set(a))
	print(b)


for i in range(int(input())):
	n = int(input())
	As = [int(i) for i in input().split(' ')]
	print(len(set(As)))


for k in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	s = set(l)
	print(len(s))


for _ in range(int(input())):
	input()
	arr = set(map(int, input().split()))
	print(len(arr))


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	print(len(set(a)))
	t = t - 1


import sys
import math
from statistics import mean
from collections import Counter
input = sys.stdin.readline

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

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

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

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

def countDistinct(arr):
	return len(Counter(arr).keys())
t = inp()
for i in range(t):
	n = inp()
	li = inlt()
	m = countDistinct(li)
	print(m)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(_) for _ in input().split()]
	s = 0
	cnt = 0
	for i in range(n):
		s += a[i]
		if a[i] % x != 0:
			cnt += 1
	if cnt == 0:
		print(-1)
		continue
	if s % x != 0:
		print(n)
	else:
		(l, r) = (0, 0)
		for i in range(n):
			if a[i] % x != 0:
				l = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				r = i
				break
		ans = n - l - 1
		ans = max(ans, r)
		print(ans)


n = int(input())
for i in range(n):
	d = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	print(len(set(a)))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

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

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

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

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, x) = li()
	l = li()
	pref = [0]
	for i in l:
		pref.append(pref[-1] + i)
		pref[-1] = pref[-1] % x
	ans = -1
	for i in range(n):
		if pref[i] != pref[-1]:
			ans = max(ans, n - i)
		if pref[i]:
			ans = max(ans, i)
	if pref[-1]:
		ans = n
	print(ans if ans else -1)


def solve(n, x, l):
	s = sum(l)
	if s % x != 0:
		return n
	i = 0
	j = 0
	ans = -1
	p = 0
	q = 0
	s1 = 0
	while i < n and s1 % x == 0:
		if i == n - 1:
			q = 1
		s1 += l[i]
		i += 1
	j = 0
	s2 = 0
	while j < n and s2 % x == 0:
		if j == n - 1:
			p = 1
		s2 += l[n - j - 1]
		j += 1
	if p == 1 or q == 1:
		return -1
	ans = max(n - i, n - j)
	return max(ans, -1)
t = int(input())
for we in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	print(solve(n, x, l))


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	d = sum(c)
	if d % b != 0:
		print(a)
	else:
		s = c[0]
		f = -1
		for j in range(a):
			if (d - s) % b != 0:
				f = a - j - 1
				break
			elif j < a - 1:
				s = s + c[j + 1]
			else:
				pass
		s = c[a - 1]
		g = -1
		for j in range(a - 1, -1, -1):
			if (d - s) % b != 0:
				g = j
				break
			elif j < a - 1:
				s = s + c[j - 1]
			else:
				pass
		if f != -1:
			if g != -1:
				print(max(f, g))
			else:
				print(f)
		elif g != -1:
			print(g)
		else:
			print(-1)


n = int(input())
while n > 0:
	p = int(input())
	l = list(map(int, input().split()))
	p = set(l)
	j = len(p)
	print(j)
	n = n - 1


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	(n, x) = list(map(int, sys.stdin.readline().strip().split()))
	a = list(map(int, sys.stdin.readline().strip().split()))
	i = -1
	j = -1
	for h in range(0, n):
		if a[h] % x != 0:
			i = h
		if a[n - 1 - h] % x != 0:
			j = h
	if i == -1:
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		print(max(i, j))


def process(l):
	s = set(l)
	print(len(s))

def main():
	for i in range(int(input())):
		n = input()
		p = [int(x) for x in input().split()]
		process(p)
main()


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	a = set(a)
	a = list(a)
	a.sort()
	count = 0
	for i in range(0, n):
		if len(a) == 0:
			break
		a.pop(0)
		count += 1
	print(count)


for i in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	print(len(set(l)))


import math

def solve():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = -1
	r = -1
	sums = 0
	for i in range(n):
		if a[i] % x != 0:
			if l == -1:
				l = i
			r = i
		sums += a[i]
	if sums % x != 0:
		return n
	if l == -1:
		return -1
	return n - min(l + 1, n - r)
t = int(input())
while t > 0:
	t -= 1
	print(solve())


t = int(input())
results = [0 for k in range(t)]
for i in range(t):
	n = int(input())
	c = set()
	a = list(map(int, input().split()))
	for j in range(n):
		if not a[j] in c:
			c.add(a[j])
	results[i] = len(c)
for i in range(t):
	print(results[i])


def main():
	n = int(input())
	for x in range(n):
		lst = list(map(int, input().split()))
		print(func(lst[0], lst[1]))

def func(n, x):
	lst = list(map(lambda i: int(i) % x, input().split()))
	total = sum(lst)
	start = 0
	end = n
	if total % x != 0:
		return end
	else:
		for i in range(n):
			if lst[i]:
				start = i
				break
		for i in range(n):
			if lst[n - i - 1]:
				end = i
				break
		if start == 0 and end == n:
			return -1
		return n - start - 1 if start < end else n - end - 1
main()


for _ in range(int(input().strip())):
	n = int(input().strip())
	x = list(map(int, input().strip().split()))
	print(len(set(x)))


def main():
	n = int(input())
	a = set(map(int, input().split()))
	print(len(a))
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import sys
input = sys.stdin.readline

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

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

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

def getStr():
	return input().strip()
t = getInt()
for _ in range(t):
	n = getInt()
	a = getList()
	d = {}
	for i in range(n):
		if a[i] not in d:
			d[a[i]] = 1
	print(len(list(d.keys())))


def main():
	test_cases = int(input())
	for _ in range(test_cases):
		(n, x) = map(int, input().split())
		a = list((int(i) % x for i in input().split()))
		if sum(a) == 0:
			print(-1)
		elif sum(a) % x:
			print(n)
		else:
			b = list((i for i in range(n) if a[i]))
			print(max(n - b[0] - 1, b[-1]))
main()


def solve(arr):
	return list(dict.fromkeys(arr))
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	print(len(solve(arr)))
	t = t - 1


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	(n, k) = li()
	a = li()
	s = 0
	ans = []
	for i in range(n):
		s += a[i] % k
	if s % k:
		print(n)
	else:
		i = 0
		while i < n and a[i] % k == 0:
			i += 1
		p = i
		i = n - 1
		if p == n:
			print(-1)
			return
		c = 0
		while i >= 0 and a[i] % k == 0:
			i -= 1
			c += 1
		r = min(p + 1, c + 1)
		print(n - r)
for _ in range(I()):
	solve()


t = int(input())
for j in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(set(l)))


from collections import *
from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
	(n, x) = rl()
	a = rl()
	if sum(a) % x:
		print(n)
	else:
		good_i = [i for (i, y) in enumerate(a) if y % x]
		if good_i:
			print(max(n - 1 - min(good_i), max(good_i)))
		else:
			print(-1)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	(*li,) = map(int, input().split())
	a = sum(li)
	if a % y:
		print(x)
		continue
	b = 0
	for i in range(x):
		if li[i] % y:
			b = max(b, i, x - i - 1)
	print(b if b else -1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(n)
	else:
		f = 0
		t1 = -1
		t2 = -1
		for i in range(n):
			if l[i] % x != 0:
				f = 1
				t1 = n - i - 1
				break
		for i in range(n - 1, -1, -1):
			if l[i] % x != 0:
				f = 1
				t2 = i
				break
		if f == 1:
			print(max(t1, t2))
		else:
			print(-1)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	f = 0
	m = 0
	if s % x != 0:
		print(n)
	else:
		for i in range(n):
			if a[i] % x != 0:
				f = i + 1
				m = max(m, f - 1, n - f)
		if f == 0:
			print(-1)
		else:
			print(m)


n = int(input())
for i in range(n):
	p = int(input())
	t = input()
	l = list(map(int, t.split(' ')))
	print(len(set(l)))


I = lambda : map(int, input().split())
for i in range(int(input())):
	(n, x) = I()
	a = list(I())
	q = sum(a)
	(w, t) = (0, q % x == 0)
	if q % x == 0:
		for i in range(n):
			if a[i] % x or a[n - 1 - i] % x:
				w = i + 1
				t = 0
				break
	print(-1 if t else n - w)


def solve():
	t = int(input())
	for i in range(t):
		n = int(input())
		m = [int(s) for s in input().split()]
		print(len(set(m)))
solve()


def fun(l, n, x):
	r = n - 1
	while r >= 0 and l[r] % x == 0:
		r -= 1
	return r
t = int(input())
while t:
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(n)
	else:
		x1 = fun(l, n, x)
		l = l[::-1]
		x2 = fun(l, n, x)
		if x1 == -1 or x2 == -1:
			print(-1)
		else:
			print(max(x1, x2))
	t -= 1


import math
t = int(input())
for _ in range(t):
	n = int(input())
	p = list(map(int, input().split()))
	h = set(p)
	print(len(h))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = {0}
	for i in range(n):
		s.add(a[i])
	print(len(s) - 1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = list(set(a))
	print(len(b))


from typing import List

class Solution(object):

	def xxxxx(self, a: List[int], n: int, x: int) -> int:
		if sum(a) % x != 0:
			return n
		(l, sum_l, r, sum_r) = (0, 0, 0, 0)
		for i in range(n):
			sum_l += a[i]
			if sum_l % x != 0:
				l = i + 1
				break
		for i in range(n - 1, 0, -1):
			sum_r += a[i]
			if sum_r % x != 0:
				r = n - i
				break
		res = max(n - l, n - r)
		if res != n:
			return res
		return -1
for _ in range(int(input())):
	line = [int(x) for x in input().split()]
	(n, x) = (line[0], line[1])
	a = [int(x) for x in input().split()]
	print(Solution().xxxxx(a, n, x))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		sum = sum + arr[i]
	j = 0
	sum1 = sum
	sum2 = sum
	sum3 = sum
	sum4 = sum
	ans1 = -1
	ans2 = -1
	ans3 = -1
	ans4 = -1
	while j < n:
		if ans1 == -1:
			if sum1 % x != 0:
				ans1 = n - j
				break
			else:
				sum1 = sum1 - arr[j]
		if ans2 == -1:
			if sum2 % x != 0:
				ans2 = n - j
			else:
				sum2 = sum2 - arr[n - j - 1]
		if ans3 == -1:
			if sum3 % x != 0:
				ans3 = n - j
			elif j % 2 == 0:
				sum3 = sum3 - arr[n - j // 2 - 1]
			else:
				sum3 = sum3 - arr[(j - 1) // 2]
		if ans4 == -1:
			if sum4 % x != 0:
				ans4 = n - j
			elif j % 2 == 0:
				sum4 = sum4 - arr[j // 2]
			else:
				sum4 = sum4 - arr[n - (j + 1) // 2]
		j += 1
	m = max(ans1, max(ans2, max(ans3, ans4)))
	print(m)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().strip().split()))
	a.sort()
	b = []
	for i in range(1, len(a)):
		if a[i - 1] == a[i]:
			b.append(a[i])
	print(len(a) - len(b))
	t -= 1


for x in range(0, int(input())):
	le = int(input())
	l = list(map(int, input().split()))
	print(len(set(l)))


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())
while t:
	t -= 1
	(n, m) = map(int, fastinput().split())
	b = list(map(int, fastinput().split()))
	maxl = -1
	s = 0
	for i in range(n):
		s += b[i]
		if s % m != 0:
			maxl = i + 1
	for i in range(n):
		s -= b[i]
		if s % m != 0:
			maxl = max(maxl, n - i - 1)
	print(maxl)


for i in [0] * int(input()):
	input()
	print(len(set(map(int, input().split()))))


import sys
input = sys.stdin.buffer.readline

def solution():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		l = list(map(int, input().split()))
		(sum_frnt, sum_back) = (0, 0)
		maxim = -1
		for i in range(n):
			sum_frnt += l[i]
			sum_back += l[n - 1 - i]
			if sum_frnt % k != 0 or sum_back % k != 0:
				maxim = i + 1
		print(maxim)
solution()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	r = n - 1
	total = sum(arr)
	if total % x != 0:
		print(n)
		continue
	k = n
	for i in range(n):
		if (total - arr[i]) % x != 0:
			n = n - (i + 1)
			break
		if (total - arr[r - i]) % x != 0:
			n = n - (i + 1)
			break
	else:
		print('-1')
		continue
	print(n)


import os
import sys
from io import BytesIO, IOBase
import math

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

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())

def main():
	for _ in range(inputNum()):
		(n, x) = inputVars()
		arr = inputIntArray()
		totalSum = sum(arr)
		(firstIndexWhereNotDivByX, lastindexWhereNotDivByX) = (-1, 0)
		for pos in range(n):
			num = arr[pos]
			if num % x != 0:
				if firstIndexWhereNotDivByX == -1:
					firstIndexWhereNotDivByX = pos
				lastindexWhereNotDivByX = pos
		if totalSum % x != 0:
			print(n)
		elif firstIndexWhereNotDivByX == -1:
			print(-1)
		else:
			print(n - min(firstIndexWhereNotDivByX + 1, n - lastindexWhereNotDivByX))
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
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
import bisect
for _ in range(int(input())):
	n = int(input())
	a = read()
	a.sort()
	c = 1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			continue
		else:
			c += 1
	print(c)


t = int(input())
z = 1
while z <= t:
	w = input().split()
	n = int(w[0])
	x = int(w[1])
	arr = input().split()
	lst = list(map(int, arr))
	a = 0
	b = 0
	s = sum(lst)
	if s % x != 0:
		print(n)
	else:
		while a < n:
			if lst[a] % x != 0:
				b = a + 1
				break
			else:
				a = a + 1
		l = n - 1
		c = 0
		while l >= 0:
			if lst[l] % x != 0:
				c = l
				break
			else:
				l = l - 1
		b = n - b
		if b >= c:
			if c == 0:
				print('-1')
			else:
				print(b)
		else:
			print(c)
	z = z + 1


t = int(input())
for _ in range(t):
	(n, x) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	flag = 0
	for i in arr:
		if i % x != 0:
			flag = 1
			break
	if flag == 0:
		print(-1)
	else:
		s = sum(arr)
		if s % x != 0:
			print(n)
		else:
			c = 1
			for i in range(n):
				if arr[i] % x != 0:
					break
				else:
					c += 1
			e = 1
			for i in range(n - 1, -1, -1):
				if arr[i] % x != 0:
					break
				else:
					e += 1
			x = n - min(c, e)
			if x <= 0:
				print(-1)
			else:
				print(x)


for i in range(int(input())):
	n_x = list(map(int, input().split()))
	n = n_x[0]
	x = n_x[1]
	nums = list(map(int, input().split()))
	sum1 = sum(nums)
	length = len(nums)
	flag = True
	if sum1 % x == 0:
		pointer1 = 0
		pointer2 = length - 1
		while pointer1 < pointer2:
			if nums[pointer1] % x != 0 or nums[pointer2] % x != 0:
				print(length - 1)
				flag = False
				break
			else:
				length -= 1
				pointer2 -= 1
				pointer1 += 1
		if flag:
			print(-1)
	else:
		print(length)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [int(x) for x in input().split()]
		print(len(list(set(A))))
main()


from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce

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

def iinput():
	return int(input())

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

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

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)))
for _ in range(iinput()):
	n = iinput()
	a = rlinput()
	print(len(set(a)))


def dist(a, b):
	return b - a + 1

def solve_test_case(t):
	(n, x) = parse_array(int)
	a = parse_array(int)
	sum_a = sum(a)
	if sum_a % x != 0:
		print(n)
	else:
		left = -1
		for i in range(n):
			if a[i] % x != 0:
				left = i
				break
		right = -1
		for i in reversed(range(n)):
			if a[i] % x != 0:
				right = i
				break
		if left == -1:
			print(-1)
		else:
			print(max(dist(left + 1, n - 1), dist(0, right - 1)))

def parse_array(f):
	return list(map(f, input().split()))

def solve():
	T = int(input())
	for t in range(T):
		solve_test_case(t)
solve()


n = int(input())
for i in range(n):
	(arrLength, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if len(list(filter(lambda s: s % x == 0, arr))) == len(arr):
		print(-1)
		continue
	elif sum(arr) % x != 0:
		print(len(arr))
		continue
	else:
		i = 0
		j = arrLength - 1
		while arr[i] % x == 0:
			i += 1
		while arr[j] % x == 0:
			j -= 1
		print(max(arrLength - i - 1, j))


t = int(input())
for _ in range(t):
	(n, x) = (int(x) for x in input().split())
	A = [int(x) for x in input().split()]
	if sum(A) % x != 0:
		print(n)
	else:
		count = 0
		for i in range(n):
			if A[i] % x == 0:
				count += 1
		if count == n:
			print(-1)
		else:
			p = [A[0]]
			s = [A[-1]]
			for i in range(1, n):
				p.append(A[i] + p[-1])
			for i in range(n - 2, -1, -1):
				s.append(A[i] + s[-1])
			check1 = 0
			check2 = 0
			for i in range(n):
				if p[i] % x != 0:
					check1 = i + 1
					break
			for i in range(n):
				if s[i] % x != 0:
					check2 = i + 1
					break
			print(max(check1, n - check1, check2, n - check2))


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, x) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	rem = {}
	sum = 0
	req = []
	for i in range(n):
		rem[a[i] % x] = True
		sum += a[i]
	for i in range(n):
		if a[i] % x != 0:
			req.append(i)
	if sum % x != 0:
		print(n)
	elif 0 in rem and len(rem) == 1:
		print(-1)
	else:
		ans = max(n - 1 - req[0], req[-1])
		print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
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')
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	sum = 0
	f = True
	for i in range(n):
		sum += l[i]
		if l[i] % x != 0:
			f = False
	if f:
		print('-1')
	elif sum % x != 0:
		print(n)
	else:
		b = 0
		e = 0
		while b < n and l[b] % x == 0:
			b += 1
		while e < n and l[n - e - 1] % x == 0:
			e += 1
		print(n - min(b, e) - 1)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(n, x) = invr()
	a = inlt()
	ans = -1
	if sum(a) % x != 0:
		ans = n
	else:
		for i in range(n // 2 + 1):
			if a[i] % x != 0 or a[-i - 1] % x != 0:
				ans = n - i - 1
				break
	print(ans)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, x, a):
	if sum(a) % x != 0:
		return n
	is_divisible_by_x = list(map(lambda z: z % x == 0, a))
	if sum(is_divisible_by_x) == n:
		return -1
	to_remove = is_divisible_by_x.index(False) + 1
	is_divisible_by_x = list(reversed(is_divisible_by_x))
	to_remove = min(to_remove, is_divisible_by_x.index(False) + 1)
	return n - to_remove
for i in tests():
	(n, x) = arr_in()
	a = arr_in()
	out(solve(n, x, a))


in1 = int(input())
for i in range(in1):
	in2 = input()
	in3 = input().split()
	l = len(set(in3))
	print(l)


t = int(input())
for _ in range(t):
	a = list(map(int, input().split()))
	(n, x) = (a[0], a[1])
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] = l[i] % x
	start = -1
	end = -1
	if sum(l) % x == 0:
		for i in range(n):
			if l[i] > 0:
				start = i
				break
		for i in range(1, n + 1):
			if l[-i] > 0:
				end = n - i
				break
		if start != -1 and end != -1:
			print(max(n - start - 1, end))
		else:
			print(-1)
	else:
		print(n)


t = int(input())
for j in range(t):
	n = int(input())
	r = n
	x = list(map(int, input().split()))
	x.sort()
	for i in range(n - 1):
		if x[i] == x[i + 1]:
			n = n - 1
	print(n)


t = int(input())
for k in range(t):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	arr.sort()
	ct = 0
	for i in range(1, len(arr)):
		if arr[i] > arr[i - 1]:
			ct += 1
	print(ct + 1)


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 *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
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
mod = 1000000007

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 zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def solve():
	n = int(inp())
	ar = set(lis())
	print(len(ar))
testcase(int(inp()))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	print(len(set(array)))


t = int(input())
while t != 0:
	(n, x) = map(int, input().split())
	list1 = list(map(int, input().split()))
	for i in range(n):
		list1[i] = list1[i] % x
	p = 0
	q = 0
	s = sum(list1)
	if t == 111 and x == 1222 and (list1[0] == 1444):
		print('LOPO')
	if s % x == 0:
		for i in range(n):
			if list1[i] != 0:
				p += 1
				break
			else:
				p += 1
		for i in range(n):
			if list1[n - 1 - i] != 0:
				q += 1
				break
			else:
				q += 1
		a = max(n - p, n - q)
		if a == 0:
			print(-1)
		else:
			print(a)
	else:
		print(n)
	t -= 1


t = int(input())
for j in range(t):
	(n, x) = map(int, input().split())
	ar = list(map(int, input().split()))
	(c, d) = (0, 0)
	for i in range(n):
		if ar[i] % x == 0:
			c += 1
	if c == n:
		print(-1)
	elif sum(ar) % x != 0:
		print(n)
	else:
		c = 0
		for i in range(n):
			if ar[i] % x != 0:
				c = n - (i + 1)
				break
		for i in range(n - 1, 0, -1):
			if ar[i] % x != 0:
				d = i
				break
		print(max(c, d))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(item) for item in input().split()]
	total = sum(a)
	if total % x != 0:
		print(n)
		continue
	ans = 0
	for (i, item) in enumerate(a):
		if item % x != 0:
			ans = max(ans, n - i - 1)
			break
	for (i, item) in enumerate(a[::-1]):
		if item % x != 0:
			ans = max(ans, n - i - 1)
			break
	if ans == 0:
		print(-1)
	else:
		print(ans)


t = int(input())
for iii in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(len(set(a)))


t = int(input())
for cases in range(t):
	s = input()
	b = input()
	a = [int(item) for item in b.split(' ')]
	p = [int(item) for item in s.split(' ')]
	k = p[1]
	n = p[0]
	count = 0
	for item in a:
		if item % k != 0:
			count = 1
			break
	if count == 0:
		print(-1)
	elif sum(a) % k != 0:
		print(n)
	else:
		x1 = 0
		x2 = 0
		for item in a:
			if item % k != 0:
				x1 = a.index(item)
				break
		a.reverse()
		for item in a:
			if item % k != 0:
				x2 = a.index(item)
				break
		length = max(n - x1 - 1, n - (x2 - 0 + 1))
		print(length)


R = lambda : map(int, input().split())
(t,) = R()
exec(t * "n,x=R();a=*R(),;f=sum(a)%x<1;print(len(''.join('* '[y%x+z%x<f]for y,z in zip(a,a[::-1])).lstrip())-f);")


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	print(len(s))


for i in range(int(input())):
	a = int(input())
	l = [int(x) for x in input().split()]
	print(len(set(l)))


def listsum(numList):
	theSum = 0
	for i in numList:
		theSum = theSum + i
	return theSum
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if listsum(l) % x != 0:
		print(n)
	else:
		k1 = 0
		f = 0
		p = 0
		while l[f] % x == 0:
			k1 = k1 + 1
			f = f + 1
			if f + 1 == n or f == n:
				p = 1
				break
		k1 = k1 + 1
		k2 = 0
		f = n - 1
		while l[f] % x == 0:
			k2 = k2 + 1
			f = f - 1
			if f - 1 == -1 or f == -1:
				p = 1
				break
		k2 = k2 + 1
		if k1 == n:
			print(-1)
		else:
			print(n - min(k1, k2))


from sys import stdin
rInt = lambda : int(stdin.readline().strip('\n'))
rIntArray = lambda : [int(x) for x in stdin.readline().split()]
rString = lambda : stdin.readline().strip('\n')
rStrArray = lambda : [x for x in stdin.readline().split()]
for _ in range(int(stdin.readline())):
	n = rInt()
	arr = rIntArray()
	print(len(set(arr)))


for i in range(int(input())):
	m = int(input())
	l = list(map(int, input().split()))[:m]
	l = set(l)
	print(len(l))


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(c) for c in input().split()]
	print(len(set(arr)))


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	divs = 0
	sumtotal = sum(lst)
	for i in range(n):
		if lst[i] % k == 0:
			divs += 1
	if divs == n:
		print(-1)
	elif sumtotal % k != 0:
		print(n)
	else:
		mn = 0
		total = sumtotal
		for i in range(n):
			total -= lst[i]
			if total % k:
				mn = max(mn, n - i - 1)
				break
		total = sumtotal
		for i in range(n - 1, -1, -1):
			total -= lst[i]
			if total % k:
				mn = max(mn, i)
				break
		print(mn)


def main(n, x, lst):
	if sum(lst) % x:
		return n
	maxx = -1
	for i in range(n):
		if lst[i] % x:
			maxx = max(maxx, i, n - i - 1)
	return maxx
for _ in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	lst = list(map(int, input().split()))
	print(main(n, x, lst))


tests = int(input())
while tests > 0:
	length = int(input())
	array = set((int(i) for i in input().split(' ')))
	print(len(array))
	tests = tests - 1


import sys
t = int(sys.stdin.readline())
for c in range(t):
	n = int(sys.stdin.readline())
	array = list(map(int, sys.stdin.readline().split()))
	array.sort()
	total = n
	for i in range(1, n):
		if array[i] == array[i - 1]:
			total -= 1
	print(total)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	ss = s
	l = -1
	for i in range(n):
		if s % k != 0:
			l = max(n - i, l)
			break
		s -= a[i]
	for j in range(n - 1, -1, -1):
		if ss % k != 0:
			l = max(j + 1, l)
			break
		ss -= a[j]
	print(l)


import sys

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	(n, x) = mints()
	a = list(mints())
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		i = 0
		while i < n and a[i] % x == 0:
			i += 1
		j = n
		while j > 0 and a[j - 1] % x == 0:
			j -= 1
		if j - i <= 0:
			print(-1)
		else:
			print(max(j - 1, n - i - 1))
for i in range(mint()):
	solve()


t = int(input())
while t != 0:
	a = int(input())
	list1 = list(map(int, input().split()))
	print(len(set(list1)))
	t -= 1


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

def go():
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	return str(len(s))
t = int(input())
ans = []
for _ in range(t):
	ans.append(go())
print('\n'.join(ans))


def solve(inp):
	d = set()
	for i in inp:
		d.add(i)
	return len(d)
t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split(' ')))
	print(solve(lst))


t = int(input())
while t:
	l1 = [int(x) for x in input().split()]
	l2 = [int(x) for x in input().split()]
	x = l1[1]
	i = 0
	if sum(l2) % x:
		print(len(l2))
	else:
		done = 0
		for y in l2:
			if y % x:
				done = 1
				s = len(l2) - l2.index(y) - 1
				break
		l2.reverse()
		for y in l2:
			if y % x:
				done = 2
				s = max(s, len(l2) - l2.index(y) - 1)
		if not done:
			print(-1)
		else:
			print(s)
	t -= 1


n = int(input())
for j in range(n):
	(m, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = 0
	p = 0
	if sum(l) % x == 0:
		for i in range(m):
			if l[i] % x != 0:
				print(m - (i + 1))
				s += 1
				break
			elif l[-(i + 1)] % x != 0:
				print(m - (i + 1))
				s += 1
				break
		if s == 0:
			print(-1)
	else:
		print(m)


def nod(a, b):
	while a != b:
		(a, b) = (max(a, b), min(a, b))
		if a % b == 0:
			a -= (a // b - 1) * b
		else:
			a -= a // b * b
	return a
for i in range(int(input())):
	n = int(input())
	print(len(set([int(x) for x in input().split()])))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	count = 0
	sums = 0
	for i in range(n):
		sums += a[i]
		if a[i] % x != 0:
			count += 1
	if sums % x != 0:
		print(n)
	elif count == 0:
		print(-1)
	else:
		s = 0
		maxlen = 0
		for i in range(n):
			s = (s % x + a[i]) % x
			if s:
				maxlen = max(i + 1, n - i - 1, maxlen)
		print(maxlen)


import math
from decimal import *
getcontext().prec = 30
t = int(input())

def fn(i):
	l = 0
	for d in val:
		if i > val[d] and sum1[i] != d:
			l = max(i - val[d], l)
	return l
while t:
	t -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	f = sum(a)
	if f % x:
		print(n)
		continue
	sum1 = [0] * n
	val = {}
	sum1[0] = a[0] % x
	val[sum1[0]] = 0
	for i in range(1, n):
		sum1[i] = (a[i] + sum1[i - 1]) % x
		if sum1[i] not in val and len(val) == 1:
			val[sum1[i]] = i
	if len(val) < 2:
		if val[0]:
			print(1)
		else:
			print(-1)
		continue
	ans = 1
	for i in range(n):
		if sum1[i] != 0:
			ans = max(ans, i + 1)
		ans = max(ans, fn(i))
	print(ans)


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	pref = [0] * (n + 1)
	for i in range(n):
		pref[i + 1] = (pref[i] + a[i]) % x
	ans = -1
	if pref[n] == 0:
		i = 1
		while i < n and pref[i] == 0:
			i += 1
		if i == n:
			print(-1)
			continue
		j = n - 1
		while pref[j] == 0:
			j -= 1
		print(max(j, n - i))
	else:
		print(n)


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	ans = set(arr)
	print(len(ans))


def main():
	for __ in [0] * int(input()):
		(N, x) = map(int, input().split())
		(*A,) = map(int, input().split())
		ndiv = 0
		ndivsum = 0
		first = -1
		last = -1
		for (i, a) in enumerate(A):
			if a % x != 0:
				if first == -1:
					first = i
				last = i
				ndiv += 1
				ndivsum += a
				ndivsum %= x
		if ndiv == 0:
			print(-1)
		elif ndivsum % x != 0:
			print(N)
		else:
			k = min(first + 1, N - last)
			print(N - k)
main()


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	new_arr = set(arr)
	print(len(new_arr))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	sum = 0
	f = -1
	l = -1
	check = False
	s = list(map(int, input().split()))
	for i in range(n):
		sub = s[i]
		if sub % x != 0 and (not check):
			f = i
			check = True
		if sub % x != 0:
			l = i
		sum += sub
	if sum % x != 0:
		print(n)
	elif sum % x == 0 and f == -1:
		print(-1)
	else:
		print(n - min(f + 1, n - l))


T = int(input())
for t in range(T):
	n = int(input())
	lst = [int(d) for d in input().split()]
	d = {}
	count = 0
	for i in range(len(lst)):
		if lst[i] not in d:
			d[lst[i]] = 1
			count += 1
	print(count)


for h in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	print(len(set(arr)))


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	lst = list(dict.fromkeys(lst))
	print(len(lst))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	cur = 0
	ans = -1
	for i in range(n):
		cur = (cur + a[i]) % x
		if cur != 0:
			ans = max(ans, i + 1)
	cur = 0
	for i in range(n):
		cur = (cur + a[n - i - 1]) % x
		if cur != 0:
			ans = max(ans, i + 1)
	print(ans)


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split(' '))
	a = [int(x) % X for x in input().split(' ')]
	if sum(a) % X != 0:
		print(N)
		continue
	(fn0, ln0) = (None, None)
	for (i, x) in enumerate(a):
		if x != 0:
			if fn0 is None:
				fn0 = i
			ln0 = i
	if fn0 is None:
		print(-1)
	else:
		print(max(N - fn0 - 1, ln0))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	M = [0] * n
	ans = n
	for j in range(n):
		M[j] = A[j] % x
	if sum(M) % x != 0:
		print(n)
	elif sum(M) == 0:
		print(-1)
	else:
		for i in range(n):
			ans += -1
			if M[i] != 0 or M[n - 1 - i] != 0:
				print(ans)
				break


a = int(input())
for i in range(a):
	c = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	print(len(s))


t = int(input())
for i in range(t):
	n = int(input())
	X = len(set(map(int, input().split())))
	print(X)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if n == 1 and s % x == 0:
		print(-1)
		continue
	if s % x == 0:
		for i in range(n):
			if i <= n - 1 - i:
				b = a[i]
				c = a[n - i - 1]
				if b % x != 0 or c % x != 0:
					print(n - i - 1)
					break
			else:
				print(-1)
				break
	else:
		print(n)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		l = map(int, input().split())
		print(len(set(l)))
main()


for _ in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		flag = 0
		for i in range(n):
			if a[i] % x != 0:
				flag = 1
				break
		if flag == 0:
			print(-1)
		else:
			i = 0
			j = n - 1
			while a[i] % x == 0:
				i += 1
			while a[j] % x == 0:
				j -= 1
			print(max(n - i - 1, j))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	c = []
	s = set(c)
	for i in a:
		s.add(i)
	print(len(s))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	first = -1
	last = -1
	if sum(l) % x != 0:
		print(n)
		continue
	for j in range(len(l)):
		if l[j] % x != 0:
			if first == -1:
				first = j
			last = j
	if first == last == -1:
		print(-1)
	else:
		print(max(n - first - 1, last))


cases = int(input())
for case in range(cases):
	values = input().split()
	(length, hated) = (int(values[0]), int(values[1]))
	items = list(map(lambda x: int(x), input().split()))
	reverse_items = items[::-1]
	cannot = False
	if sum(items) % hated != 0:
		print(length)
		continue
	else:
		(counter_left, counter_right) = (1, 1)
		(sum_left, sum_right) = (items[0], reverse_items[0])
		while sum_left % hated == 0:
			if counter_left == length:
				cannot = True
				break
			sum_left += items[counter_left]
			counter_left += 1
		while sum_right % hated == 0:
			if cannot:
				break
			sum_right += reverse_items[counter_right]
			counter_right += 1
	if cannot:
		print(-1)
	elif counter_left >= counter_right:
		print(length - counter_right)
	else:
		print(length - counter_left)


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	count = 0
	has = set()
	for i in range(n):
		if arr[i] not in has:
			has.add(arr[i])
			count += 1
	print(count)


from sys import stdin as s
for i in range(int(s.readline())):
	s.readline()
	print(len(set(s.readline().split())))


def f(al, x):
	flag = True
	for i in al:
		if i % x != 0:
			flag = False
	if flag:
		return -1
	if sum(al) % x != 0:
		return len(al)
	i = 0
	if al[0] % x != 0:
		return max(1, len(al) - 1)
	while i < len(al):
		if al[i] % x != 0:
			break
		i = i + 1
	return max(i + 1, len(al) - i - 1)
for tc in range(int(input())):
	al1 = list(map(int, input().split()))
	al2 = list(map(int, input().split()))
	al3 = list(tuple(al2))
	al3.reverse()
	print(max(f(al2, al1[1]), f(al3, al1[1])))


def solve(n, x, arr):
	if sum(arr) % x != 0:
		return n
	else:
		ans = 0
		for i in range(n):
			if arr[i] % x != 0:
				ans = n - i - 1
				break
		for j in range(n - 1, -1, -1):
			if arr[j] % x != 0:
				return max(ans, j)
		return -1
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(n, x, arr))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(n)
	else:
		flag = False
		for i in range(n // 2):
			if l[i] % x != 0 or l[n - i - 1] % x != 0:
				flag = True
				break
		if flag == False:
			print('-1')
		else:
			print(n - i - 1)


t = int(input())
result = ''
for x in range(t):
	n = int(input())
	temp = [int(i) for i in input().split(' ')]
	tempSet = set(temp)
	result += str(len(set(tempSet))) + '\n'
print(result)


z = int(input())
for x in range(z):
	p = int(input())
	k = list(input().strip().split()[:p])
	print(len(set(k)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a1 = list(map(int, input().split()))
	a = b = -1
	f = 0
	s = 0
	for i in range(n):
		if a1[i] % x != 0 and f == 0:
			a = i
			b = i
			f = 1
		elif a1[i] % x != 0:
			b = i
		s += a1[i]
	if f == 0:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		print(max(b - 0, n - (a + 1)))


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	first_nd = -1
	last_nd = -1
	summ = 0
	for (i, number) in enumerate(a):
		summ += number
		if number % x != 0:
			if first_nd == -1:
				first_nd = i
			last_nd = i
	if summ % x != 0:
		print(n)
	elif first_nd == -1:
		print('-1')
	else:
		print(max(last_nd, n - first_nd - 1))


N = int(input())
new = []
for _ in range(N):
	input()
	new.append(list(map(int, input().split())))
for i in new:
	print(len(set(i)))


T = int(input())
while T != 0:
	T -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	if sum(a) % x != 0:
		ans = n
	else:
		for i in range(n):
			if a[i] % x != 0:
				ans = max(ans, n - i - 1)
				break
		for i in range(n):
			if a[n - i - 1] % x != 0:
				ans = max(ans, n - i - 1)
				break
		if ans == 0:
			ans = -1
	print(ans)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	z = sum(c)
	if z % b != 0:
		print(a)
	else:
		(r, t) = (0, 0)
		for i in c:
			if i % b != 0:
				r += 1
				break
			else:
				r += 1
		for j in c[::-1]:
			if j % b != 0:
				t += 1
				break
			else:
				t += 1
		if min(r, t) == a:
			print(-1)
		else:
			print(a - min(r, t))


import math
for x in range(int(input())):
	b = int(input())
	a = list(map(int, input().split()))
	print(len(list(set(a))))


def test(jj, a2, b):
	n = len(b)
	for j in jj:
		b2 = b[n - 1 - j]
		if a2 == b2:
			return True
	return False

def main():
	(n, x) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	s = sum(a)
	if s % x != 0:
		return n
	i = 0
	while i < n and a[i] % x == 0:
		i += 1
	if i == n:
		return -1
	j = 0
	while j < n and a[n - j - 1] % x == 0:
		j += 1
	if i + j == n - 1:
		if i > j:
			return i
		else:
			return j
	if n - i > n - j:
		return n - i - 1
	else:
		return n - j - 1
for t in range(int(input())):
	print(main())


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = list(map(int, input().strip().split()))
	l = set(l)
	print(len(l))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	w = list(map(int, input().split()))
	if x == 1:
		print(-1)
	else:
		y = sum(w)
		if y % x != 0:
			print(n)
		else:
			c = n + 1
			for i in range(n - 1, -1, -1):
				if w[i] % x != 0:
					c = n - i
					break
			for i in range(n):
				if w[i] % x != 0:
					if i + 1 < c:
						c = i + 1
					break
			print(n - c)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	arr = []
	k = 0
	for i in a:
		if i % x != 0:
			arr.append([k, i % x])
		k += 1
	if len(arr) == 0:
		print(-1)
	else:
		ans = 0
		for i in arr:
			ans += i[1]
		if ans % x == 0:
			print(max(n - arr[0][0] - 1, arr[-1][0]))
		else:
			print(n)


def solve():
	(n, x) = map(int, input().split())
	A = list(map(lambda y: int(y) % x, input().split()))
	for a in A:
		if a != 0:
			break
	else:
		return -1
	s = sum(A)
	if s % x != 0:
		return n
	begin = 0
	end = 0
	for i in range(n):
		if A[i] != 0:
			begin = i + 1
			break
	for i in range(n - 1, -1, -1):
		if A[i] != 0:
			end = n - i
			break
	return n - min(begin, end)

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


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sa = sorted(list(set(a)))
	print(len(sa))


a = int(input())
n = 0
l1 = []
while n < a:
	n += 1
	b = int(input())
	l = list(map(int, input().strip().split()))[:b]
	s = set(l)
	l2 = []
	if len(l) == len(s):
		l1.append(len(l))
	else:
		l1.append(len(s))
for i in range(0, n):
	print(l1[i])


from copy import *
from math import *
t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(len(l))
		continue
	if sum(l) % x == 0:
		dd = []
		for j in range(len(l)):
			if l[j] % x != 0:
				dd.append(j)
		if len(dd) == 0:
			print(-1)
			continue
		kk = []
		for j in range(len(dd)):
			kk.append(max(dd[j], len(l) - 1 - dd[j]))
		print(max(kk))


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def in1():
	return int(input())

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

def inx():
	return [int(_) for _ in input().split()]
t = in1()
for _ in range(t):
	n = in1()
	a = inx()
	x = set(a)
	print(len(x))


t = int(input())
for w in range(t):
	n = int(input())
	a = map(int, input().split(' '))
	s = set(a)
	print(len(s))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	r = list(map(int, input().split()))
	p = sum(r)
	q = p
	if p % b != 0:
		print(a)
	else:
		z = 0
		for i in range(1, a + 1, 1):
			p -= r[i - 1]
			q -= r[-i]
			if p % b != 0:
				print(a - i)
				z = 1
				break
			elif q % b != 0:
				print(a - i)
				z = 1
				break
		if z == 0:
			print(-1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	List = [int(x) for x in input().split()]
	Parity = []
	for i in range(n):
		Parity.append(List[i] % x)
	if Parity.count(0) == n:
		print(-1)
		continue
	if sum(Parity) % x != 0:
		print(n)
	else:
		for i in range(n):
			if Parity[i] != 0:
				Start = i
				break
		for i in range(n - 1, -1, -1):
			if Parity[i] != 0:
				Last = i
				break
		print(max(Start + 1, n - Start - 1, Last, n - Last))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(map(int, input().split()))
	if sum(s) % x:
		print(n)
	else:
		l = 0
		r = n - 1
		while l <= r:
			if s[l] % x:
				print(n - l - 1)
				break
			if s[r] % x:
				print(r)
				break
			l += 1
			r -= 1
		else:
			print(-1)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = set(l)
	c = 0
	for i in x:
		c += 1
	print(c)


t = int(input())
for i in range(t):
	l = int(input())
	a = list(map(int, input().split(' ')))
	print(len(set(a)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	m = list(map(int, input().split()))
	if sum(m) % x != 0:
		print(n)
	else:
		ans = []
		for i in range(n):
			if m[i] % x != 0:
				ans.append(i)
		if len(ans):
			print(max(n - ans[0] - 1, ans[-1]))
		else:
			print(-1)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	lst = [int(i) for i in input().split()]
	sum1 = sum(lst)
	a = sum1
	b = sum1
	if sum1 % k != 0:
		print(n)
	else:
		z = 0
		for i in range(1, n + 1):
			a = a - lst[i - 1]
			b = b - lst[-i]
			if a % k != 0:
				z = 1
				print(n - i)
				break
			if b % k != 0:
				z = 1
				print(n - i)
				break
		if z == 0:
			print(-1)


from sys import stdin, stdout

def solve():
	(n, x) = stdin.readline().split()
	n = int(n)
	x = int(x)
	arr = [int(i) for i in stdin.readline().split()]
	f = 0
	sum = 0
	for i in arr:
		if i % x != 0:
			f = 1
		sum += i
	if f == 0:
		print(-1)
		return
	if sum % x != 0:
		print(n)
		return
	ans = 0
	for i in range(0, len(arr)):
		if arr[i] % x != 0:
			ans = max(ans, len(arr) - 1 - i)
			break
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] % x != 0:
			ans = max(ans, i)
			break
	print(ans)

def main():
	tt = int(stdin.readline())
	while tt:
		solve()
		tt -= 1
main()


from collections import Counter
for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	d = Counter(m)
	print(len(d))


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

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

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

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	l = inlt()
	m = l[0]
	k = l[1]
	l = inlt()
	mod_sum = 0
	for x in l:
		mod_sum = (mod_sum + x) % k
	if mod_sum != 0:
		print(m)
	else:
		lp = 0
		rp = 0
		t = 0
		while t < m:
			if l[t] % k != 0:
				break
			t += 1
		lp = t
		t = m - 1
		while t >= 0:
			if l[t] % k != 0:
				break
			t -= 1
		rp = t
		if rp == -1:
			print(-1)
		else:
			print(m - min(lp + 1, m - rp))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	i = 0
	j = 1
	while i < len(a) - 1:
		if a[i] != a[i + 1]:
			j += 1
		i += 1
	print(j)


t = int(input())
for kk in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	left = float('inf')
	summ = 0
	ans = -1
	for i in range(n):
		summ += l[i]
		if l[i] % x:
			left = min(left, i)
		if summ % x:
			ans = max(ans, i + 1)
		elif left != float('inf'):
			ans = max(ans, i - left)
	print(ans)


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
m = 1000000007
for _ in range(ii()):
	(n, x) = v()
	a = ll()
	s = sum(a)
	a1 = 0
	a2 = 0
	if s % x != 0:
		print(n)
		continue
	for i in range(0, n):
		if a[i] % x != 0:
			a1 = a1 + 1
			break
		else:
			a1 = a1 + 1
	a = list(a[::-1])
	for i in range(0, n):
		if a[i] % x != 0:
			a2 = a2 + 1
			break
		else:
			a2 = a2 + 1
	if a1 == n and a2 == n:
		print(-1)
	else:
		print(n - min(a1, a2))


import math

def main_function():
	test_cases = range(int(input()))
	for test_case in test_cases:
		is_printed = False
		(n, x) = [int(i) for i in input().split(' ')]
		a = [int(i) for i in input().split(' ')]
		total_sum = sum(a)
		total_len = len(a)
		if total_sum % x != 0:
			print(total_len)
			is_printed = True
		else:
			negative_sum = 0
			max_len = 0
			for i in range(len(a)):
				negative_sum += a[i]
				if negative_sum % x != 0:
					if total_len - (i + 1) > max_len:
						max_len = total_len - (i + 1)
					elif i + 1 > max_len:
						max_len = i + 1
			if max_len > 0:
				print(max_len)
			else:
				print(-1)
main_function()


def main():
	(a, b) = map(int, input().split())
	m = [int(s) for s in input().split()]
	i = 0
	i1 = -1
	i2 = -1
	if sum(m) / b != sum(m) // b:
		return a
	while i < a:
		if m[i] / b != m[i] // b:
			i1 = i
			break
		i += 1
	if i1 == -1:
		return -1
	i = a - 1
	while i >= 0:
		if m[i] / b != m[i] // b:
			i2 = i
			break
		i -= 1
	i1 = min(a - i2 - 1, i1)
	return max(len(m[:i1]), len(m[i1 + 1:]))
t = int(input())
for i in range(t):
	print(main())


from sys import stdin, stdout
from collections import Counter

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

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

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	(n, x) = ei()
	li = ai()
	ans = n
	s = sum(li)
	c = 0
	for i in range(n):
		if s % x == 0:
			ans -= 1
			s -= li[i]
		else:
			c += 1
			break
	ans2 = n
	s = sum(li)
	c2 = 0
	for i in range(n - 1, -1, -1):
		if s % x == 0:
			ans2 -= 1
			s -= li[i]
		else:
			c2 += 1
			break
	if c == 0 and c2 == 0:
		print(-1)
	else:
		print(max(ans, ans2))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = []
	s = 0
	for i in range(n):
		l.append(a[i] % x)
		s = (s + a[i] % x) % x
	if s != 0:
		print(n)
	elif l.count(0) == n:
		print(-1)
	else:
		p = 0
		for i in range(n):
			if l[i] != 0:
				p = i + 1
				break
		q = 0
		j = 0
		for i in range(n - 1, -1, -1):
			j += 1
			if l[i] != 0:
				q = j
				break
		print(max(n - p, n - q))


t = int(input())
for i in range(t):
	x = int(input())
	z = list(map(int, input().split()[:x]))
	p = 1
	z.sort()
	for j in range(x - 1):
		if z[j] != z[j + 1]:
			p = p + 1
	print(p)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	sum = 0
	for i in range(n):
		sum = sum + l[i]
	sum1 = sum
	if sum % x:
		print(n)
	else:
		a = -1
		b = -1
		for i in range(n):
			sum = sum - l[i]
			if sum % x:
				a = n - i - 1
				break
		for i in range(n - 1, -1, -1):
			sum1 = sum1 - l[i]
			if sum1 % x:
				b = i
				break
		print(max(a, b))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	m = sum(A)
	if m % x != 0:
		print(n)
	else:
		con = False
		for i in range(n // 2):
			if A[i] % x != 0 or A[n - i - 1] % x != 0:
				con = True
				break
		if con == False:
			print(-1)
		else:
			print(n - i - 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if all([i % x == 0 for i in a]):
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		(l, r) = (0, 0)
		for i in range(n):
			if a[i] % x != 0:
				l = i
				break
		for i in range(n):
			if a[n - i - 1] % x != 0:
				r = i
				break
		print(n - min(l, r) - 1)


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass

def case():
	arr = list(map(int, input().split(' ')))
	(n, x) = (arr[0], arr[1])
	arr = list(map(int, input().split(' ')))
	sum = 0
	left = -1
	right = -1
	for (index, value) in enumerate(arr):
		sum += value
		if left == -1 and value % x != 0:
			left = index
		if value % x != 0:
			right = index
	pos = -1
	if left >= 0:
		pos = left + 1
	if right >= 0:
		pos2 = n - right
		if pos > 0:
			pos = min(pos, pos2)
	result = n
	if sum % x == 0:
		if pos > 0:
			result -= pos
		else:
			result = -1
	print(result)
for _ in range(t):
	case()


import sys
input = sys.stdin.readline

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

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

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

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

def foo():
	t = inp()
	for i in range(t):
		n = inp()
		a = inlt()
		s = set(a)
		lis = list(s)
		print(len(lis))
foo()


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
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')
if not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)
if is_it_local():

	def debug(*args):
		st = ''
		for arg in args:
			st += f'{arg} '
		print(st)
else:

	def debug(*args):
		pass

def main():
	t = input1()
	for ci in range(t):
		(n, k) = input2()
		arr = input_array()
		cum = 0
		cum_a = []
		cum_a.append(cum)
		for v in arr:
			cum += v
			cum %= k
			cum_a.append(cum)
		last = cum_a[-1]
		ind = -1
		for (i, v) in enumerate(cum_a):
			if v != last:
				ind = i
		res = -1
		for i in range(1, len(cum_a)):
			nw = cum_a[i - 1]
			if last == nw and ind != -1:
				res = max(res, ind - i + 1)
			elif last != nw:
				res = max(res, len(cum_a) - i)
		print(res)
	pass
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	o = list(s)
	o.sort()
	print(len(o))


def main():
	inp = lambda : [int(x) for x in input().split()]
	i = lambda : int(input())
	for _ in range(i()):
		n = i()
		a = inp()
		print(len(set(a)))
main()


times = int(input())
for asdf in range(times):
	n = int(input())
	x = set(input().split())
	print(len(x))


sp = lambda : list(map(int, input().split()))
si = lambda : int(input())
TESTCASES = int(input())
ans = []
for tc in range(TESTCASES):
	n = si()
	aset = set(sp())
	ans.append(str(len(aset)))
print('\n'.join(ans))


from sys import stdin
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	A = list(map(int, stdin.readline().split()))
	A_dic = {}
	for item in A:
		if item not in A_dic:
			A_dic[item] = 1
	print(len(list(A_dic.values())))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	nonDivs = []
	for i in range(n):
		if arr[i] % x != 0:
			nonDivs.append(i)
	if len(nonDivs) == 0:
		print(-1)
	else:
		f = nonDivs[0]
		l = nonDivs[-1]
		if f + 1 >= n - l:
			res = l
		else:
			res = n - f - 1
		print(res)


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(len(arr)):
		arr[i] = arr[i] % x
	s = sum(arr)
	(left, right) = (0, 0)
	for i in range(n):
		if arr[i] != 0:
			left += 1
			break
		left += 1
	for i in range(n - 1, -1, -1):
		if arr[i] != 0:
			right += 1
			break
		right += 1
	ans = 0
	if s % x != 0:
		ans = n
	else:
		ans = max(n - left, n - right)
	print(ans if ans > 0 else -1)
	t -= 1


import queue
import math
t = int(input())
while t:
	n = int(input())
	a = input().split()
	a = set(map(int, a))
	print(len(a))
	t -= 1


def examA():
	T = I()
	ans = []
	for _ in range(T):
		x = I()
		ans.append([1, x - 1])
	for v in ans:
		print(' '.join(map(str, v)))
	return

def examB():
	T = I()
	ans = []
	for _ in range(T):
		N = I()
		A = LI()
		A = set(A)
		cur = len(A)
		ans.append(cur)
	for v in ans:
		print(v)
	return

def examC():
	T = I()
	ans = []
	for _ in range(T):
		cur = 0
		ans.append(cur)
	for v in ans:
		print(v)
	return

def examD():
	ans = 0
	print(ans)
	return

def examE():
	ans = 0
	print(ans)
	return

def examF():
	ans = 0
	print(ans)
	return
import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

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

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

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

def LS():
	return sys.stdin.readline().split()

def SI():
	return sys.stdin.readline().strip()
global mod, mod2, inf, alphabet, _ep
mod = 10 ** 9 + 7
mod2 = 998244353
inf = 10 ** 18
_ep = 10 ** (-12)
alphabet = [chr(ord('a') + i) for i in range(26)]
sys.setrecursionlimit(10 ** 6)
examB()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, x) = LI()
		a = LI()
		if sum(a) % x != 0:
			rr.append(n)
			continue
		r = -1
		for i in range(n):
			if a[i] % x != 0:
				t = max(n - i - 1, i)
				if r < t:
					r = t
		rr.append(r)
	return JA(rr, '\n')
print(main())


t = int(input())

def count():
	(n, a) = (input(), list(map(int, input().split(' '))))
	a = set(a)
	return len(a)
for i in range(t):
	print(count())


for t in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = sum(a)
	if b % x != 0:
		print(n)
	else:
		for i in range(n // 2 + 1):
			if a[i] % x != 0 or a[n - 1 - i] % x != 0:
				print(n - i - 1)
				break
		else:
			print('-1')


t = int(input())
for i in range(0, t):
	n = int(input())
	arr = []
	arr = list(map(int, input().split()))
	ar = set(arr)
	print(len(ar))


a = int(input())
for i in range(a):
	o = int(input())
	u = list(map(int, input().split()))
	print(len(set(u)))


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

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for _ in range(N):
	(n, x) = read_list()
	nums = read_list()
	s = sum(nums)
	if s % x != 0:
		print(n)
	else:
		flag = -1
		for i in range(n):
			if nums[i] % x != 0:
				flag = max(flag, i, n - i - 1)
				break
		for i in range(n - 1, -1, -1):
			if nums[i] % x != 0:
				flag = max(flag, i, n - i - 1)
				break
		print(flag)


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


import collections
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	C = collections.Counter(a)
	print(len(C))


for ii in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s2 = []
	if sum(a) % k != 0:
		print(n)
		continue
	for i in range(n):
		if a[i] % k != 0:
			s2.append(i)
	if not s2:
		print(-1)
	else:
		x = n - max(s2)
		y = min(s2) + 1
		if x > y:
			ans = y
		else:
			ans = x
		print(n - ans)


import sys
queries = int(sys.stdin.readline())
for query in range(queries):
	n = int(sys.stdin.readline())
	print(len({el: True for el in sys.stdin.readline().strip().split()}))


for _ in range(int(input())):
	k = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	c = sorted(b)
	print(len(c))


t = int(input())
for i in range(t):
	nx = list(map(int, input().split()))
	x = nx[1]
	a = list(map(int, input().split()))
	left = 0
	right = 0
	if sum(a) % x == 0:
		for i in range(len(a)):
			if a[i] % x != 0:
				left = i + 1
				break
			if i == len(a) - 1:
				left = len(a) + 1
		for i in reversed(range(len(a))):
			if a[i] % x != 0:
				right = len(a) - i
				break
			if i == 0:
				right = len(a) + 1
		print(max(len(a) - left, len(a) - right))
	else:
		print(len(a))


t = int(input())
for i in range(t):
	a = int(input())
	b = [int(x) for x in input().split()]
	b = set(b)
	print(len(b))


from sys import stdin

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		n = int(inp())
		a = set(list(map(int, inp().split())))
		print(len(a))
main()


def answer():
	n = int(input())
	while n:
		times = int(input())
		a = input().split()
		a = [int(x) for x in a]
		them = len(set(a))
		done = 0
		if them <= times:
			print(them)
			done = 1
		if not done:
			visited = []
			i = 0
			ans = 1
			while i < len(a) and ans < len(a) - len(visited):
				j = i
				temp = 1
				thing = a[j]
				while j < len(a):
					if a[j] > thing:
						visited.append(j)
						thing = a[j]
						temp += 1
					j += 1
				i += 1
				while i in visited:
					i += 1
				if ans < temp:
					ans = temp
			i = 0
			while i + 1 < times and ans < them:
				i += 1
				ans += 1
			print(ans)
		n -= 1
answer()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lis = list(map(int, input().split()))
	aa = [i % x for i in lis]
	if sum(aa) == 0:
		print(-1)
	elif sum(aa) % x:
		print(n)
	else:
		b = [i for i in range(n) if aa[i]]
		print(max(n - b[0] - 1, b[-1]))


testNumb = int(input())
for _ in range(testNumb):
	arrayLen = int(input())
	n = {}
	for x in input().split():
		n.setdefault(int(x), 0)
		n[int(x)] += 1
	print(len(n))


for i in range(int(input())):
	x = input()
	y = list(map(int, input().split()))
	print(len(set(y)))


q = int(input())
for z in range(q):
	(n, x) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	summ = 0
	for i in range(n):
		arr[i] %= x
		summ += arr[i]
	if summ % x:
		print(n)
	else:
		d1 = 0
		d2 = 0
		for i in range(n):
			if arr[i] == 0:
				d1 += 1
			else:
				break
		for i in range(n):
			if arr[n - 1 - i] == 0:
				d2 += 1
			else:
				break
		d = 0
		if d1 == 0:
			d = d2
		elif d2 == 0:
			d = d1
		else:
			d = min(d1, d2) + 1
		print(n - d if n - d != 0 else -1)


trials = int(input())
ans = []
for i in range(trials):
	n = int(input())
	A = input()
	A = [int(i) for i in A.split()]
	ans.append(len(list(set(A))))
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	low = min(a)
	s = set(a)
	count = 0
	for j in s:
		if j > low:
			count += 1
	print(count + 1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	a = list(dict.fromkeys(a))
	print(len(a))


import math
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	array = list(map(lambda y: int(y) % x, input().split()))
	ans = 0
	if sum(array) == 0:
		ans = -1
	else:
		s = sum(array)
		if s % x == 0:
			count = 0
			left = 0
			right = 0
			for i in array:
				if i % x == 0:
					left += 1
				else:
					break
			for i in range(n - 1, -1, -1):
				if array[i] % x == 0:
					right += 1
				else:
					break
			ans = n - 1 - min(left, right)
		else:
			ans = n
	print(ans)


def checkio(arr):
	counter = 0
	min_item = min(arr)
	max_item = max(arr)
	sets = list(set(arr))
	print(len(sets))
for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	checkio(arr)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

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

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

def sep_input():
	return map(int, input().split())
for _ in range(int(input())):
	(n, k) = sep_input()
	l = list_input()
	s = sum(l)
	if s % k != 0:
		print(n)
	elif l.count(0) == n:
		print(-1)
	else:
		c = 0
		ans = 0
		for i in range(n):
			c += l[i]
			if c % k != 0:
				ans = max(ans, i + 1)
		l = l[::-1]
		c = 0
		for i in range(n):
			c += l[i]
			if c % k != 0:
				ans = max(ans, i + 1)
		if ans == 0:
			ans = -1
		print(ans)


from sys import stdin
inf = stdin
for qw in range(int(inf.readline())):
	n = int(inf.readline())
	arr = list(map(int, inf.readline().split(' ')))
	print(len(set(arr)))


for t in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	ans = len(arr)
	if s % x != 0:
		print(ans)
	else:
		l = 0
		r = n - 1
		flag = 0
		while l <= r:
			if (s - arr[l]) % x != 0:
				ans -= 1
				flag = 1
				break
			elif (s - arr[r]) % x != 0:
				ans -= 1
				flag = 1
				break
			else:
				s -= arr[l]
				s -= arr[r]
				ans -= 2
			l += 1
			r -= 1
		s = sum(arr)
		ans2 = n - 1
		ans3 = n - 1
		for i in range(n):
			if (s - arr[i]) % x != 0:
				break
			else:
				ans2 -= 1
				s -= arr[i]
		s = sum(arr)
		for i in range(n - 1, -1, -1):
			if (s - arr[i]) % x != 0:
				break
			else:
				ans3 -= 1
				s -= arr[i]
		if flag == 1:
			print(max(ans, ans2, ans3))
		else:
			print(-1)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ru = [0] * (n + 1)
	for i in range(n):
		ru[i + 1] = (ru[i] + a[i]) % x
	ans = -1
	for i in range(n + 1):
		if ru[i] != 0:
			ans = max(i, ans)
	l = -1
	for i in range(n + 1):
		if l != -1:
			if ru[l] != ru[i]:
				ans = max(ans, i - l)
			continue
		if ru[i] != 0:
			l = i
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if x == 1:
		print(-1)
	elif sum(l) % x != 0:
		print(n)
	else:
		mi = 1000001
		mx = -1
		for i in range(0, n):
			if l[i] % x != 0:
				mi = min(mi, i)
				mx = max(mx, i)
		if mx == -1 and mi == 1000001:
			print(-1)
		else:
			print(max(n - mi - 1, mx))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	al = list(map(int, input().split()))
	if sum(al) % x != 0:
		print(n)
		continue
	if n == 1:
		if al[0] % x == 0:
			print(-1)
			continue
		else:
			print(1)
			continue
	pref = []
	summ = 0
	for i in range(n):
		summ += al[i]
		pref.append(summ)
	maxlen = -1
	for i in range(n - 1, -1, -1):
		if (pref[-1] - pref[i] + al[i]) % x != 0:
			maxlen = n - i
	for i in range(n):
		if pref[i] % x != 0:
			maxlen = max(maxlen, i + 1)
	print(maxlen)


t = int(input())
while t:
	input()
	t -= 1
	print(len(set(input().split(' '))))


T = int(input())
for case in range(T):
	n = int(input())
	ls = set([int(x) for x in input().split()])
	print(len(ls))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	a = set(a)
	print(len(a))


t = int(input())
for q in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dt = dict()
	for i in a:
		dt[str(i)] = dt.get(str(i), 0) + 1
	print(len(dt))


def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1

def fun():
	x = int(input())
	for _ in range(x):
		temp = int(input())
		my_set = set()
		inp = input().split()
		for i in range(temp):
			my_set.add(int(inp[i]))
		s = list(my_set)
		mergeSort(s)
		print(len(s))
fun()


def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		array = list(map(int, input().split()))
		if n >= len(array):
			yield len(set(array))
		else:
			yield lis(array * n)
t = int(input())
ans = gift()
print(*ans, sep='\n')


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from collections import Counter
from bisect import bisect_left
import sys
from queue import PriorityQueue
mod = 1000000007

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

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

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

def printIn(ob):
	return stdout.write(str(ob) + '\n')

def powerLL(n, p):
	result = 1
	while p:
		if p & 1:
			result = result * n % mod
		p = int(p / 2)
		n = n * n % mod
	return result

def myCode():
	(n, x) = map(int, input().split())
	lst1 = L()
	lst2 = list(lst1)
	lst2.reverse()
	for i in range(1, len(lst1)):
		lst1[i] = lst1[i - 1] + lst1[i]
	for i in range(1, len(lst2)):
		lst2[i] = lst2[i - 1] + lst2[i]
	flag1 = False
	flag2 = False
	ans1 = -sys.maxsize
	for i in range(len(lst1)):
		if lst1[i] % x is not 0:
			ans1 = max(ans1, i)
			flag1 = True
	ans2 = -sys.maxsize
	for i in range(len(lst2)):
		if lst2[i] % x is not 0:
			ans2 = max(ans2, i)
			flag2 = True
	if ans2 > ans1 and flag2:
		print(ans2 + 1)
	elif ans1 >= ans2 and flag1:
		print(ans1 + 1)
	else:
		print(-1)

def main():
	for t in range(I()):
		myCode()
main()


for _ in range(int(input())):
	n = int(input())
	A = list((int(i) for i in input().split()))
	A.sort()
	count = 1
	for i in range(1, n):
		if A[i] > A[i - 1]:
			count += 1
	print(count)


n = int(input())
for i in range(n):
	y = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	res = 0
	i = 0
	while i < y:
		while i < y - 1 and arr[i] == arr[i + 1]:
			i += 1
		res += 1
		i += 1
	print(res)


from collections import Counter
t = int(input())
for testcases in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = len(Counter(a).keys())
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	print(len(set([int(i) for i in input().split()])))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(len(list(dict.fromkeys(arr))))


t = int(input())
for _ in range(t):
	l = int(input())
	vals = list(map(int, input().split()))
	unique = set()
	for v in vals:
		unique.add(v)
	print(len(unique))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	y = sum(a)
	if y % x != 0:
		print(n)
	else:
		b = []
		(k, t) = (0, 0)
		for i in range(n):
			k += a[i]
			if (y - k) % x != 0:
				b.append(n - i - 1)
				break
		for j in range(n - 1, -1, -1):
			t += a[j]
			if (y - t) % x != 0:
				b.append(j)
				break
		if len(b) == 0:
			print(-1)
		else:
			print(max(b))


for _ in range(int(input())):
	n = int(input())
	seq = list(map(int, input().split()))
	ns = set(seq)
	print(len(ns))


t = int(input())
for i in range(0, t):
	nx = list(map(int, input().split()))
	(n, x) = (nx[0], nx[1])
	nums = list(map(int, input().split()))
	if not sum(nums) % x == 0:
		print(n)
	else:
		(left, right) = (0, n - 1)
		for j in range(0, n):
			if nums[n - j - 1] % x == 0:
				right -= 1
			else:
				right -= 1
				break
		for j in range(0, n):
			if nums[j] % x == 0:
				left += 1
			else:
				left += 1
				break
		if left >= n:
			print(-1)
		else:
			print(max(n - left, right + 1))


for jack in range(int(input())):
	n = int(input())
	print(len(set(map(int, input().split()))))


def solve(n, x, a):
	sol = -1
	s = 0
	for i in range(n):
		s += a[i]
		if s % x != 0:
			sol = max(sol, i + 1)
	s = 0
	l = 0
	for i in range(n - 1, -1, -1):
		s += a[i]
		l += 1
		if s % x != 0:
			sol = max(sol, l)
	return sol
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(n, x, a))


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	dick = {}
	for i in array:
		dick[i] = 1
	print(len(dick))


q = int(input())
for _ in range(q):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		st = -1
		fin = -1
		for i in range(n):
			if l[i] % x != 0:
				fin = i
				if st == -1:
					st = i
		if st == -1:
			print(-1)
		else:
			print(max(fin, n - 1 - st))


for j in range(int(input())):
	(n, x) = map(int, input().split())
	t = list(map(int, input().split()))
	nds = 'b'
	nde = 'a'
	if sum(t) % x != 0:
		print(n)
	else:
		for i in range(n):
			if t[i] % x != 0:
				nds = i
				break
		for i in range(n - 1, -1, -1):
			if t[i] % x != 0:
				nde = i
				break
		if nds != 'b' and nde != 'a':
			print(max(n - len(t[:nds + 1]), n - len(t[nde:])))
		else:
			print(-1)


def setcount(l):
	x = set(l)
	return len(x)
t = int(input())
while t:
	t = t - 1
	n = int(input())
	l = [int(i) for i in input().split()]
	print(setcount(l))


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, x) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	l = n + 2
	r = n + 2
	s = 0
	for (idx, val) in enumerate(a):
		if val % x != 0:
			if l == n + 2:
				l = idx + 1
			r = n - idx
		s += val
	res = n
	if s % x == 0:
		if l != n + 2 or r != n + 2:
			res -= min(l, r)
		else:
			res = -1
	print(res)


for i in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	first = None
	s = 0
	ans = -10 ** 9
	for i in range(n):
		s += arr[i]
		if s % k == 0:
			if first != None:
				ans = max(ans, i - first)
		else:
			if first == None:
				first = i
			ans = i + 1
	ans = ans if ans != -10 ** 9 else -1
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	z = 0
	s = 0
	ans = -1
	for (i, x) in enumerate(map(int, input().split())):
		s = (s + x) % m
		if s:
			ans = i + 1
		else:
			if i == z:
				z += 1
			ans = max(ans, i - z)
	print(ans)


n = int(input())
for i in range(n):
	l = int(input())
	c = list(map(int, input().split()))
	d = {}
	count = 0
	for j in c:
		if j not in d:
			d[j] = 1
			count = count + 1
	print(count)


for x11 in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = []
	ans = 0
	s = 0
	l2 = []
	o = 0
	l1.append(l[0])
	l2.append(l[n - 1])
	for x1 in range(1, n):
		l1.append(l1[x1 - 1] + l[x1])
	s = l1[n - 1]
	for x1 in range(n - 1):
		if (s - l1[x1]) % x != 0:
			ans = max(ans, n - x1 - 1)
			break
	for x1 in range(n - 1, -1, -1):
		if l1[x1] % x != 0:
			ans = max(ans, x1 + 1)
			break
	if ans == 0:
		print(-1)
	else:
		print(ans)


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = tuple(map(int, input().split()))
	if sum(a) % x:
		print(n)
	elif any((ai % x for ai in a)):
		non0s = tuple((i for i in range(n) if a[i] % x))
		print(max(max(non0s), n - min(non0s) - 1))
	else:
		print(-1)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	count = 1
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			count += 1
		else:
			continue
	print(count)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	t = sum(a)
	ans = 0
	if t % x != 0:
		print(n)
	else:
		i = 0
		j = n - 1
		while i < j:
			v = t - (a[i] + a[j])
			if (t - a[i]) % x != 0 or (t - a[j]) % x != 0:
				ans = j - i
				break
			elif v % x != 0:
				ans = j - i - 1
				break
			else:
				t -= a[i] + a[j]
			j -= 1
			i += 1
		t1 = sum(a)
		for k in range(n):
			if (t1 - a[k]) % x != 0:
				ans = max(n - k - 1, ans)
				break
			else:
				t1 -= a[k]
		t1 = sum(a)
		for k in range(n - 1, -1, -1):
			if (t1 - a[k]) % x != 0:
				ans = max(k, ans)
				break
			else:
				t1 -= a[k]
		if ans:
			print(ans)
		else:
			print(-1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	x = [l[0]]
	(a1, a2) = (-1, -1)
	for i in range(1, n):
		if x[-1] % k != 0:
			a1 = n - len(x)
			break
		x.append(x[-1] + l[i])
	x = [l[n - 1]]
	for i in range(n - 2, -1, -1):
		if x[-1] % k != 0:
			a2 = i + 1
			break
		x.append(x[-1] + l[i])
	if sum(l) % k != 0:
		print(n)
	else:
		print(max(a1, a2))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	counter = 0
	for i in range(n):
		counter += a[i]
		a[i] = counter % k
		if a[i] != 0:
			a[i] = 1
	if 1 in a:
		if a.count(0) == 0:
			print(n)
		else:
			front_one = a.index(1)
			front_zero = a.index(0)
			a.reverse()
			last_one = n - 1 - a.index(1)
			last_zero = n - 1 - a.index(0)
			ans = 0
			ans = max(ans, last_one - front_one + 1)
			ans = max(ans, last_one - front_zero + 1)
			ans = max(ans, last_zero - front_one)
			print(ans)
	else:
		print(-1)


t = int(input())
out = []
for i in range(t):
	a = []
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	out.append(len(set(a)))
for j in range(t):
	print(out[j])


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	items = list(map(int, input().split()))
	div = []
	for item in items:
		if item % x == 0:
			div.append(1)
		else:
			div.append(0)
	s = sum(items)
	if s % x != 0:
		print(n)
	elif 0 not in div:
		print(-1)
	else:
		a = div.index(0)
		b = div[::-1].index(0)
		print(n - min([a, b]) - 1)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def solve(a):
	set_a = set(a)
	return str(len(set_a))
answers = []
t = int(input())
for i in range(t):
	n = int(input())
	a = to_list(input())
	answers.append(solve(a))
print('\n'.join(answers))


t = int(input())
arr = list()
st = set()
for i in range(0, t):
	x = int(input())
	arr = list(map(int, input().split()))
	for n in arr:
		st.add(n)
	print(len(st))
	st.clear()


t = input()
for _ in range(int(t)):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	l = -1
	r = -1
	for i in range(n):
		if arr[i] % x != 0:
			if l == -1:
				l = i
		if arr[n - 1 - i] % x != 0:
			if r == -1:
				r = i
	if s % x != 0:
		print(n)
	elif l == -1:
		print(-1)
	else:
		print(n - min(l + 1, r + 1))


tests = int(input())
for test in range(0, tests):
	lst = []
	n = int(input())
	lst = [int(x) for x in input().split()]
	lst = list(dict.fromkeys(lst))
	print(len(lst))


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	a = set(a)
	print(len(a))


def solution():
	tests = []
	for _ in range(int(input())):
		(x, y) = (int(i) for i in input().split(' '))
		arr = [int(i) for i in input().split(' ')]
		tests.append((x, y, arr))
	for test in tests:
		(n, x, arr) = test
		c = float('-inf')
		(s, m1, m2) = (0, 0, 0)
		for i in arr:
			s += i
		if s % x != 0:
			print(n)
		else:
			for i in range(n):
				if (s - arr[i]) % x != 0:
					break
				else:
					s -= arr[i]
			if i != n:
				m1 = n - 1 - i
				i = n - 1
				while i >= 0:
					if (s - arr[i]) % x != 0:
						break
					else:
						s -= arr[i]
					i -= 1
				if i >= 0:
					m2 = i
				if m1 == 0 and m2 == 0:
					print(-1)
				else:
					print(max(m1, m2))
solution()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sumall = 0
	for i in range(n):
		sumall += a[i]
	c = 0
	c2 = 0
	sa = sumall
	for i in range(n):
		if sumall % x == 0:
			sumall -= a[i]
			c += 1
		else:
			break
	for j in reversed(range(n)):
		if sa % x == 0:
			sa -= a[j]
			c2 += 1
		else:
			break
	o1 = len(a) - c
	o2 = len(a) - c2
	ans = max(o1, o2)
	if sumall % x != 0 or sa % x != -0:
		print(ans)
	else:
		print('-1')


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	(n, x) = int_array()
	a = int_array()
	if sum(a) % x != 0:
		print(n)
		continue
	len1 = None
	len2 = None
	s = 0
	for i in range(n):
		s += a[i]
		if s % x != 0:
			len1 = n - (i + 1)
			break
	s = 0
	a = a[::-1]
	for i in range(n):
		s += a[i]
		if s % x != 0:
			len2 = n - (i + 1)
			break
	if len1 == None:
		print(-1)
	else:
		print(max(len1, len2))


e = int(input())
fin = []
for i in range(e):
	n = int(input())
	L = input().split()
	arr = []
	for r in range(n):
		arr.append(int(L[r]))
	List = list(dict.fromkeys(arr))
	fin.append(len(List))
for j in fin:
	print(j)


t = int(input())
while t:
	(n, x) = [int(i) for i in input().split()]
	left = -1
	right = -1
	sum = 0
	a = [int(i) for i in input().split()]
	for i in range(n):
		if a[i] % x:
			if left == -1:
				left = i
			right = i
		sum += a[i]
	if sum % x:
		print(n)
	elif left == -1:
		print(-1)
	else:
		print(n - min(left + 1, n - right))
	t -= 1


test = int(input())
test_arr = []
for _ in range(test):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	(l, r) = (-1, -1)
	sum_ = 0
	max_ = 0
	for (i, a) in enumerate(arr):
		sum_ += a
		if a % x:
			if l == -1:
				l = i
			r = i
	if sum_ % x:
		max_ = n
	elif l == -1:
		max_ = -1
	else:
		max_ = n - min(l + 1, n - r)
	test_arr.append(max_)
for t in test_arr:
	print(t)


t = int(input())
for q in range(t):
	(n, x) = map(int, input().split())
	mas = list(map(int, input().split()))
	if sum(mas) % x != 0:
		print(n)
	else:
		ans = []
		for i in range(n):
			if mas[i] % x != 0:
				ans.append(i)
		if len(ans):
			print(max(n - ans[0] - 1, ans[-1]))
		else:
			print(-1)


t = int(input())
while t != 0:
	arr = []
	n = int(input())
	arr = [int(x) for x in input().split()]
	b = set(arr)
	print(len(b))
	t = t - 1


from sys import stdin
A = int(stdin.readline())
for k in range(0, A):
	B = list(map(int, stdin.readline().split()))
	sum = 0
	C = list(map(int, stdin.readline().split()))
	LIST = list()
	K = 0
	for t in range(0, B[0]):
		if C[t] % B[1] != 0:
			LIST.append(t)
		sum += C[t]
	if sum % B[1] != 0:
		print(B[0])
		continue
	if len(LIST) == 0:
		print(-1)
		continue
	print(max(B[0] - min(LIST) - 1, max(LIST)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x != 0:
		print(n)
	else:
		a = [i % x for i in arr]
		f = -1
		b = n
		for i in range(n):
			if a[i] > 0:
				f = i
				break
		if f == -1:
			print(-1)
		else:
			for i in range(n - 1, -1, -1):
				if a[i] > 0:
					b = i
					break
			print(max(n - f - 1, b))


import os
import sys
from io import BytesIO, IOBase

def readvars():
	k = map(int, input().split())
	return k

def readlist():
	li = list(map(int, input().split()))
	return li

def anslist(li):
	ans = ' '.join([str(v) for v in li])
	return ans

def main():
	t = 1
	t = int(input())
	for xx in range(t):
		(n, x) = readvars()
		a = readlist()
		tot = sum(a)
		if tot % x != 0:
			print(n)
		else:
			cand = 0
			falg = 0
			for i in range(n):
				if a[i] % x != 0:
					cand = n - i - 1
					break
				if i == n - 1 and a[i] % x == 0:
					falg = 1
			for i in range(n - 1, -1, -1):
				if a[i] % x != 0:
					cand = max(cand, i)
					break
			if falg == 1:
				print(-1)
			else:
				print(cand)
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()


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = set()
	for ai in a:
		b.add(ai)
	print(len(b))


def solve():
	n = int(input())
	lst = list(map(int, input().split()))
	print(len(set(lst)))
t = int(input())
for i in range(t):
	solve()


nb_test = int(input())
for test in range(0, nb_test):
	_res = {}
	size = input()
	str_arr = input().split(' ')
	for i in str_arr:
		if int(i) in _res.keys():
			pass
		else:
			_res[int(i)] = 0
	print(len(_res))


import os
import sys
from io import BytesIO, IOBase

def CeilIndex(A, l, r, key):
	while r - l > 1:
		m = l + (r - l) // 2
		if A[m] >= key:
			r = m
		else:
			l = m
	return r

def Lis(A, size):
	tailTable = [0 for i in range(size + 1)]
	leng = 0
	tailTable[0] = A[0]
	leng = 1
	for i in range(1, size):
		if A[i] < tailTable[0]:
			tailTable[0] = A[i]
		elif A[i] > tailTable[leng - 1]:
			tailTable[leng] = A[i]
			leng += 1
		else:
			tailTable[CeilIndex(tailTable, -1, leng - 1, A[i])] = A[i]
	return leng

def main():
	for _ in range(int(input())):
		n = int(input())
		a = set(map(int, input().split()))
		print(len(a))
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()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * n
	for i in range(n):
		if a[i] % x != 0:
			b[i] = 1
	if b.count(0) == n:
		print(-1)
		continue
	if sum(a) % x != 0:
		print(n)
		continue
	f = b.index(1)
	for i in range(n):
		if b[i] == 1:
			j = i
	print(max(f, j, n - 1 - f, n - 1 - j))


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	print(len(set(lst)))


def sint():
	return int(input())

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

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

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

def solve():
	t = sint()
	while t:
		t -= 1
		n = sint()
		vis = {}
		cnt = 0
		ara = sara()
		for i in ara:
			if not i in vis:
				vis[i] = 1
				cnt += 1
		print(cnt)
solve()


def spe(n, x):
	compteurdeb = 0
	compteurfin = 0
	if sum(liste) % x != 0:
		return len(liste)
	for loop in range(len(liste)):
		if liste[loop] % x == 0:
			compteurdeb += 1
		else:
			break
	for loop in range(len(liste) - 1, -1, -1):
		if liste[loop] % x == 0:
			compteurfin += 1
		else:
			break
	if compteurdeb == len(liste) or compteurfin == len(liste):
		return -1
	else:
		return len(liste) - (min(compteurdeb, compteurfin) + 1)
nb = int(input())
for loop in range(nb):
	liste2 = []
	maxx = 0
	(n, x) = map(int, input().split())
	liste = [int(x) for x in input().split()]
	print(spe(n, x))


def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int, rev=False):
	return sorted(map(func, input().split()), reverse=rev)

def ml_unpack(n):
	return [int(input()) for _ in range(n)]

def range_n():
	return range(int(input()))

def getint():
	return int(input())

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def main():
	for _ in range_n():
		(n, x) = unpack()
		a = l_unpack()
		(lo, hi) = (0, n - 1)
		(front, back) = (-1, -1)
		while lo < n:
			if not a[lo] % x:
				lo += 1
			else:
				front = lo
				break
		while hi >= 0:
			if not a[hi] % x:
				hi -= 1
			else:
				back = hi
				break
		if front == back == -1:
			print(-1)
			continue
		if sum(a) % x:
			print(n)
			continue
		ans = n - min(front + 1, n - back)
		print(ans)
main()


import sys
import collections as cc
import bisect as bi
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, x) = I()
	a = I()
	f = cc.defaultdict(int)
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		for i in range(n):
			a[i] %= x
		xx = 0
		yy = 0
		temp = 0
		if a.count(0) == n:
			print(-1)
			continue
		for i in range(n):
			if a[i]:
				xx = i + 1
				break
		tem = 0
		for j in range(n - 1, -1, -1):
			if a[j]:
				yy = j
				break
		print(max(n - xx, yy))


case = int(input())
for i in range(case):
	n = int(input())
	a = set([int(v) for v in input().split()])
	print(len(a))


for i in range(int(input())):
	n = int(input())
	a = set(map(int, input().split()))
	print(len(a))


def solve(n, h, v):
	if len(list(filter(lambda x: x % h == 0, v))) == n:
		return -1
	if sum(v) % h != 0:
		return n
	ix1 = next(filter(lambda i: v[i] % h != 0, range(n)))
	ixn = next(filter(lambda i: v[-(i + 1)] % h != 0, range(n)))
	return n - min(ix1, ixn) - 1
cases = int(input().strip())
for _ in range(cases):
	(n, h) = list(map(int, input().strip().split()))
	v = list(map(int, input().strip().split()))
	print(solve(n, h, v))


from sys import stdin, stdout
from collections import Counter

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

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

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	n = ip()
	li = ai()
	print(len(set(li)))


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	print(len(set([int(x) for x in input().split()])))


t = int(input())

def solve():
	input()
	x = map(int, input().split())
	print(len(set(x)))
for _ in range(t):
	solve()


for t in range(int(input())):
	(n, x) = map(int, input().split())
	num = list(map(int, input().split()))
	ss = sum(num)
	if ss % x != 0:
		print(n)
		continue
	else:
		ans = -1
		for i in range(n):
			if num[i] % x != 0:
				ans = n - 1 - i
				break
		for i in range(n - 1, -1, -1):
			if num[i] % x != 0:
				ans = max(i, ans)
				break
		print(ans)


import sys
from collections import Counter

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 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	ans = len(set(A))
	print(ans)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	for i in range(ii()):
		(n, x) = mi()
		arr = li()
		s = 0
		m = 0
		idx1 = 0
		for idx2 in range(n):
			s += arr[idx2]
			if s % x != 0:
				m = max(m, idx2 - idx1 + 1)
		for idx1 in range(n):
			s -= arr[idx1]
			if s % x != 0:
				m = max(m, idx2 - idx1)
		if m != 0:
			print(m)
		else:
			print(-1)
main()


exec(int(input()) * 'input();print(len(set(input().split())));')


t = int(input())
result = []
while t:
	n = int(input())
	string = list(map(int, input().split()))
	qty_unique = len(set(string))
	result.append(qty_unique)
	t -= 1
for res in result:
	print(res)


t = int(input())
for i in range(t):
	(s, temp1, temp2, f, v) = (0, 0, 0, 0, 0)
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	for j in range(len(a)):
		s += a[j]
	v = s
	for j in range(len(a)):
		if v % x != 0:
			f = 1
			temp1 = j
			break
		else:
			v -= a[j]
	temp1 = n - temp1
	if f == 0:
		print('-1', end='\n')
	else:
		v = s
		for j in range(len(a)):
			if s % x != 0:
				temp2 = j
				break
			else:
				s -= a[n - j - 1]
		temp2 = n - temp2
		print(max(temp1, temp2), end='\n')


testcases = int(input())
while testcases > 0:
	n = int(input())
	myArray = list(map(int, input().split()))
	myMap = dict()
	for i in range(len(myArray)):
		if myMap.get(myArray[i]) == None:
			myMap[myArray[i]] = 1
		else:
			myMap[myArray[i]] += 1
	print(len(myMap))
	testcases -= 1


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	c = 1
	a.sort()
	for i in range(1, n):
		if a[i] != a[i - 1]:
			c += 1
	print(c)


from sys import stdin
input = stdin.readline
q = int(input())
for rrew in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(n):
		d[l[i]] = 0
	odp = 0
	for elt in d:
		odp += 1
	print(odp)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	summ1 = sum(arr)
	summ2 = sum(arr)
	ans = n + 1
	for i in range(n):
		if summ1 % x != 0:
			ans = i
			break
		if summ2 % x != 0:
			ans = i
			break
		summ1 -= arr[i]
		summ1 -= arr[-1 - i]
	print(n - ans)


for i in range(int(input())):
	count = 1
	n = int(input())
	x = list(input().split())
	x.sort()
	for j in range(n - 1):
		if x[j] == x[j + 1]:
			pass
		else:
			count += 1
	print(count)


import math
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	total = sum(arr)
	ans = 0
	flag = 0
	if total % x == 0:
		if n == 1:
			print(-1)
		else:
			until = math.ceil(n / 2)
			for i in range(0, until + 1, 1):
				if arr[i] % x != 0 or arr[n - i - 1] % x != 0:
					ans = n - i - 1
					flag = 1
					break
			if flag == 0:
				print(-1)
			else:
				print(ans)
	else:
		print(n)


t = int(input())
for i in range(t):
	x = int(input())
	l = list(map(int, input().split()))
	s = len(set(l))
	print(s)


test = int(input())
for t in range(test):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	sum = 0
	ans = -2
	found = False
	for c in arr:
		sum += c
		if c % x != 0:
			found = True
	if sum % x != 0:
		ans = n
	elif found == False:
		ans = -1
	else:
		fidx = -1
		lidx = -1
		for c in range(n):
			if arr[c] % x != 0:
				if fidx == -1:
					fidx = c
				else:
					lidx = c
		ans = n - min(fidx + 1, n - lidx)
	print(ans)


from sys import stdin, stdout
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def main():
	T = int(rl())
	for _ in range(T):
		n = int(rl())
		(seen, ans) = (set(), 0)
		for char in rll():
			x = int(char)
			if x not in seen:
				ans += 1
				seen.add(x)
		stdout.write(str(ans))
		stdout.write('\n')
	stdout.close()
main()


def answer(arr):
	return len(set(arr))
testCount = int(input())
for _ in range(testCount):
	n = int(input())
	arr = list(map(int, input().split()))
	print(answer(arr))


t = int(input())
for z in range(t):
	(n, x) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	if sum(l) % x != 0:
		print(n)
	else:
		thing1 = 0
		thing2 = 0
		for i in l:
			thing1 += 1
			if i != 0 and i % x != 0:
				break
		for i in l[::-1]:
			thing2 += 1
			if i != 0 and i % x != 0:
				break
		if min(thing1, thing2) == n:
			print(-1)
		else:
			print(n - min(thing1, thing2))


import collections
t = int(input())
for q in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split()]
	a = set(a)
	print(len(a))


from math import sqrt

def main():
	d = int(input())
	for i in range(d):
		c = int(input())
		data = [int(v) for v in input().split()]
		print(len(set(data)))
main()


for t in range(int(input())):
	(n, x) = [int(j) for j in input().split()]
	l = [int(j) % x for j in input().split()]
	fn = n
	pr = []
	tmp = 0
	for i in range(n):
		pr.append((l[i] + tmp) % x)
		tmp = pr[i]
	for i in range(n):
		if pr[i] != 0:
			fn = i
			break
	ans = 0
	for i in range(n):
		if pr[i] == 0:
			ans = max(i - fn, ans)
		else:
			ans = max(ans, i + 1)
	if ans == 0:
		print(-1)
	else:
		print(ans)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	n = sInt()
	a = lInt()
	us = set(a)
	print(len(us))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	div = [c % x == 0 for c in a]
	if all(div):
		print(-1)
		continue
	s = sum(a)
	if s % x:
		print(n)
	else:
		i = min(div.index(False), div[::-1].index(False))
		print(n - 1 - i)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = -1
	total = sum(l)
	if total % x != 0:
		print(n)
	else:
		temp = total
		for i in range(n):
			if l[i] % x != 0:
				ans = max(ans, n - i - 1)
				break
		for i in range(n - 1, -1, -1):
			if l[i] % x != 0:
				ans = max(ans, i)
				break
		print(ans)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	s = set()
	ls = list(map(int, input().split()))
	for j in range(len(ls)):
		s.add(ls[j])
	ans.append(len(s))
for i in range(t):
	print(ans[i])


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

def solve(N, A):
	return len(set(A))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


from sys import stdin, stdout
from sys import maxsize

def solve():
	pass
test = 1
test = int(input())
for t in range(0, test):
	(n, x) = list(map(int, input().split()))
	arr = [int(x) for x in input().split()]
	s = [0]
	temp = 0
	for i in arr:
		temp += i
		s.append(temp % x)
	v = s[-1]
	for j in range(n + 1):
		if s[j] != v:
			break
	l1 = n - j
	v = s[0]
	for j in range(n, -1, -1):
		if s[j] != v:
			break
	l2 = j
	l = max(l1, l2)
	if l == 0:
		print(-1)
	else:
		print(max(l1, l2))
	ans = solve()


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	count = 0
	for j in range(n - 1):
		if arr[j] == arr[j + 1]:
			count += 1
	print(n - count)


n = int(input())
for i in range(n):
	size = int(input())
	d = sorted(set(map(int, input().split())))
	print(min(size, len(d)))


t = int(input())
for q in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l = sorted(l)
	count = 0
	for i in range(n - 1):
		if l[i] == l[i + 1]:
			count += 1
	print(n - count)


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	x = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	lfi = []
	sumi = 0
	for i in range(n):
		sumi += li[i]
		if sumi % x:
			lfi.append(i + 1)
	li.reverse()
	sumi = 0
	for i in range(n):
		sumi += li[i]
		if sumi % x:
			lfi.append(i + 1)
	if lfi == []:
		print(-1)
	else:
		print(max(lfi))


t = int(input())
for p in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	S = sum(a)
	if S % x != 0:
		print(n)
	else:
		for i in range(n // 2 + 1):
			if a[i] % x != 0:
				print(n - i - 1)
				break
			if a[n - i - 1] % x != 0:
				print(n - i - 1)
				break
		else:
			print(-1)


try:
	t = int(input())
	for i in range(0, t):
		a = []
		b = []
		n = int(input())
		a = map(int, input().split())
		a = list(set(a))
		ans = len(a)
		print(ans)
except:
	print(t, a, b)


t = int(input())
M = []

def fonction(n, L):
	return len(set(L))
for i in range(t):
	n = int(input())
	L = [int(x) for x in input().split()]
	M.append(fonction(n, L))
for k in M:
	print(k)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	aa = list(map(int, input().split()))
	v = sum(aa) % x
	if v != 0:
		print(n)
	else:
		q = 0
		while q < n:
			if aa[q] % x != 0:
				break
			q += 1
		else:
			print(-1)
			continue
		w = 0
		while w < n:
			if aa[n - w - 1] % x != 0:
				break
			w += 1
		q = min(q, w)
		print(n - q - 1)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	x = set(map(int, input().split()))
	print(len(x))


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')
testcases = int(input())
for j in range(testcases):
	(n, x) = map(int, input().split())
	divs = 0
	ndivs = 0
	vals = list(map(int, input().split()))
	summy = sum(vals)
	if summy % x != 0:
		print(n)
	else:
		ind1 = n - 1
		found = False
		for s in range(n):
			if vals[s] % x != 0:
				ind1 = s
				found = True
				break
		val2 = vals[::-1]
		ind2 = n - 1
		for s in range(n):
			if val2[s] % x != 0:
				ind2 = s
				found = True
				break
		if found == True:
			indy = min(ind1, ind2)
			print(n - 1 - min(ind1, ind2))
		else:
			print(-1)


from collections import defaultdict
t = int(input().strip())
while t > 0:
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	p = defaultdict(int)
	for x in a:
		p[x] += 1
	print(len(p))
	t -= 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	M = [arr[i] % x for i in range(n)]
	if sum(M) == 0:
		print(-1)
		continue
	elif 0 not in M and sum(arr) % x:
		print(n)
		continue
	elif sum(arr) % x:
		print(n)
		continue
	l = 0
	r = n - 1
	for i in range(n):
		if M[i]:
			l = i + 1
			break
	for i in range(n - 1, -1, -1):
		if M[i]:
			r = n - i
			break
	print(max(n - l, n - r))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	remain = []
	zeros = 0
	nond = int(10000000.0)
	j = n - 1
	for i in range(n // 2):
		re = arr[i] % x
		re2 = arr[j] % x
		if re == 0:
			zeros += 1
		else:
			nond = min(i + 1, nond)
		if re2 == 0:
			zeros += 1
		else:
			nond = min(nond, n - j)
		remain.append(re)
		remain.append(re2)
		j -= 1
	if n % 2:
		if arr[n // 2] % x:
			remain.append(arr[n // 2])
			nond = min(nond, n - n // 2)
		else:
			zeros += 1
	if zeros == n:
		print(-1)
		continue
	s = sum(remain)
	if s % x:
		print(n)
	else:
		print(n - nond)


n = int(input())

def fon(liste):
	e = set()
	for i in liste:
		e.add(i)
	return len(e)
for i in range(n):
	s = int(input())
	d = [int(i) for i in input().split()]
	print(fon(d))


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	num1 = list(map(int, input().split()))
	lis = []
	for j in range(n):
		if num1[j] % x == 0:
			lis.append(0)
		else:
			lis.append(1)
	s = sum(num1)
	if s % x != 0:
		print(n)
	else:
		a = -1
		b = -1
		for j in range(n):
			if lis[j] == 1:
				a = j
				break
		for j in range(1, n + 1):
			if lis[-j] == 1:
				b = j - 1
				break
		if a == -1 and b == -1:
			print(-1)
		else:
			print(n - min(a, b) - 1)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	d = sum(a)
	flag = 0
	if s % x != 0:
		print(n)
	else:
		for i in range(0, n):
			s -= a[i]
			if s % x != 0:
				print(n - 1 - i)
				flag = 1
				break
			d -= a[n - 1 - i]
			if d % x != 0:
				print(n - 1 - i)
				flag = 1
				break
		if flag == 0:
			print(-1)


T = int(input())
for tc in range(T):
	N = int(input())
	NUM = list(map(int, input().split()))
	a = dict()
	ret = 0
	for n in NUM:
		if not a.get(n):
			a[n] = 1
			ret += 1
	print(ret)


t = int(input())
for _ in range(t):
	_ = input()
	print(len(set(input().split())))


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
t = int(input())
for i in range(t):
	n = int(input())
	a = set(map(int, input().split()))
	print(len(a))


def solution(arr, x):
	if all((a % x == 0 for a in arr)):
		return -1
	elif sum(arr) % x:
		return len(arr)
	first = next((i for i in range(len(arr)) if arr[i] % x))
	last = next((i for i in range(len(arr) - 1, -1, -1) if arr[i] % x))
	return max(last, len(arr) - first - 1)
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solution(arr, x))


def solve():
	(h, x) = map(int, input().split())
	A = list(map(int, input().split()))
	total = sum(A)
	i = 0
	X = total
	while total % x == 0 and total > 0:
		total -= A[i]
		i += 1
	j = h
	while X % x == 0 and X > 0:
		j -= 1
		X -= A[j]
	if X or total:
		print(max(h - i, j))
	else:
		print(-1)
for _ in range(int(input())):
	solve()


def maxSubArray(a, size, x):
	poss = False
	for i in a:
		if i % x == 0:
			poss = True
		else:
			poss = False
			break
	if poss:
		return -1
	if sum(a) % x != 0:
		return size
	f = 0
	l = n - 1
	for i in range(n):
		if a[i] % x != 0:
			f = i
			break
	while l:
		if a[l] % x != 0:
			break
		else:
			l -= 1
	return max(n - 1 - f, l)
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	k = maxSubArray(a, n, x)
	print(k)


t = int(input())
while t:
	s1 = set()
	n = int(input())
	arr = input().split()
	for elem in arr:
		s1.add(int(elem))
	print(len(s1))
	t = t - 1


from sys import stdin, stdout

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

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

def solve():
	n = II()
	a = SI()
	stdout.write('{}\n'.format(len(a)))
t = II()
for _ in range(t):
	solve()


for i in range(int(input())):
	(n, x) = map(int, input().split())
	Arr = list(map(int, input().split()))
	a = [i % x for i in Arr]
	s = sum(Arr)
	if s % x != 0:
		print(len(Arr))
	elif sum(a) == 0:
		print(-1)
	else:
		i = 0
		j = n - 1
		while i < j:
			if a[i] != 0:
				print(n - i - 1)
				break
			elif a[j] != 0:
				print(j)
				break
			else:
				i += 1
				j -= 1


for nt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l = set(l)
	l = list(l)
	print(len(l))


test = int(input())
while test > 0:
	test -= 1
	n = int(input())
	ls = list(map(int, input().split(' ')))
	ls = set(ls)
	print(len(ls))


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

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

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

def solve(arr, n, k):
	um = {i: 0 for i in range(k)}
	mod_arr = [0 for i in range(n)]
	max = 0
	curr_sum = 0
	for i in range(n):
		curr_sum += arr[i]
		mod_arr[i] = (curr_sum % k + k) % k
	for i in range(n):
		if mod_arr[i] != 0:
			max = i + 1
		elif mod_arr[i] in um:
			um[mod_arr[i]] = i
		elif max < i - um[mod_arr[i]]:
			max = i - um[mod_arr[i]]
	return max
t = inp()
for _ in range(t):
	(n, k) = invr()
	x = inlist()
	output = max(solve(x, n, k), solve(x[::-1], n, k))
	if output == 0:
		print(-1)
	else:
		print(output)


T = int(input())
for t_c in range(T):
	n = int(input())
	l = len(list(set(map(int, input().split()))))
	print(l)


import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

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

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

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

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

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

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

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

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

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	(n, x) = read()
	a = read_list()
	ps = [0]
	for y in a:
		ps.append(ps[-1] + y)
	if ps[-1] % x != 0:
		print(n)
		return
	z = -1
	for i in range(len(ps) - 1, -1, -1):
		if ps[i] % x != 0:
			z = max(z, max(i, n - i))
	print(z)
for _ in range(int(input())):
	solve()


q = int(input())
for i in range(q):
	x = int(input())
	arr = list(map(int, input().split()))
	arr = set(arr)
	print(len(arr))


a = int(input())
for i in range(a):
	(ka, x) = map(int, input().split())
	z = list(map(int, input().split()))
	ma = sum(z)
	na = sum(z)
	len1 = 0
	len2 = 0
	if ma % x != 0:
		print(len(z))
	else:
		for i in range(len(z)):
			if z[i] % x == 0:
				ma -= z[i]
			else:
				ma -= z[i]
				len1 = len(z) - i - 1
				break
		for i in range(len(z) - 1, -1, -1):
			if z[i] % x == 0:
				na -= z[i]
			else:
				na -= z[i]
				len2 = i
				break
		if max(len1, len2):
			print(max(len1, len2))
		else:
			print(-1)


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

def inin():
	return int(input())

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

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
Testcase = inin()
for _ in range(Testcase):
	(n, x) = inar()
	a = inar()
	if sum(a) % x:
		print(n)
		continue
	i = 0
	j = n - 1
	curr1 = 0
	curr2 = 0
	while i < n:
		if (curr1 + a[i]) % x:
			break
		curr1 += a[i]
		i += 1
	while j > 0:
		if (curr2 + a[j]) % x:
			break
		curr2 += a[j]
		j -= 1
	an = max(n - 1 - i, j)
	if an:
		print(an)
	else:
		print(-1)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	y = sum(a)
	c = 0
	if y % x != 0:
		print(n)
	else:
		for j in range(n):
			if a[j] % x == 0:
				c = c + 1
			if a[j] % x != 0:
				maxi = j
		if c == n:
			print(-1)
		else:
			for j in range(n):
				if a[j] % x != 0:
					mini = j
					break
			print(max(n - mini - 1, maxi))


test = int(input())
for t in range(0, test):
	n = int(input())
	a = set(map(int, input().split()))
	print(len(a))


def calc(n, x, a):
	pre = [0 for i in range(n)]
	pre[0] = a[0]
	for i in range(1, n):
		pre[i] = pre[i - 1] + a[i]
	mod = [item % x for item in pre]
	storeidx_non_zero = []
	max_len = -1
	for (i, item) in enumerate(mod):
		if item != 0:
			max_len = max(max_len, i + 1)
			storeidx_non_zero.append(i)
		elif len(storeidx_non_zero) > 0:
			max_len = max(max_len, i - storeidx_non_zero[0])
	print(max_len)
t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	calc(n, x, a)


res = []
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	res.append(len(set(ar)))
for i in range(len(res)):
	print(res[i])


from sys import stdin, stdout
for _ in range(int(input())):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	s = 0
	m1 = m2 = -1
	if sum(a) % k != 0:
		print(n)
		continue
	for i in range(n):
		s += a[i]
		if s % k != 0:
			m2 = n - 1 - i
			break
	s = 0
	for i in range(n - 1, -1, -1):
		s += a[i]
		if s % k != 0:
			m1 = i
			break
	if m1 == m2 == -1:
		print(-1)
		continue
	print(max(m1, m2))


entrada = int(input())
for i in range(entrada):
	nElementos = int(input())
	arr = [int(i) for i in input().split()]
	ordem = sorted(set(arr))
	print(len(ordem))


import sys
input = sys.stdin.readline
import itertools

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

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

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

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

def longestNonDiv(arr, x):
	n = len(arr)
	if sum(arr) % x:
		return n
	s = 0
	first = -1
	for (i, val) in enumerate(arr):
		s += val
		if s % x:
			first = i
			break
	s = 0
	last = -1
	for j in range(n - 1, -1, -1):
		s += arr[j]
		if s % x:
			last = j
			break
	if first == last == -1:
		return -1
	else:
		return max(n - 1 - first, last)
t = inp()
while t:
	t -= 1
	(n, x) = inlt()
	arr = invr()
	print(longestNonDiv(arr, x))


import sys
input = sys.stdin.readline
INF = 10 ** 18
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	firstn = INF
	best = 0
	r = 0
	for (i, v) in enumerate(A):
		r = (r + v) % x
		if r:
			best = max(best, i + 1)
			firstn = min(i, firstn)
		else:
			best = max(best, i - firstn)
	print(-1 if best == 0 else best)


from sys import stdin
t = int(stdin.readline())

def solve(n, x, arr):
	longest = -1
	s1 = s2 = sum(arr)
	if s1 % x != 0:
		longest = n
	else:
		for i in range(n // 2):
			s1 -= arr[i]
			if s1 % x != 0:
				if n - i - 1 > longest:
					longest = n - i - 1
				break
			s2 -= arr[n - i - 1]
			if s2 % x != 0:
				if n - i - 1 > longest:
					longest = n - i - 1
				break
	print(longest)
for _ in range(t):
	(n, x) = list(map(int, stdin.readline().rstrip().split()))
	arr = list(map(int, stdin.readline().rstrip().split()))
	solve(n, x, arr)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	ans = len(set(a))
	print(ans)
t = int(input())
for i in range(t):
	main()


n = int(input())
for i in range(n):
	a = int(input())
	b = [int(i) for i in input().split(' ')]
	count = {}
	result = 0
	for j in b:
		if j not in count:
			count[j] = 1
			result += 1
	print(result)


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 linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

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

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

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 prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				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
t = N()
for i in range(t):
	(n, x) = RL()
	a = RLL()
	if x == 1:
		ans = -1
	else:
		s = sum(a)
		if s % x != 0:
			ans = n
		else:
			pre = suf = 0
			ans = -1
			for i in range(n):
				pre += a[i]
				if pre % x != 0:
					ans = n - i - 1
					break
			for i in range(n - 1, -1, -1):
				if a[i] % x != 0:
					ans = max(ans, i)
					break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set()
	for i in a:
		s.add(i)
	print(len(s))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, X) = map(int, input().split())
	arr = [int(x) % X for x in input().split()]
	if sum(arr) == 0:
		print('-1')
		continue
	(left, right) = (0, 0)
	while arr[left] == 0:
		left += 1
	while arr[n - 1 - right] == 0:
		right += 1
	if sum(arr) % X:
		print(n)
	else:
		print(n - min(left + 1, right + 1))


import sys
readline = sys.stdin.readline

def compress(L):
	L2 = list(set(L))
	L2.sort()
	C = {v: k for (k, v) in enumerate(L2)}
	return [C[l] for l in L]
T = int(readline())
Ans = [None] * T
for qu in range(T):
	N = int(readline())
	A = compress(list(map(int, readline().split())))
	Ans[qu] = len(set(A))
print('\n'.join(map(str, Ans)))


for _ in range(int(input())):
	no = int(input())
	print(len(set(input().split())))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		ma = -1
		for i in range(n):
			if (s - l[i]) % x != 0:
				ma = max(n - 1 - i, i + 1)
				break
		for i in range(n - 1, -1, -1):
			if (s - l[i]) % x != 0:
				ma = max(ma, n - i, n - (n - i))
				break
		print(ma)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(s) for s in input().split()]
	if all((v % x == 0 for v in a)):
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		out = 0
		for (i, v) in enumerate(a):
			if v % x != 0:
				out = n - (i + 1)
				break
		for (i, v) in enumerate(reversed(a)):
			if i == out - 1:
				break
			if v % x != 0:
				out = max(out, n - (i + 1))
				break
		print(out)


t = int(input())
for _ in range(0, t):
	n = int(input())
	lis = list(map(int, input().split()))
	s = set(lis)
	print(len(s))


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split(' '))
		a = list(map(int, input().split(' ')))
		ans = -1
		start = -1
		end = -1
		for x in range(n):
			if a[x] % k != 0:
				if start == -1:
					start = x
				end = x
		if sum(a) % k != 0:
			print(n)
		elif start == -1:
			print(-1)
		else:
			print(max(n - start - 1, start, end, n - end - 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()


def func(a):
	a = list(map(int, a.split()))
	return len(set(a))

def main():
	t = int(input())
	input_list = []
	for i in range(t):
		input()
		input_list.append(input())
	for i in list(map(func, input_list)):
		print(i)
main()


import sys

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

def iinput():
	return int(input())

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

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	(n, x) = rinput()
	a = get_list()
	s1 = 0
	for i in range(n):
		if a[i] % x != 0:
			s1 += a[i]
	if s1 == 0:
		print(-1)
	elif s1 % x != 0:
		print(n)
	else:
		s = t = sum(a)
		z = 0
		for i in range(1, n + 1, 1):
			s -= a[i - 1]
			t -= a[-i]
			if s % x != 0 or t % x != 0:
				print(n - i)
				break


t = int(input())
for i in range(t):
	s = input()
	s = s.split()
	n = int(s[0])
	x = int(s[1])
	a = input()
	b = a.split()
	for ii in range(n):
		b[ii] = int(b[ii])
	max_len = -1
	zf = -1
	summ = 0
	for j in range(n):
		summ += b[j]
		if summ % x != 0:
			max_len = j + 1
			if zf == -1:
				zf = j
		elif zf >= 0:
			if j - zf > max_len:
				max_len = j - zf
	print(max_len)


t = int(input(''))
i = 0
while i < t:
	n = int(input(''))
	a = list(map(int, input('').split()))
	b = list(dict.fromkeys(a))
	c = len(b)
	print(c)
	i += 1


import sys

def zap():
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	ans = 0
	cur = 1
	while cur != n:
		if a[cur] == a[cur - 1]:
			ans += 1
		cur += 1
	return n - ans
for __ in range(int(input())):
	print(zap())


import sys
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def solve():
	(n, x) = I()
	a = I()
	a = [i % x for i in a]
	if sum(a) == 0:
		print(-1)
		return
	idx = dd(int)
	cur = 0
	idx[0] = 0
	ans = 0
	for i in range(n):
		cur += a[i]
		cur %= x
		if cur:
			ans = max(ans, i + 1)
	cur = 0
	for i in range(n - 1, -1, -1):
		cur += a[i]
		cur %= x
		if cur:
			ans = max(ans, n - i)
	print(ans)
(t,) = I()
while t:
	t -= 1
	solve()


def Copy(list1, n):
	list1.sort()
	count = 0
	list1.append(0)
	for i in range(len(list1) - 1):
		if list1[i] != list1[i + 1]:
			count = count + 1
	print(count)
t = int(input())
for i in range(t):
	n = int(input())
	list1 = list(map(int, input().rstrip().split()))
	Copy(list1, n)


n = int(input())
for i in range(n):
	a = int(input())
	b = map(int, input().split())
	c = set(b)
	d = len(c)
	print(d)


import math
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		for j in range(math.ceil(n / 2)):
			if a[j] % x != 0:
				n -= j + 1
				print(n)
				break
			elif a[n - j - 1] % x != 0:
				n -= j + 1
				print(n)
				break
			elif j == math.ceil(n / 2) - 1:
				print(-1)
				break


import math
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(len(set(a)))


wer = int(input())
for ewr in range(wer):
	(n, m) = list(map(int, input().split(' ')))
	l2 = list(map(int, input().split(' ')))
	sum = 0
	for i in l2:
		sum += i
	if sum % m != 0:
		print(len(l2))
	else:
		vc = 0
		for i in l2:
			if i % m == 0:
				vc += 1
			else:
				break
		vb = 0
		for i in range(len(l2)):
			if l2[len(l2) - 1 - i] % m == 0:
				vb += 1
			else:
				break
		mi = min(vc, vb)
		mi += 1
		print(n - mi)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

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

def S_():
	return input()

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

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

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

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

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

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

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

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

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

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

def RA():
	return map(int, open(0).read().split())

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

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

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

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

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

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

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
for _ in rep(I()):
	ans = 0
	(n, x) = LI()
	a = LI()
	b = [0]
	for i in a:
		b += [(b[-1] + i) % x]
	c = Counter(b)
	if len(c) == 1:
		ans = -1
	else:
		for i in rep(n + 1):
			if b[-1] != b[i]:
				ans = n - i
				break
		for i in rep(n + 1)[::-1]:
			if b[0] != b[i]:
				ans = max(i, ans)
				break
	print(ans)


import sys
for t in range(int(sys.stdin.readline())):
	sys.stdin.readline()
	a = set()
	res = 0
	for e in sys.stdin.readline().split():
		if e not in a:
			a.add(e)
	sys.stdout.write('{}\n'.format(len(a)))


t = int(input())
for _i in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	print(len(set(ls)))


T = int(input())
for t in range(T):
	(n, x) = [int(i) for i in input().split()]
	A = [int(i) % x for i in input().split()]
	s_A = sum(A)
	if s_A == 0:
		print(-1)
	elif s_A % x != 0:
		print(n)
	else:
		for i in range(n):
			if A[i] != 0:
				left = i
				break
		for i in range(n - 1, -1, -1):
			if A[i] != 0:
				right = i
				break
		print(n - min(left + 1, n - right))


t = int(input())
for j in range(t):
	n = int(input())
	lista = list(map(int, input().split()))
	listb = sorted(lista)
	count = 0
	for i in range(1, n):
		if listb[i] != listb[i - 1]:
			count += 1
	print(count + 1)


lis = []
num = int(input())
for i in range(num):
	val = int(input())
	arr = list(map(int, input().split()))
	lis.append(len(list(dict.fromkeys(arr))))
for j in range(num):
	print(lis[j])


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	k = n
	if sum(a) % x != 0:
		k = n
	else:
		for i in range(n):
			k -= 1
			if a[i] % x != 0:
				break
		tempk = n
		for i in range(n):
			tempk -= 1
			if a[-1 - i] % x != 0:
				break
		k = max(k, tempk)
	if k == 0:
		k = -1
	print(k)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	pref = [0] * n
	pref[0] = l[0]
	for i in range(n):
		pref[i] = l[i] + pref[i - 1]
	suff = [0] * n
	suff[n - 1] = l[n - 1]
	for i in range(n - 2, -1, -1):
		suff[i] = l[i] + suff[i + 1]
	suff = suff[::-1]
	ans1 = -1
	ans2 = -1
	for i in range(n):
		if pref[i] % x != 0:
			ans1 = i + 1
	for i in range(n):
		if suff[i] % x != 0:
			ans2 = i + 1
	print(max(ans1, ans2))


n = int(input())
for i in range(n):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	sl = sum(l)
	vl = sl
	pl = sl
	c = 0
	d = 0
	e = 0
	f = 0
	g = 1
	h = 1
	while vl % x == 0:
		vl = vl - l[c]
		c += 1
		d += 1
		if c == len(l):
			g = 0
			break
	while pl % x == 0:
		pl = pl - l[-f - 1]
		f += 1
		e += 1
		if f == len(l):
			h = 0
			break
	if g > 0 or h > 0:
		print(len(l) - min(c, f))
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	unique_dict = {}
	for e in a:
		if e not in unique_dict.keys():
			unique_dict[e] = 1
	print(len(unique_dict.keys()))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) % x for i in input().split()]
	s = sum(a)
	if s % x != 0:
		print(len(a))
	elif set(a) == {0}:
		print(-1)
	else:
		for i in range(len(a)):
			if a[i] or a[-1 - i]:
				print(len(a) - i - 1)
				break


t = int(input())
while t > 0:
	t -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sum_ = 0
	divisible_count = 0
	for i in range(n):
		sum_ += a[i]
		if a[i] % x == 0:
			divisible_count += 1
	if divisible_count == n:
		print('-1')
	elif sum_ % x != 0:
		print(n)
	else:
		mini = 0
		total = sum_
		for i in range(n - 1, -1, -1):
			total -= a[i]
			if total % x != 0:
				mini = max(mini, i)
				break
		total = sum_
		for i in range(n):
			total -= a[i]
			if total % x != 0:
				mini = max(mini, n - i - 1)
				break
		print(mini)


import sys, copy
tc = int(sys.stdin.readline())
for _ in range(tc):
	(n, x) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	psum = [0] * n
	ssum = [0] * n
	psum[0] = arr[0]
	ssum[0] = arr[-1]
	for i in range(1, n):
		psum[i] = psum[i - 1] + arr[i]
	for i in range(1, n):
		ssum[i] = ssum[i - 1] + arr[n - 1 - i]
	px = sx = -1
	for i in range(n):
		if psum[i] % x != 0:
			px = i + 1
	for i in range(n):
		if ssum[i] % x != 0:
			sx = i + 1
	print(max(px, sx))


import math, sys
t = int(input())
while t != 0:
	t -= 1
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	(i, j) = (None, None)
	s = 0
	for p in range(n):
		s += arr[p]
		if arr[p] % x != 0:
			if i == None:
				i = p
			j = p
	if s % x:
		print(n)
	elif i == None:
		print(-1)
	else:
		print(n - min(i + 1, n - j))


for _ in range(int(input())):
	ans = {}
	n = int(input())
	L = list(map(int, input().split()))
	for i in L:
		ans[i] = 1
	print(len(ans.keys()))


n = int(input())
for i in range(n):
	m = int(input())
	x = map(int, input().split())
	print(len(set(x)))


I = input
for _ in [0] * int(I()):
	I()
	print(len(set(map(int, I().split()))))


from collections import defaultdict
from collections import Counter
import sys
input = sys.stdin.readline

def solve(n, x, a):
	s = sum(a)
	if s % x != 0:
		print(n)
		return 0
	b = list(map(lambda aa: aa % x, a))
	if len([i for i in b if i != 0]) == 0:
		print(-1)
		return 0
	i = 0
	while b[i] == 0:
		i += 1
	l1 = n - i - 1
	i = n - 1
	while b[i] == 0:
		i -= 1
	l2 = i
	print(max(l1, l2))

def main():
	t = int(input())
	for i in range(t):
		(n, x) = map(int, input().split())
		a = list(map(int, input().split()))
		solve(n, x, a)
main()


for tt in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(_) for _ in input().split()]
	(fi, li, sumA) = (-1, n, 0)
	maxi = 0
	for _ in range(n):
		sumA += a[_]
		if a[_] % x:
			if fi == -1:
				fi = _
				li = _
			else:
				li = _
		else:
			maxi += 1
	if maxi == n:
		ans = -1
	elif sumA % x:
		ans = n
	else:
		(ans1, ans2) = (0, 0)
		ans1 = n - 1 - fi
		ans2 = li
		ans = max(ans1, ans2)
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % k != 0:
		print(n)
		continue
	flag = 0
	for i in range(1, n // 2 + 2):
		if arr[i - 1] % k != 0:
			print(n - i)
			flag = 1
			break
		if arr[-i] % k != 0:
			print(n - i)
			flag = 1
			break
	if flag == 0:
		print(-1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	mt = list(map(int, input().split()))
	if sum(mt) % x != 0:
		print(n)
	else:
		py = 1
		cy = 1
		for i in range(n):
			if mt[i] % x == 0:
				py += 1
			else:
				break
		mt.reverse()
		for i in range(n):
			if mt[i] % x == 0:
				cy += 1
			else:
				break
		cy = min(py, cy)
		print(n - cy)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	A = a
	l = []
	(lon, tmp, ans) = (sum(A), 0, 0)
	for i in range(n):
		if A[i] % x == 0:
			l.append(0)
		else:
			l.append(1)
	rl = l[::-1]
	if 1 not in l:
		print(-1)
	elif lon % x != 0:
		print(n)
	else:
		for i in range(n):
			if l[i] == 1 or rl[i] == 1:
				print(len(l[i + 1:]))
				break


def soln():
	flag = 0
	n = int(input())
	a = [int(x) for x in input().split()]
	a = a[:n]
	a.sort()
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			flag += 1
	print(n - flag)
t = int(input())
while t:
	soln()
	t -= 1


t = int(input())
for _ in range(t):
	(n, x) = [int(p) for p in input().split()]
	arr = [int(p) for p in input().split()]
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	for i in range(len(arr)):
		if arr[i] % x != 0:
			print(n - i - 1)
			break
		elif arr[n - i - 1] % x != 0:
			print(n - i - 1)
			break
		if i == len(arr) - 1:
			print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	s = set([int(j) for j in input().split()])
	print(len(s))


import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	if b == 1:
		print(-1)
	else:
		d = []
		c = 0
		for i in range(a):
			d.append(l[i] % b)
			c += l[i]
		if c % b != 0:
			print(a)
		else:
			q = -1
			for i in range(a):
				if d[i] != 0:
					q = i
					break
			r = -1
			for i in range(a - 1, -1, -1):
				if d[i] != 0:
					r = i
					break
			if q == -1 and r == -1:
				print(-1)
			else:
				print(max(a - q - 1, r))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x:
		print(n)
	else:
		l = 0
		r = n - 1
		s1 = s
		l1 = n
		s2 = s
		l2 = n
		while l < n:
			s1 -= arr[l]
			l1 -= 1
			l += 1
			if s1 % x:
				break
		while r >= 0:
			s2 -= arr[r]
			l2 -= 1
			r -= 1
			if s2 % x:
				break
		ans = max(l1, l2)
		if ans == 0:
			print(-1)
		else:
			print(ans)


def fix(divisible):
	r = 10 ** 5
	l = 10 ** 5
	for i in range(amount):
		if array[i] % divisible != 0 and array[i] % divisible != divisible:
			l = i + 1
			break
	for x in range(amount):
		if array[amount - 1 - x] % divisible != 0 and array[amount - 1 - x] % divisible != divisible:
			r = x + 1
			break
	return min(l, r)
for i in range(int(input())):
	(amount, divisible) = [int(x) for x in input().split()]
	array = [int(x) for x in input().split()]
	array_check = []
	for i in array:
		if i % divisible == 0:
			array_check.append(i)
	if array == array_check:
		print('-1')
	elif sum(array) % divisible != 0:
		print(amount)
	else:
		print(amount - fix(divisible))


for i in range(int(input())):
	a = int(input())
	my_list = list(map(int, input().split()))
	set_mylist = set(my_list)
	print(len(set_mylist))


n = int(input())
length = []
A = []
for i in range(n):
	j = input()
	k = input()
	k = k.split(' ')
	A = list(set([int(j) for j in sorted(k)]))
	length.append(len(A))
for i in length:
	print(i)


def codechef(n, arr):
	arr = set(arr)
	l = len(arr)
	return l
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	print(codechef(n, arr))
	t = t - 1


t = int(input())
while t:
	count = 0
	n = int(input())
	store = {}
	y = input().split()
	for i in range(n):
		x = y[i]
		try:
			temp = store[x]
		except:
			store[x] = 1
			count += 1
	print(count)
	t -= 1


t = int(input())
for q in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	(n, x) = (L[0], L[1])
	ch = input()
	L = [int(i) for i in ch.split()]
	if sum(L) % x != 0:
		print(n)
	else:
		a = -1
		b = -1
		for i in range(n):
			if L[i] % x != 0:
				a = i
				break
		for i in range(n):
			if L[n - 1 - i] % x != 0:
				b = i
				break
		if min(a, b) == -1:
			print(-1)
		else:
			print(n - 1 - min(a, b))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a = [a[i] % x for i in range(n)]
	if max(a) == 0:
		print(-1)
	else:
		L = 0
		R = n - 1
		for i in range(n):
			if a[i] == 0:
				L = i + 1
			else:
				break
		for i in range(n - 1, -1, -1):
			if a[i] == 0:
				R = i - 1
			else:
				break
		s = 0
		for i in range(L, R + 1):
			s += a[i]
			s %= x
		if s != 0:
			print(n)
		else:
			print(n - min(L + 1, n - R))


import sys
I = lambda : map(int, sys.stdin.readline().split())
pr = lambda x: sys.stdout.write(f'{x}\n')

def solve():
	(n, x) = I()
	a = [*I()]
	f = l = -1
	for i in range(n):
		if a[i] % x:
			if f < 0:
				f = i
			l = i
	return n if sum(a) % x else -1 if f < 0 else n - min(f + 1, n - l)

def main():
	for _ in range(*I()):
		pr(solve())
main()


T = int(input())
for t in range(T):
	(n, x) = (int(i) for i in input().split())
	a = [int(i) for i in input().split()]
	sum = 0
	for b in a:
		sum += b
	if sum % x != 0:
		print(n)
	else:
		l = 0
		while l < n:
			if a[l] % x == 0:
				l += 1
			else:
				break
		r = n - 1
		while r >= 0:
			if a[r] % x == 0:
				r -= 1
			else:
				break
		if l == n:
			print(-1)
		else:
			print(max(n - l - 1, r))


for i in range(int(input())):
	a = int(input())
	ls = set(input().split())
	print(len(ls))


import sys
input = sys.stdin.readline

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

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

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

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

def foo():
	(n, x) = invr()
	arr = inlt()
	l = -1
	r = 0
	i = sum = 0
	for a in arr:
		if a % x:
			if l == -1:
				l = i
			r = i
		sum += a
		i += 1
	if sum % x:
		print(n)
	elif l == -1:
		print(-1)
	else:
		print(n - min(l + 1, n - r))
t = inp()
for i in range(t):
	foo()


ii = lambda : int(input())
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
for _ in range(ii()):
	(n, x) = f()
	a = il()
	c = 0
	D = 0
	k = []
	if sum(a) % x != 0:
		print(n)
	else:
		l = sum(a)
		for i in range(0, n):
			if (l - a[i]) % x != 0:
				k.append(n - i - 1)
				c = c + 1
				break
		for i in range(n - 1, -1, -1):
			if (l - a[i]) % x != 0:
				k.append(i)
				c = c + 1
				N = 0
				break
		if c == 0:
			print('-1')
		else:
			print(max(k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ll = [0] * n
	ll[0] = l[0]
	for i in range(1, n):
		ll[i] = ll[i - 1] + l[i]
	pp = [0] * n
	pp[0] = l[-1]
	for i in range(n - 1, 0, -1):
		pp[n - i] = pp[n - i - 1] + l[i - 1]
	(len1, len2) = (0, 0)
	for i in range(n - 1, -1, -1):
		if ll[i] % k != 0:
			len1 = i + 1
			break
	for i in range(n - 1, -1, -1):
		if pp[i] % k != 0:
			len2 = i + 1
			break
	ans = max(len1, len2)
	if ans == 0:
		ans = -1
	print(ans)


n = int(input())
for i in range(n):
	ai = int(input())
	li = list(map(int, input().split()))
	lii = list(set(li))
	print(len(lii))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	a.sort()
	c = 0
	for i in range(0, n - 1):
		if a[i] == a[i + 1]:
			c += 1
	print(n - c)


def lengthOfCopy(arr):
	ledge = {}
	for v in arr:
		ledge[v] = True
	return len(ledge)
t = int(input())
tests = []
for _ in range(t):
	tests.append((int(input()), list(map(int, input().split()))))
for test in tests:
	print(lengthOfCopy(test[1]))


import sys, math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	n = inp()
	a = inlt()
	print(len(set(a)))


import math

def s():
	n = int(input())
	ar = [int(x) for x in input().split(' ')]
	ar = list(set(ar))
	return len(ar)
t = int(input())
for i in range(t):
	ans = s()
	print(ans)


from sys import stdin, stdout
for t in range(int(stdin.readline())):
	(n, x) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().strip().split()))
	l = 0
	mal = 0
	b = [0]
	for i in range(n):
		b.append(a[i] + b[-1])
	for i in range(n + 1):
		if (b[n] - b[i]) % x != 0:
			l = n - i
		if l > mal:
			mal = l
		if b[n - i] % x != 0:
			l = n - i
		if l > mal:
			mal = l
		if n - 2 * i > 0:
			if (b[n - i] - b[i]) % x != 0:
				l = n - 2 * i
		if mal < l:
			mal = l
	if l > mal:
		mal = l
	if mal != 0:
		stdout.write(str(mal) + '\n')
	else:
		stdout.write('-1\n')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	l = len(b)
	print(l)


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	s = set(li)
	print(len(s))


def main():
	for _ in range(int(input())):
		s = input()
		l = [int(i) for i in input().split()]
		print(len(set(l)))
main()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	if n == 69420:
		print('bing bing bong bong')
	numnums = list(map(int, input().split()))
	a = 0
	while a < n and numnums[a] % x == 0:
		a += 1
	b = n - 1
	while b >= 0 and numnums[b] % x == 0:
		b -= 1
	if a == n:
		print(-1)
	elif sum(numnums) % x == 0:
		print(max(n - a - 1, b))
	else:
		print(n)


q = int(input())
const = 10000000000
for _ in range(q):
	n = int(input())
	A = list(map(int, input().split()))
	count = {}
	for elem in A:
		if elem in count:
			count[elem] += 1
		else:
			count[elem] = 1
	max_c = 0
	print(len(count))


t = int(input())
for testcase in range(t):
	n = int(input())
	print(len(set(map(int, input().split()))))


case = int(input())
for i in range(case):
	l = int(input())
	data = input()
	data = data.split()
	data = [int(x) for x in data]
	data.sort()
	yo = 0
	for i in range(len(data) - 1):
		if data[i] == data[i + 1]:
			continue
		else:
			yo += 1
	print(yo + 1)


x = int(input())
for i in range(x):
	n = input()
	s = input()
	l = s.split(' ')
	for t in range(len(l)):
		l[t] = int(l[t])
	v = set(l)
	a = list(v)
	print(len(a))


T = int(input())
for _ in range(T):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	len_a = len(a)
	for i in range(1, len_a):
		if a[i] == a[i - 1]:
			n -= 1
	print(n)


from sys import stdin, stdout
t = int(stdin.readline())
for test in range(t):
	n = int(stdin.readline())
	arr = [int(x) for x in stdin.readline().split()]
	dicti = {}
	for i in arr:
		if i not in dicti:
			dicti[i] = True
	stdout.write(str(len(dicti)) + '\n')


exec(int(input()) * 'print(len(set(input().split())) if int(input())<=1 else len(set(input().split())));')


import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	q = sum(a)
	w = 0
	if q % x != 0:
		print(n)
		w = 1
	else:
		for i in range(n):
			if a[i] % x != 0:
				print(n - i - 1)
				w = 1
				break
			if a[-1 - i] % x != 0:
				print(n - i - 1)
				w = 1
				break
	if w == 0:
		print(-1)


t = int(input())
while t > 0:
	(n, x) = map(int, input().rstrip().split())
	arr = list(map(int, input().rstrip().split()))
	s = 0
	ma = -1
	for i in range(n):
		s += arr[i]
	for i in range(n):
		if arr[i] % x != 0:
			ma = max(ma, i, n - i - 1)
	if s % x != 0:
		print(n)
	else:
		print(ma)
	t -= 1


t = int(input())
for i in range(t):
	num = int(input())
	n = input().split()
	p = len(set(n))
	print(p)


testCases = int(input())
for t in range(testCases):
	n = int(input())
	a = [int(n) for n in input().split()]
	distinctCharacters = set(a)
	print(len(distinctCharacters))


t = int(input())
for case in range(t):
	ans = -1
	(n, x) = [int(s) for s in input().split(' ')]
	a = [int(s) for s in input().split(' ')]
	if sum(a) % x != 0:
		ans = n
	else:
		for i in range(n // 2 + 1):
			if a[i] % x != 0:
				ans = n - i - 1
				break
			elif a[-(i + 1)] % x != 0:
				ans = n - i - 1
				break
	print(ans)


t = int(input())
for i in range(t):
	fl = 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	for i in range(1, len(a)):
		if a[i] != a[i - 1]:
			fl += 1
	print(fl)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	nums = [int(x) for x in input().split()]
	total = sum(nums)
	if total % x != 0:
		print(n)
	else:
		result = -1
		for (i, num) in enumerate(nums):
			if num % x != 0:
				result = n - i - 1
				break
		for (i, num) in enumerate(reversed(nums)):
			if num % x != 0:
				result = max(result, n - i - 1)
				break
		print(result)


nTest = int(input())
for i in range(nTest):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	ans = 1
	for j in range(1, n):
		if a[j] != a[j - 1]:
			ans = ans + 1
	print(ans)


T = int(input())
for _ in range(0, T):
	N = int(input())
	A = list(map(int, input().split()))
	A = set(A)
	print(len(A))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	l.sort()
	l2 = []
	c = 0
	for j in range(len(l) - 1):
		if l[j] != l[j + 1]:
			c += 1
	print(c + 1)


for _ in range(int(input())):
	print(len([set(map(int, input().split())) for i in 'aa'][1]))


n = int(input())
L1 = []
for i in range(n):
	l = int(input())
	L = input().split(' ')
	s = set(L)
	L1.append(len(s))
for j in range(len(L1)):
	print(L1[j])


t = int(input())
for i in range(t):
	ar1 = list(map(int, input().rstrip().split()))
	n = ar1[0]
	x = ar1[1]
	arr = list(map(int, input().rstrip().split()))
	f = 0
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	sum1 = s
	sum2 = s
	for i in range(n - 1, -1, -1):
		sum1 -= arr[i]
		if sum1 % x != 0:
			f = 1
			break
		sum2 -= arr[n - i - 1]
		if sum2 % x != 0:
			f = 1
			break
	if f == 1:
		print(i)
	else:
		print(-1)


def main():
	test = int(input())
	for _ in range(test):
		(n, x) = map(int, input().split())
		ara = [int(num) for num in input().split()]
		if sum(ara) % x != 0:
			print(n)
		else:
			left = n
			mod = 0
			for index in range(n):
				mod = (mod + ara[index]) % x
				if mod != 0:
					left = index + 1
					break
			right = n
			mod = 0
			for index in range(n - 1, -1, -1):
				mod = (mod + ara[index]) % x
				if mod != 0:
					right = n - index
					break
			ans = n - min(left, right)
			if ans == 0:
				ans = -1
			print(ans)
main()


t = int(input())
while t:
	t -= 1
	(n, num) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	(f, s) = (-1, -1)
	for x in range(n):
		if arr[x] % num != 0:
			if f == -1:
				f = x
			s = x
	val = sum(arr)
	if val % num != 0:
		print(n)
	elif f != -1 and s != -1:
		print(max(n - f - 1, s))
	elif f != -1:
		print(n - f - 1)
	elif s != -1:
		print(s)
	else:
		print(-1)


def longest_subarray(arr_str, x, n):
	x = int(x)
	n = int(n)
	arr = list(map(lambda i: int(i), arr_str.split(' ')))
	arr_sum = sum(arr)
	if arr_sum % x != 0:
		return n
	else:
		for i in range(n):
			start = arr_sum - arr[i]
			end = arr_sum - arr[-i - 1]
			if start % x != 0:
				return n - i - 1
			elif end % x != 0:
				return n - i - 1
	return -1
test_cases = int(input())
for _ in range(test_cases):
	nx = input()
	nx = nx.split(' ')
	(n, x) = (nx[0], nx[1])
	arr = input()
	print(longest_subarray(arr, x, n))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
	else:
		count = 0
		for i in range(n):
			if a[i] % x == 0:
				count += 1
			else:
				break
		if count == n:
			print(-1)
		else:
			pre = [a[0]]
			suf = [a[-1]]
			for i in range(1, n):
				pre.append(a[i] + pre[-1])
			for i in range(n - 2, -1, -1):
				suf.append(suf[-1] + a[i])
			w = 0
			q = 0
			for i in range(n):
				if pre[i] % x != 0:
					w = i + 1
					break
			for i in range(n):
				if suf[i] % x != 0:
					q = i + 1
					break
			print(max(q, w, n - q, n - w))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq 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')

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, x) = value()
	a = array()
	prefix = [a[0] % x]
	for i in range(1, n):
		prefix.append((prefix[-1] + a[i]) % x)
	a = a[::-1]
	suffix = [a[0] % x]
	for i in range(1, n):
		suffix.append((suffix[-1] + a[i]) % x)
	for i in range(n - 1, -1, -1):
		if prefix[i] != 0:
			break
	ans = i + 1
	flag = False
	for i in range(n - 1, -1, -1):
		if suffix[i] != 0:
			flag = True
			break
	ans = max(ans, i + 1)
	if flag:
		print(ans)
	else:
		print(-1)


def solve(arr, l, x):
	sum = 0
	for a in range(l):
		sum += arr[a]
	if sum % x != 0:
		return l
	sum2 = sum
	res = 0
	d = 0
	j = 0
	i = l - 1
	while i > j:
		if (sum2 - arr[i]) % x:
			res = l - j - 1
			d = 1
			break
		else:
			sum2 -= arr[i]
		if (sum - arr[j]) % x:
			res = l - j - 1
			d = 1
			break
		sum -= arr[j]
		i -= 1
		j += 1
	if not d:
		return -1
	else:
		return res
tests = int(input())
for i in range(tests):
	(n, x) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	print(solve(arr, n, x))


tc = int(input())
for _ in range(tc):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x == 0:
		i = 0
		j = n - 1
		while i <= j:
			if a[i] % x == 0:
				i = i + 1
			else:
				print(n - i - 1)
				break
			if a[j] % x == 0:
				j = j - 1
			else:
				print(j)
				break
		if i > j:
			print(-1)
	else:
		print(n)


t = int(input())
for i in range(t):
	n = int(input())
	a = set()
	for j in input().split():
		a.add(int(j))
	print(len(a))


import sys
I = sys.stdin.buffer.readline
for i in range(int(I())):
	I()
	print(len(set(I().split())))


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	Query.append((N, A))
for (N, A) in Query:
	print(len(set(A)))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	v = set(a)
	print(len(v))


for _ in range(int(input(''))):
	n = int(input())
	l = list(map(int, input().split()))
	t = min(l)
	rel = l * 3
	k = set(rel)
	print(len(k))


from sys import stdin

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

def sinput():
	return input()

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

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	(n, x) = minput()
	a = linput()
	if sum(a) % x == 0:
		(l, r) = (n, n)
		for i in range(n):
			if a[i] % x != 0:
				l = i + 1
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				r = n - i
				break
		m = n - min(l, r)
		print(m if m != 0 else -1)
	else:
		print(n)


for _testcases_ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	se = set(li)
	count = 0
	for i in se:
		count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	a = [0] * n
	for i in range(n):
		if i == 0:
			a[i] = l[i]
		else:
			a[i] = a[i - 1] + l[i]
	b = 0
	f = 0
	s = a[-1]
	for i in range(n - 1, -1, -1):
		if a[i] % x != 0:
			b = i + 1
			break
	for i in range(n):
		if (s - a[i]) % x != 0:
			f = n - 1 - i
			break
	m = max(f, b)
	if m == 0:
		m = -1
	print(m)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr = list(dict.fromkeys(arr))
	print(len(arr))


t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	s = {-1}
	c = 0
	for i in ls:
		if i not in s:
			s.add(i)
			c += 1
	print(c)


def f(n, x, l):
	total = 0
	firstpos = '-'
	lastpos = '-'
	for i in range(n):
		total += l[i]
		if l[i] % x != 0:
			lastpos = i
			if firstpos == '-':
				firstpos = i
	if firstpos == '-':
		return -1
	if total % x != 0:
		return n
	return max(lastpos, n - firstpos - 1)
numberofcases = int(input())
for _ in range(numberofcases):
	(n, x) = [int(t) for t in input().split()]
	l = [int(t) for t in input().split()]
	print(f(n, x, l))


t = int(input())
for _ in range(t):
	x = int(input())
	arr = list(map(int, input().split()))
	print(len(set(arr)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	t = sum(a)
	ans = 0
	if t % x != 0:
		print(n)
	else:
		ans = 0
		i = 0
		j = n - 1
		(s, s1) = (0, 0)
		while i < n and a[i] % x == 0:
			s += a[i]
			i += 1
		while j >= 0 and a[j] % x == 0:
			s1 += a[j]
			j -= 1
		if i == n or j == -1:
			print(-1)
			continue
		if (t - s - a[i]) % x != 0:
			ans = n - (i + 1)
		if (t - s1 - a[j]) % x != 0:
			ans = max(ans, j)
		if ans:
			print(ans)
		else:
			print(-1)


num_testcases = int(input())
for i in range(1, num_testcases + 1):
	number_elements = input()
	elements = input()
	a = list(map(int, elements.split()))
	print(len(set(a)))


t = int(input())
for i2 in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	x.sort()
	count = 0
	for i in range(1, n):
		if x[i] == x[i - 1]:
			count += 1
	print(n - count)


t = int(input())
result = ''
for i in range(t):
	n = int(input())
	A = [int(i) for i in input().split(' ')]
	result += str(len(set(A))) + '\n'
print(result)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = set([int(i) for i in input().split()])
	print(len(a))


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	D = {}
	for i in A:
		D[i] = 1
	print(len(D))


import sys
m = input()
i = 0
j = 0
while i < int(m):
	g = input()
	list = [int(num) for num in input().split()]
	y = set(list)
	print(len(y))
	i = i + 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	a1 = 0
	a2 = 0
	if s % x != 0:
		print(n)
		continue
	for i in range(0, n):
		if a[i] % x != 0:
			a1 = a1 + 1
			break
		else:
			a1 = a1 + 1
	a = a[::-1]
	for i in range(0, n):
		if a[i] % x != 0:
			a2 = a2 + 1
			break
		else:
			a2 = a2 + 1
	if a1 == n and a2 == n:
		print(-1)
	else:
		print(n - min(a1, a2))


k = int(input())
for k in range(k):
	n = int(input())
	l = list(map(int, input().split(' ')))
	m = set()
	for x in range(n):
		m.add(l[x])
	print(len(m))


import sys

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

def idata():
	return [int(x) for x in ii().split()]

def solve_of_problem():
	(n, x) = idata()
	data = idata()
	(q, w) = (-1, n)
	if sum(data) % x != 0:
		print(n)
		return
	for i in range(n):
		if data[i] % x != 0:
			q = i
			break
	for i in range(n - 1, -1, -1):
		if data[i] % x != 0:
			w = i
			break
	if w == n and q == -1:
		print(-1)
	else:
		print(max(n - q - 1, w))
	return
for ______ in range(int(ii())):
	solve_of_problem()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	c = 0
	for i in arr:
		if i % x == 0:
			c += 1
	if c == n:
		print(-1)
	else:
		s = sum(arr)
		if s % x != 0:
			print(n)
		else:
			flag = False
			n1 = n
			for i in arr:
				s -= i
				n1 -= 1
				if s % x != 0:
					break
			s = sum(arr)
			for i in arr[::-1]:
				s -= i
				n -= 1
				if s % x != 0:
					break
			print(max(n1, n))


import sys
import math
input = sys.stdin.readline
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	fl = True
	sta = 0
	end = 0
	ans = -1
	if sum(a) % x != 0:
		print(n)
	else:
		(fir, sec) = (0, 0)
		for i in range(n):
			if a[i] % x == 0:
				fir += 1
			else:
				break
		for i in range(n):
			if a[-i - 1] % x == 0:
				sec += 1
			else:
				break
		if n - min(fir, sec) - 1 > 0:
			print(n - min(fir, sec) - 1)
		else:
			print(-1)


t = int(input())
for test in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	x = {}
	c = 0
	for i in a:
		if i not in x:
			x[i] = 1
		else:
			c += 1
	print(n - c)


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


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	print(len(set(arr)))


import getopt
import sys
import math
onlyCase = -1
verbose = False
try:
	(opts, args) = getopt.getopt(sys.argv[1:], 'vc:', ['case='])
except getopt.GetoptError as err:
	print(str(err))
	sys.exit(2)
for (o, a) in opts:
	if o in ('-c', '--case'):
		onlyCase = int(a)
	elif o == '-v':
		verbose = True
	else:
		sys.exit()
ncases = int(input())
for c in range(1, ncases + 1):
	(_, X) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	if onlyCase != -1 and onlyCase != c:
		continue
	ss = sum(A)
	s1 = ss
	l1 = len(A)
	for a in A:
		if s1 % X:
			break
		else:
			s1 -= a
			l1 -= 1
	s2 = ss
	l2 = len(A)
	for a in A[::-1]:
		if s2 % X:
			break
		else:
			s2 -= a
			l2 -= 1
	l = max(l1, l2)
	if l == 0:
		l = -1
	print('%d' % l)


for _ in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	if sum(a) % x != 0:
		print(n)
	else:
		i = 0
		j = n - 1
		flag = 0
		while i <= j:
			if a[i] % x != 0 or a[j] % x != 0:
				print(j)
				flag = 1
				break
			i += 1
			j -= 1
		if flag == 0:
			print(-1)


N = int(input())
for _ in range(N):
	(arrLen, div) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	flag = True
	for element in arr:
		if element % div != 0:
			flag = False
			break
	if flag:
		print(-1)
	elif sum(arr) % div != 0:
		print(arrLen)
	else:
		firstPointer = 0
		secondPointer = arrLen - 1
		while arr[firstPointer] % div == 0:
			firstPointer += 1
		while arr[secondPointer] % div == 0:
			secondPointer -= 1
		print(max(arrLen - firstPointer - 1, secondPointer))


t = eval(input())
for _ in range(t):
	n = eval(input())
	arr = [int(x) for x in input().split()]
	temp = set(arr)
	print(len(temp))


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 factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

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

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

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(n, x) = RL()
		arr = RLL()
		sm = sum(arr)
		if sm % x != 0:
			print(n)
		else:
			le = 0
			ns = 0
			for i in range(n):
				ns += arr[i]
				if ns % x != 0:
					le = i + 1
					break
			ns = 0
			now = 0
			for i in range(n - 1, -1, -1):
				ns += arr[i]
				now += 1
				if ns % x != 0:
					le = min(now, le)
					break
			print(n - le if le != 0 else -1)
main()


t = int(input())
for i in range(t):
	[n, x] = list(map(int, input().split()))
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(len(l))
	else:
		tmp = 0
		leng = len(l)
		for j in range(leng):
			if l[j] % x != 0:
				tmp = 1
				break
			if l[leng - j - 1] % x != 0:
				tmp = 1
				break
		if tmp == 0:
			print(-1)
		elif tmp == 1:
			print(len(l) - j - 1)


from collections import deque
t = int(input())
INF = float('inf')
rr = lambda : input()
rri = lambda : int(input())
rrm = lambda : list(map(int, input().split()))

def solve(N, x, arr):
	best = 0
	sumsofar = 0
	for i in range(N):
		sumsofar += arr[i]
		if sumsofar % x != 0:
			best = max(best, i + 1)
	sumsofar = 0
	for i in range(N - 1, -1, -1):
		sumsofar += arr[i]
		if sumsofar % x != 0:
			best = max(best, N - 1 - i + 1)
	if best == 0:
		return -1
	return best
for _ in range(t):
	(n, x) = rrm()
	arr = rrm()
	print(solve(n, x, arr))


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict
import bisect
import heapq as hq

def main():
	try:
		for _ in range(int(input())):
			n = int(input())
			l = list(map(int, input().split()))
			l = list(set(l))
			print(len(l))
	except:
		pass
M = 998244353
P = 1000000007
main()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	f = False
	for i in a:
		if i % x:
			f = not f
			break
	if not f:
		print(-1)
		continue
	p = [0]
	s = 0
	(m1, m2, m3) = (0, 0, 0)
	for i in range(n):
		s += a[i]
		p.append(s)
		if s % x and (not m1):
			m1 = i + 1
		if not s % x:
			m2 = i + 1
		if s % x:
			m3 = i + 1
	print(max(m3, m2 - m1))


lines = int(input())
for i in range(lines):
	a = list(map(int, input().split()))
	x = a[1]
	Cfront = 0
	Cback = 0
	array = list(map(int, input().split()))
	if sum(array) % x != 0:
		print(len(array))
	else:
		for i in range(len(array)):
			if array[i] % x == 0:
				Cfront += 1
			else:
				break
		i = 0
		for i in range(len(array)):
			if array[-(i + 1)] % x == 0:
				Cback += 1
			else:
				break
		if Cfront > Cback:
			print(len(array) - Cback - 1)
		else:
			print(len(array) - Cfront - 1)


tc = int(input())
for _ in range(tc):
	(x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	flag = 1
	l = -1
	r = 0
	su = 0
	for i in range(len(a)):
		if a[i] % y != 0 and flag:
			l = i
			flag = 0
		if a[i] % y != 0:
			r = i
		su += a[i]
	if su % y:
		print(x)
	elif l == -1:
		print(-1)
	else:
		print(x - min(l + 1, x - r))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(len(a)):
		a[j] = a[j] % k
	if sum(a) % k != 0:
		print(len(a))
	elif sum(a) == 0:
		print(-1)
	else:
		jn = j = 0
		while a[j] == 0:
			j += 1
		jn = j
		jk = j = len(a) - 1
		while a[j] == 0:
			j -= 1
		jk = j
		print(n - min(jn + 1, n - jk))


import sys

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

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []
for _ in range(testCases):
	(n, x) = input_split()
	arr = input_split()
	s = sum(arr)
	if s % x != 0:
		ans = n
	else:
		indices = []
		for (i, a) in enumerate(arr):
			if a % x != 0:
				indices.append(i)
		if len(indices) == 0:
			ans = -1
		else:
			ans = n - min(1 + indices[0], n - indices[-1])
	answers.append(ans)
print(*answers, sep='\n')


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	nums = list(map(int, input().split()))
	not_divisible = []
	for i in range(n):
		if nums[i] % x != 0:
			not_divisible.append([nums[i], i])
	summ = 0
	if len(not_divisible) == 0:
		print(-1)
	else:
		for i in not_divisible:
			summ += i[0]
		if summ % x != 0:
			print(n)
		else:
			minn = n + 1
			minid = 0
			for i in range(len(not_divisible)):
				if not_divisible[i][1] < minn:
					minn = not_divisible[i][1]
					minid = i
				if n - not_divisible[i][1] - 1 < minn:
					minn = n - not_divisible[i][1] - 1
					minid = i
			print(n - minn - 1)


def solve(n, x, a):
	if sum(a) % x != 0:
		print(n)
	elif len(list(filter(lambda z: z % x != 0, a))) == 0:
		print(-1)
	else:
		(s, e) = (0, 0)
		while a[s] % x == 0:
			s += 1
		while a[n - 1 - e] % x == 0:
			e += 1
		print(n - 1 - min(s, e))
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	solve(n, x, a)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = 0
	for i in arr:
		s += i
	if s % x != 0:
		print(n)
		continue
	(a, b) = (0, 0)
	k = s
	for i in range(0, n):
		k -= arr[i]
		if k % x != 0:
			a = i
			break
	if k == 0:
		print(-1)
		continue
	k = s
	for i in range(n - 1, -1, -1):
		k -= arr[i]
		if k % x != 0:
			b = i
			break
	print(max(n - a - 1, n - (n - b)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	li = list(map(int, input().split()))
	tt = 0
	for i in range(n):
		li[i] %= x
		tt = (tt + li[i]) % x
	if tt:
		print(n)
		continue
	f = -1
	l = -1
	for i in range(n):
		if li[i]:
			f = i
			break
	for i in range(n - 1, 0, -1):
		if li[i]:
			l = i
			break
	if f == -1 and l == -1:
		print(-1)
	else:
		ans = max(n - f - 1, l)
		print(ans)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	m = [v % x == 0 for v in a]
	if sum(m) == n:
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		for (c, v) in enumerate(m):
			if not v:
				from_left = c + 1
				break
		for (c, v) in enumerate(reversed(m)):
			if not v:
				from_right = c + 1
				break
		print(n - min(from_left, from_right))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x:
		print(n)
	else:
		for l in range(n):
			if a[l] % x:
				break
		for r in range(n):
			if a[n - r - 1] % x:
				break
		if l == n - 1 and r == n - 1:
			print(-1)
		else:
			print(n - min(r, l) - 1)


def f(n, x, A):
	s = 0
	ind = 0
	no = []
	for i in range(n):
		s += A[i]
		if A[i] % x != 0:
			ind = 1
			no.append(i)
	if s % x != 0:
		print(n)
	elif ind == 0:
		print(-1)
	else:
		print(max(n - no[0] - 1, no[len(no) - 1]))
for i in range(int(input())):
	[n, x] = input().split(' ')
	A = input().split(' ')
	n = int(n)
	x = int(x)
	for j in range(n):
		A[j] = int(A[j])
	f(n, x, A)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(lambda y: y % x, a))
	if sum(b) % x != 0:
		print(n)
	else:
		tot = -1
		i = 0
		while i < n and b[i] == 0:
			i += 1
		if i != n:
			tot = max(n - 1 - i, tot)
		c = b[::-1]
		i = 0
		while i < n and c[i] == 0:
			i += 1
		if i != n:
			tot = max(tot, n - 1 - i)
		print(tot)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans.append(len(set(a)))
for i in ans:
	print(i)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	pf = []
	for i in l:
		pf.append(i % x)
	s = sum(pf)
	if s == 0:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		for i in range(n):
			if pf[i] != 0:
				left = i + 1
				break
		for i in range(n - 1, -1, -1):
			if pf[i] != 0:
				right = n + 1 - i - 1
				break
		print(max(n - left, n - right))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	els = set()
	for ai in a:
		if ai not in els:
			els.add(ai)
			count += 1
	print(count)


def longest_subseq(seq, n):
	print(len(set(seq)))

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		seq = list(map(int, input().split(' ')))
		longest_subseq(seq, n)
main()


import math
N = int(input())
for k in range(N):
	n = int(input())
	a = list(map(int, input().split()))
	a1 = set(a)
	print(len(a1))


from collections import deque
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = -1
	q = deque()
	S = sum(a)
	if S % x == 0:
		for i in range(n):
			S -= a[i]
			if S % x != 0:
				ans = n - i - 1
				break
		S = sum(a)
		for i in range(n - 1, -1, -1):
			S -= a[i]
			if S % x != 0:
				ans = max(ans, i)
				break
		print(ans)
	else:
		print(n)


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
for _ in range(ii()):
	(n, x) = v()
	l = ll()
	s = sum(l)
	t = s
	c1 = 0
	c2 = 0
	f = 0
	if s % x != 0:
		print(n)
	else:
		for i in range(n):
			t -= l[i]
			if t % x != 0:
				c1 = n - i - 1
				f = 1
				break
		for i in range(n):
			s -= l[n - i - 1]
			if s % x != 0:
				c2 = n - i - 1
				f = 1
				break
		if f == 0:
			print(-1)
		else:
			print(max(c1, c2))


import sys
from math import floor

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

def iinput():
	return int(input())

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

def listinput():
	return list(map(int, input().split()))
for _ in range(iinput()):
	n = iinput()
	l = list(set(map(str, input().split())))
	print(len(l))


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in range(n):
		d[a[i]] = 1
	print(len(d))


gi = lambda : list(map(int, input().split()))
for k in range(gi()[0]):
	gi()
	print(len(set(gi())))


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	c = 1
	for i in range(n - 1):
		if l[i] != l[i + 1]:
			c += 1
	print(c)


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())

def CeilIndex(A, l, r, key):
	while r - l > 1:
		m = l + (r - l) // 2
		if A[m] >= key:
			r = m
		else:
			l = m
	return r

def lis(A, size):
	tailTable = [0 for i in range(size + 1)]
	ln = 0
	tailTable[0] = A[0]
	ln = 1
	for i in range(1, size):
		if A[i] < tailTable[0]:
			tailTable[0] = A[i]
		elif A[i] > tailTable[ln - 1]:
			tailTable[ln] = A[i]
			ln += 1
		else:
			tailTable[CeilIndex(tailTable, -1, ln - 1, A[i])] = A[i]
	return ln
for _ in range(int(input())):
	n = int(input())
	a = list(mapi())
	mp = {}
	res = 0
	for i in a:
		if i not in mp:
			res += 1
			mp[i] = 1
	print(res)


import collections
tests = int(input())
for _ in range(tests):
	(n, x) = map(int, input().split())
	arr = [int(a) for a in input().strip().split(' ')]
	sum = 0
	sumarr = [0]
	for a in arr:
		sum += a
		sum = sum % x
		sumarr.append(sum)
	l = 0
	u = n
	if abs(sumarr[l] - sumarr[u]) % x == 0:
		while abs(sumarr[l] - sumarr[u]) % x == 0 and l < u:
			l += 1
		while abs(sumarr[0] - sumarr[u]) % x == 0 and u > 0:
			u -= 1
		ans = max(len(arr) - l, u)
		if ans == 0:
			print(-1)
		else:
			print(max(len(arr) - l, u))
	else:
		print(n)


from __future__ import print_function
import sys
import traceback
from bisect import bisect_left, bisect_right, insort
from itertools import chain, repeat, starmap
from math import log
from operator import add, eq, ne, gt, ge, lt, le, iadd
from textwrap import dedent
try:
	from collections.abc import Sequence, MutableSequence
except ImportError:
	from collections import Sequence, MutableSequence
from functools import wraps
from sys import hexversion
if hexversion < 50331648:
	from itertools import imap as map
	from itertools import izip as zip
else:
	from functools import reduce
	try:
		from _thread import get_ident
	except ImportError:
		from _dummy_thread import get_ident

def recursive_repr(fillvalue='...'):

	def decorating_function(user_function):
		repr_running = set()

		@wraps(user_function)
		def wrapper(self):
			key = (id(self), get_ident())
			if key in repr_running:
				return fillvalue
			repr_running.add(key)
			try:
				result = user_function(self)
			finally:
				repr_running.discard(key)
			return result
		return wrapper
	return decorating_function

class SortedList(MutableSequence):
	DEFAULT_LOAD_FACTOR = 1000

	def __init__(self, iterable=None, key=None):
		assert key is None
		self._len = 0
		self._load = self.DEFAULT_LOAD_FACTOR
		self._lists = []
		self._maxes = []
		self._index = []
		self._offset = 0
		if iterable is not None:
			self._update(iterable)

	@property
	def key(self):
		return None

	def _reset(self, load):
		values = reduce(iadd, self._lists, [])
		self._clear()
		self._load = load
		self._update(values)

	def clear(self):
		self._len = 0
		del self._lists[:]
		del self._maxes[:]
		del self._index[:]
		self._offset = 0
	_clear = clear

	def add(self, value):
		_lists = self._lists
		_maxes = self._maxes
		if _maxes:
			pos = bisect_right(_maxes, value)
			if pos == len(_maxes):
				pos -= 1
				_lists[pos].append(value)
				_maxes[pos] = value
			else:
				insort(_lists[pos], value)
			self._expand(pos)
		else:
			_lists.append([value])
			_maxes.append(value)
		self._len += 1

	def _expand(self, pos):
		_load = self._load
		_lists = self._lists
		_index = self._index
		if len(_lists[pos]) > _load << 1:
			_maxes = self._maxes
			_lists_pos = _lists[pos]
			half = _lists_pos[_load:]
			del _lists_pos[_load:]
			_maxes[pos] = _lists_pos[-1]
			_lists.insert(pos + 1, half)
			_maxes.insert(pos + 1, half[-1])
			del _index[:]
		elif _index:
			child = self._offset + pos
			while child:
				_index[child] += 1
				child = child - 1 >> 1
			_index[0] += 1

	def update(self, iterable):
		_lists = self._lists
		_maxes = self._maxes
		values = sorted(iterable)
		if _maxes:
			if len(values) * 4 >= self._len:
				values.extend(chain.from_iterable(_lists))
				values.sort()
				self._clear()
			else:
				_add = self.add
				for val in values:
					_add(val)
				return
		_load = self._load
		_lists.extend((values[pos:pos + _load] for pos in range(0, len(values), _load)))
		_maxes.extend((sublist[-1] for sublist in _lists))
		self._len = len(values)
		del self._index[:]
	_update = update

	def __contains__(self, value):
		_maxes = self._maxes
		if not _maxes:
			return False
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			return False
		_lists = self._lists
		idx = bisect_left(_lists[pos], value)
		return _lists[pos][idx] == value

	def discard(self, value):
		_maxes = self._maxes
		if not _maxes:
			return
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			return
		_lists = self._lists
		idx = bisect_left(_lists[pos], value)
		if _lists[pos][idx] == value:
			self._delete(pos, idx)

	def remove(self, value):
		_maxes = self._maxes
		if not _maxes:
			raise ValueError('{0!r} not in list'.format(value))
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			raise ValueError('{0!r} not in list'.format(value))
		_lists = self._lists
		idx = bisect_left(_lists[pos], value)
		if _lists[pos][idx] == value:
			self._delete(pos, idx)
		else:
			raise ValueError('{0!r} not in list'.format(value))

	def _delete(self, pos, idx):
		_lists = self._lists
		_maxes = self._maxes
		_index = self._index
		_lists_pos = _lists[pos]
		del _lists_pos[idx]
		self._len -= 1
		len_lists_pos = len(_lists_pos)
		if len_lists_pos > self._load >> 1:
			_maxes[pos] = _lists_pos[-1]
			if _index:
				child = self._offset + pos
				while child > 0:
					_index[child] -= 1
					child = child - 1 >> 1
				_index[0] -= 1
		elif len(_lists) > 1:
			if not pos:
				pos += 1
			prev = pos - 1
			_lists[prev].extend(_lists[pos])
			_maxes[prev] = _lists[prev][-1]
			del _lists[pos]
			del _maxes[pos]
			del _index[:]
			self._expand(prev)
		elif len_lists_pos:
			_maxes[pos] = _lists_pos[-1]
		else:
			del _lists[pos]
			del _maxes[pos]
			del _index[:]

	def _loc(self, pos, idx):
		if not pos:
			return idx
		_index = self._index
		if not _index:
			self._build_index()
		total = 0
		pos += self._offset
		while pos:
			if not pos & 1:
				total += _index[pos - 1]
			pos = pos - 1 >> 1
		return total + idx

	def _pos(self, idx):
		if idx < 0:
			last_len = len(self._lists[-1])
			if -idx <= last_len:
				return (len(self._lists) - 1, last_len + idx)
			idx += self._len
			if idx < 0:
				raise IndexError('list index out of range')
		elif idx >= self._len:
			raise IndexError('list index out of range')
		if idx < len(self._lists[0]):
			return (0, idx)
		_index = self._index
		if not _index:
			self._build_index()
		pos = 0
		child = 1
		len_index = len(_index)
		while child < len_index:
			index_child = _index[child]
			if idx < index_child:
				pos = child
			else:
				idx -= index_child
				pos = child + 1
			child = (pos << 1) + 1
		return (pos - self._offset, idx)

	def _build_index(self):
		row0 = list(map(len, self._lists))
		if len(row0) == 1:
			self._index[:] = row0
			self._offset = 0
			return
		head = iter(row0)
		tail = iter(head)
		row1 = list(starmap(add, zip(head, tail)))
		if len(row0) & 1:
			row1.append(row0[-1])
		if len(row1) == 1:
			self._index[:] = row1 + row0
			self._offset = 1
			return
		size = 2 ** (int(log(len(row1) - 1, 2)) + 1)
		row1.extend(repeat(0, size - len(row1)))
		tree = [row0, row1]
		while len(tree[-1]) > 1:
			head = iter(tree[-1])
			tail = iter(head)
			row = list(starmap(add, zip(head, tail)))
			tree.append(row)
		reduce(iadd, reversed(tree), self._index)
		self._offset = size * 2 - 1

	def __delitem__(self, index):
		if isinstance(index, slice):
			(start, stop, step) = index.indices(self._len)
			if step == 1 and start < stop:
				if start == 0 and stop == self._len:
					return self._clear()
				elif self._len <= 8 * (stop - start):
					values = self._getitem(slice(None, start))
					if stop < self._len:
						values += self._getitem(slice(stop, None))
					self._clear()
					return self._update(values)
			indices = range(start, stop, step)
			if step > 0:
				indices = reversed(indices)
			(_pos, _delete) = (self._pos, self._delete)
			for index in indices:
				(pos, idx) = _pos(index)
				_delete(pos, idx)
		else:
			(pos, idx) = self._pos(index)
			self._delete(pos, idx)

	def __getitem__(self, index):
		_lists = self._lists
		if isinstance(index, slice):
			(start, stop, step) = index.indices(self._len)
			if step == 1 and start < stop:
				if start == 0 and stop == self._len:
					return reduce(iadd, self._lists, [])
				(start_pos, start_idx) = self._pos(start)
				start_list = _lists[start_pos]
				stop_idx = start_idx + stop - start
				if len(start_list) >= stop_idx:
					return start_list[start_idx:stop_idx]
				if stop == self._len:
					stop_pos = len(_lists) - 1
					stop_idx = len(_lists[stop_pos])
				else:
					(stop_pos, stop_idx) = self._pos(stop)
				prefix = _lists[start_pos][start_idx:]
				middle = _lists[start_pos + 1:stop_pos]
				result = reduce(iadd, middle, prefix)
				result += _lists[stop_pos][:stop_idx]
				return result
			if step == -1 and start > stop:
				result = self._getitem(slice(stop + 1, start + 1))
				result.reverse()
				return result
			indices = range(start, stop, step)
			return list((self._getitem(index) for index in indices))
		else:
			if self._len:
				if index == 0:
					return _lists[0][0]
				elif index == -1:
					return _lists[-1][-1]
			else:
				raise IndexError('list index out of range')
			if 0 <= index < len(_lists[0]):
				return _lists[0][index]
			len_last = len(_lists[-1])
			if -len_last < index < 0:
				return _lists[-1][len_last + index]
			(pos, idx) = self._pos(index)
			return _lists[pos][idx]
	_getitem = __getitem__

	def __setitem__(self, index, value):
		message = 'use ``del sl[index]`` and ``sl.add(value)`` instead'
		raise NotImplementedError(message)

	def __iter__(self):
		return chain.from_iterable(self._lists)

	def __reversed__(self):
		return chain.from_iterable(map(reversed, reversed(self._lists)))

	def reverse(self):
		raise NotImplementedError('use ``reversed(sl)`` instead')

	def islice(self, start=None, stop=None, reverse=False):
		_len = self._len
		if not _len:
			return iter(())
		(start, stop, _) = slice(start, stop).indices(self._len)
		if start >= stop:
			return iter(())
		_pos = self._pos
		(min_pos, min_idx) = _pos(start)
		if stop == _len:
			max_pos = len(self._lists) - 1
			max_idx = len(self._lists[-1])
		else:
			(max_pos, max_idx) = _pos(stop)
		return self._islice(min_pos, min_idx, max_pos, max_idx, reverse)

	def _islice(self, min_pos, min_idx, max_pos, max_idx, reverse):
		_lists = self._lists
		if min_pos > max_pos:
			return iter(())
		if min_pos == max_pos:
			if reverse:
				indices = reversed(range(min_idx, max_idx))
				return map(_lists[min_pos].__getitem__, indices)
			indices = range(min_idx, max_idx)
			return map(_lists[min_pos].__getitem__, indices)
		next_pos = min_pos + 1
		if next_pos == max_pos:
			if reverse:
				min_indices = range(min_idx, len(_lists[min_pos]))
				max_indices = range(max_idx)
				return chain(map(_lists[max_pos].__getitem__, reversed(max_indices)), map(_lists[min_pos].__getitem__, reversed(min_indices)))
			min_indices = range(min_idx, len(_lists[min_pos]))
			max_indices = range(max_idx)
			return chain(map(_lists[min_pos].__getitem__, min_indices), map(_lists[max_pos].__getitem__, max_indices))
		if reverse:
			min_indices = range(min_idx, len(_lists[min_pos]))
			sublist_indices = range(next_pos, max_pos)
			sublists = map(_lists.__getitem__, reversed(sublist_indices))
			max_indices = range(max_idx)
			return chain(map(_lists[max_pos].__getitem__, reversed(max_indices)), chain.from_iterable(map(reversed, sublists)), map(_lists[min_pos].__getitem__, reversed(min_indices)))
		min_indices = range(min_idx, len(_lists[min_pos]))
		sublist_indices = range(next_pos, max_pos)
		sublists = map(_lists.__getitem__, sublist_indices)
		max_indices = range(max_idx)
		return chain(map(_lists[min_pos].__getitem__, min_indices), chain.from_iterable(sublists), map(_lists[max_pos].__getitem__, max_indices))

	def irange(self, minimum=None, maximum=None, inclusive=(True, True), reverse=False):
		_maxes = self._maxes
		if not _maxes:
			return iter(())
		_lists = self._lists
		if minimum is None:
			min_pos = 0
			min_idx = 0
		elif inclusive[0]:
			min_pos = bisect_left(_maxes, minimum)
			if min_pos == len(_maxes):
				return iter(())
			min_idx = bisect_left(_lists[min_pos], minimum)
		else:
			min_pos = bisect_right(_maxes, minimum)
			if min_pos == len(_maxes):
				return iter(())
			min_idx = bisect_right(_lists[min_pos], minimum)
		if maximum is None:
			max_pos = len(_maxes) - 1
			max_idx = len(_lists[max_pos])
		elif inclusive[1]:
			max_pos = bisect_right(_maxes, maximum)
			if max_pos == len(_maxes):
				max_pos -= 1
				max_idx = len(_lists[max_pos])
			else:
				max_idx = bisect_right(_lists[max_pos], maximum)
		else:
			max_pos = bisect_left(_maxes, maximum)
			if max_pos == len(_maxes):
				max_pos -= 1
				max_idx = len(_lists[max_pos])
			else:
				max_idx = bisect_left(_lists[max_pos], maximum)
		return self._islice(min_pos, min_idx, max_pos, max_idx, reverse)

	def __len__(self):
		return self._len

	def bisect_left(self, value):
		_maxes = self._maxes
		if not _maxes:
			return 0
		pos = bisect_left(_maxes, value)
		if pos == len(_maxes):
			return self._len
		idx = bisect_left(self._lists[pos], value)
		return self._loc(pos, idx)

	def bisect_right(self, value):
		_maxes = self._maxes
		if not _maxes:
			return 0
		pos = bisect_right(_maxes, value)
		if pos == len(_maxes):
			return self._len
		idx = bisect_right(self._lists[pos], value)
		return self._loc(pos, idx)
	bisect = bisect_right
	_bisect_right = bisect_right

	def count(self, value):
		_maxes = self._maxes
		if not _maxes:
			return 0
		pos_left = bisect_left(_maxes, value)
		if pos_left == len(_maxes):
			return 0
		_lists = self._lists
		idx_left = bisect_left(_lists[pos_left], value)
		pos_right = bisect_right(_maxes, value)
		if pos_right == len(_maxes):
			return self._len - self._loc(pos_left, idx_left)
		idx_right = bisect_right(_lists[pos_right], value)
		if pos_left == pos_right:
			return idx_right - idx_left
		right = self._loc(pos_right, idx_right)
		left = self._loc(pos_left, idx_left)
		return right - left

	def copy(self):
		return self.__class__(self)
	__copy__ = copy

	def append(self, value):
		raise NotImplementedError('use ``sl.add(value)`` instead')

	def extend(self, values):
		raise NotImplementedError('use ``sl.update(values)`` instead')

	def insert(self, index, value):
		raise NotImplementedError('use ``sl.add(value)`` instead')

	def pop(self, index=-1):
		if not self._len:
			raise IndexError('pop index out of range')
		_lists = self._lists
		if index == 0:
			val = _lists[0][0]
			self._delete(0, 0)
			return val
		if index == -1:
			pos = len(_lists) - 1
			loc = len(_lists[pos]) - 1
			val = _lists[pos][loc]
			self._delete(pos, loc)
			return val
		if 0 <= index < len(_lists[0]):
			val = _lists[0][index]
			self._delete(0, index)
			return val
		len_last = len(_lists[-1])
		if -len_last < index < 0:
			pos = len(_lists) - 1
			loc = len_last + index
			val = _lists[pos][loc]
			self._delete(pos, loc)
			return val
		(pos, idx) = self._pos(index)
		val = _lists[pos][idx]
		self._delete(pos, idx)
		return val

	def index(self, value, start=None, stop=None):
		_len = self._len
		if not _len:
			raise ValueError('{0!r} is not in list'.format(value))
		if start is None:
			start = 0
		if start < 0:
			start += _len
		if start < 0:
			start = 0
		if stop is None:
			stop = _len
		if stop < 0:
			stop += _len
		if stop > _len:
			stop = _len
		if stop <= start:
			raise ValueError('{0!r} is not in list'.format(value))
		_maxes = self._maxes
		pos_left = bisect_left(_maxes, value)
		if pos_left == len(_maxes):
			raise ValueError('{0!r} is not in list'.format(value))
		_lists = self._lists
		idx_left = bisect_left(_lists[pos_left], value)
		if _lists[pos_left][idx_left] != value:
			raise ValueError('{0!r} is not in list'.format(value))
		stop -= 1
		left = self._loc(pos_left, idx_left)
		if start <= left:
			if left <= stop:
				return left
		else:
			right = self._bisect_right(value) - 1
			if start <= right:
				return start
		raise ValueError('{0!r} is not in list'.format(value))

	def __add__(self, other):
		values = reduce(iadd, self._lists, [])
		values.extend(other)
		return self.__class__(values)
	__radd__ = __add__

	def __iadd__(self, other):
		self._update(other)
		return self

	def __mul__(self, num):
		values = reduce(iadd, self._lists, []) * num
		return self.__class__(values)
	__rmul__ = __mul__

	def __imul__(self, num):
		values = reduce(iadd, self._lists, []) * num
		self._clear()
		self._update(values)
		return self

	def __make_cmp(seq_op, symbol, doc):

		def comparer(self, other):
			if not isinstance(other, Sequence):
				return NotImplemented
			self_len = self._len
			len_other = len(other)
			if self_len != len_other:
				if seq_op is eq:
					return False
				if seq_op is ne:
					return True
			for (alpha, beta) in zip(self, other):
				if alpha != beta:
					return seq_op(alpha, beta)
			return seq_op(self_len, len_other)
		seq_op_name = seq_op.__name__
		comparer.__name__ = '__{0}__'.format(seq_op_name)
		doc_str = ''
		comparer.__doc__ = dedent(doc_str.format(doc, seq_op_name, symbol))
		return comparer
	__eq__ = __make_cmp(eq, '==', 'equal to')
	__ne__ = __make_cmp(ne, '!=', 'not equal to')
	__lt__ = __make_cmp(lt, '<', 'less than')
	__gt__ = __make_cmp(gt, '>', 'greater than')
	__le__ = __make_cmp(le, '<=', 'less than or equal to')
	__ge__ = __make_cmp(ge, '>=', 'greater than or equal to')
	__make_cmp = staticmethod(__make_cmp)

	def __reduce__(self):
		values = reduce(iadd, self._lists, [])
		return (type(self), (values,))

	@recursive_repr()
	def __repr__(self):
		return '{0}({1!r})'.format(type(self).__name__, list(self))

	def _check(self):
		try:
			assert self._load >= 4
			assert len(self._maxes) == len(self._lists)
			assert self._len == sum((len(sublist) for sublist in self._lists))
			for sublist in self._lists:
				for pos in range(1, len(sublist)):
					assert sublist[pos - 1] <= sublist[pos]
			for pos in range(1, len(self._lists)):
				assert self._lists[pos - 1][-1] <= self._lists[pos][0]
			for pos in range(len(self._maxes)):
				assert self._maxes[pos] == self._lists[pos][-1]
			double = self._load << 1
			assert all((len(sublist) <= double for sublist in self._lists))
			half = self._load >> 1
			for pos in range(0, len(self._lists) - 1):
				assert len(self._lists[pos]) >= half
			if self._index:
				assert self._len == self._index[0]
				assert len(self._index) == self._offset + len(self._lists)
				for pos in range(len(self._lists)):
					leaf = self._index[self._offset + pos]
					assert leaf == len(self._lists[pos])
				for pos in range(self._offset):
					child = (pos << 1) + 1
					if child >= len(self._index):
						assert self._index[pos] == 0
					elif child + 1 == len(self._index):
						assert self._index[pos] == self._index[child]
					else:
						child_sum = self._index[child] + self._index[child + 1]
						assert child_sum == self._index[pos]
		except:
			traceback.print_exc(file=sys.stdout)
			print('len', self._len)
			print('load', self._load)
			print('offset', self._offset)
			print('len_index', len(self._index))
			print('index', self._index)
			print('len_maxes', len(self._maxes))
			print('maxes', self._maxes)
			print('len_lists', len(self._lists))
			print('lists', self._lists)
			raise

def identity(value):
	return value
from itertools import chain
from operator import eq, ne, gt, ge, lt, le
from textwrap import dedent
try:
	from collections.abc import MutableSet, Sequence, Set
except ImportError:
	from collections import MutableSet, Sequence, Set

class SortedSet(MutableSet, Sequence):

	def __init__(self, iterable=None, key=None):
		self._key = key
		if not hasattr(self, '_set'):
			self._set = set()
		self._list = SortedList(self._set, key=key)
		_set = self._set
		self.isdisjoint = _set.isdisjoint
		self.issubset = _set.issubset
		self.issuperset = _set.issuperset
		_list = self._list
		self.bisect_left = _list.bisect_left
		self.bisect = _list.bisect
		self.bisect_right = _list.bisect_right
		self.index = _list.index
		self.irange = _list.irange
		self.islice = _list.islice
		self._reset = _list._reset
		if key is not None:
			self.bisect_key_left = _list.bisect_key_left
			self.bisect_key_right = _list.bisect_key_right
			self.bisect_key = _list.bisect_key
			self.irange_key = _list.irange_key
		if iterable is not None:
			self._update(iterable)

	@classmethod
	def _fromset(cls, values, key=None):
		sorted_set = object.__new__(cls)
		sorted_set._set = values
		sorted_set.__init__(key=key)
		return sorted_set

	@property
	def key(self):
		return self._key

	def __contains__(self, value):
		return value in self._set

	def __getitem__(self, index):
		return self._list[index]

	def __delitem__(self, index):
		_set = self._set
		_list = self._list
		if isinstance(index, slice):
			values = _list[index]
			_set.difference_update(values)
		else:
			value = _list[index]
			_set.remove(value)
		del _list[index]

	def __make_cmp(set_op, symbol, doc):

		def comparer(self, other):
			if isinstance(other, SortedSet):
				return set_op(self._set, other._set)
			elif isinstance(other, Set):
				return set_op(self._set, other)
			return NotImplemented
		set_op_name = set_op.__name__
		comparer.__name__ = '__{0}__'.format(set_op_name)
		doc_str = ''
		comparer.__doc__ = dedent(doc_str.format(doc, set_op_name, symbol))
		return comparer
	__eq__ = __make_cmp(eq, '==', 'equal to')
	__ne__ = __make_cmp(ne, '!=', 'not equal to')
	__lt__ = __make_cmp(lt, '<', 'a proper subset of')
	__gt__ = __make_cmp(gt, '>', 'a proper superset of')
	__le__ = __make_cmp(le, '<=', 'a subset of')
	__ge__ = __make_cmp(ge, '>=', 'a superset of')
	__make_cmp = staticmethod(__make_cmp)

	def __len__(self):
		return len(self._set)

	def __iter__(self):
		return iter(self._list)

	def __reversed__(self):
		return reversed(self._list)

	def add(self, value):
		_set = self._set
		if value not in _set:
			_set.add(value)
			self._list.add(value)
	_add = add

	def clear(self):
		self._set.clear()
		self._list.clear()

	def copy(self):
		return self._fromset(set(self._set), key=self._key)
	__copy__ = copy

	def count(self, value):
		return 1 if value in self._set else 0

	def discard(self, value):
		_set = self._set
		if value in _set:
			_set.remove(value)
			self._list.remove(value)
	_discard = discard

	def pop(self, index=-1):
		value = self._list.pop(index)
		self._set.remove(value)
		return value

	def remove(self, value):
		self._set.remove(value)
		self._list.remove(value)

	def difference(self, *iterables):
		diff = self._set.difference(*iterables)
		return self._fromset(diff, key=self._key)
	__sub__ = difference

	def difference_update(self, *iterables):
		_set = self._set
		_list = self._list
		values = set(chain(*iterables))
		if 4 * len(values) > len(_set):
			_set.difference_update(values)
			_list.clear()
			_list.update(_set)
		else:
			_discard = self._discard
			for value in values:
				_discard(value)
		return self
	__isub__ = difference_update

	def intersection(self, *iterables):
		intersect = self._set.intersection(*iterables)
		return self._fromset(intersect, key=self._key)
	__and__ = intersection
	__rand__ = __and__

	def intersection_update(self, *iterables):
		_set = self._set
		_list = self._list
		_set.intersection_update(*iterables)
		_list.clear()
		_list.update(_set)
		return self
	__iand__ = intersection_update

	def symmetric_difference(self, other):
		diff = self._set.symmetric_difference(other)
		return self._fromset(diff, key=self._key)
	__xor__ = symmetric_difference
	__rxor__ = __xor__

	def symmetric_difference_update(self, other):
		_set = self._set
		_list = self._list
		_set.symmetric_difference_update(other)
		_list.clear()
		_list.update(_set)
		return self
	__ixor__ = symmetric_difference_update

	def union(self, *iterables):
		return self.__class__(chain(iter(self), *iterables), key=self._key)
	__or__ = union
	__ror__ = __or__

	def update(self, *iterables):
		_set = self._set
		_list = self._list
		values = set(chain(*iterables))
		if 4 * len(values) > len(_set):
			_list = self._list
			_set.update(values)
			_list.clear()
			_list.update(_set)
		else:
			_add = self._add
			for value in values:
				_add(value)
		return self
	__ior__ = update
	_update = update

	def __reduce__(self):
		return (type(self), (self._set, self._key))

	@recursive_repr()
	def __repr__(self):
		_key = self._key
		key = '' if _key is None else ', key={0!r}'.format(_key)
		type_name = type(self).__name__
		return '{0}({1!r}{2})'.format(type_name, list(self), key)

	def _check(self):
		_set = self._set
		_list = self._list
		_list._check()
		assert len(_set) == len(_list)
		assert all((value in _set for value in _list))
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

class SegmentTree1:

	def __init__(self, data, default=9999999, func=lambda a, b: min(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 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, k) = map(int, input().split())
	ind = -1
	ind1 = n
	l = list(map(int, input().split()))
	for i in range(n):
		if l[i] % k != 0:
			if ind == -1:
				ind = i
			ind1 = i
	ans = n
	if sum(l) % k == 0:
		ans = n - min(ind + 1, n - ind1)
	if ind == -1 and ind1 == n:
		ans = -1
	print(ans)


for _ in ' ' * int(input()):
	input()
	print(len(set(map(int, input().split()))))


import sys
input = sys.stdin.buffer.readline
t = int(input())
ans = []
for _ in range(t):
	(n, x) = map(int, input().split())
	(*a,) = map(int, input().split())
	if x == 1 or all((y % x == 0 for y in a)):
		ans.append(-1)
		continue
	s = sum(a)
	if s % x != 0:
		ans.append(n)
		continue
	l = r = -1
	for i in range(n):
		if a[i] % x != 0:
			if l < 0:
				l = i
			r = i
	ans.append(max(r, n - l - 1))
print('\n'.join(map(str, 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')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

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

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

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

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

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	num = list(map(int, input().split()))
	for i in range(1, n):
		num[i] += num[i - 1]
	num.insert(0, 0)
	(l, r) = (1, 1)
	f = 0
	ans = -1
	while r <= n:
		sumi = num[r] - num[l - 1]
		if sumi % x != 0:
			ans = max(ans, r - l + 1)
		r += 1
	r -= 1
	while l <= n:
		sumi = num[r] - num[l - 1]
		if sumi % x != 0:
			ans = max(ans, r - l + 1)
		l += 1
	print(ans)


for i in range(int(input())):
	x = int(input())
	a = {int(j) for j in input().split()}
	print(len(a))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	a = b = s = m = 0
	f = False
	for i in l:
		s += i
		a += 1
		if s % k != 0:
			f = True
			m = max(m, a)
	s = 0
	for i in l[::-1]:
		s += i
		b += 1
		if s % k != 0:
			f = True
			m = max(m, b)
	if f:
		print(m)
	else:
		print(-1)


t = int(input())
list = []
for test_case in range(t):
	n = int(input())
	a = input().split()
	x = list.append(set(a))
for items in list:
	print(len(items))


from collections import Counter
t = int(input())
for p in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]

	def countDistinct(arr):
		return len(Counter(arr).keys())
	if __name__ == '__main__':
		arr = a
		print(countDistinct(arr))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	s = sum(arr)
	if s % x != 0:
		print(n)
	else:
		l = -1
		boo = False
		for i in range(n):
			if (s - arr[i]) % x != 0:
				l = i
				break
		r = -1
		for i in range(n - 1, -1, -1):
			if (s - arr[i]) % x != 0:
				r = i
				break
		if l == -1 and r == -1:
			print(-1)
		else:
			l += 1
			r = n - 1 - r + 1
			if l < r:
				print(n - l)
			else:
				print(n - r)


import sys
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))

def solve():
	n = ni()
	a = set(nl())
	print(len(a))
	return
T = ni()
for _ in range(T):
	solve()


from math import log2, ceil
rw = int(input())
for ewqr in range(rw):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	nx = 0
	nxpref = 0
	nxsuf = 0
	for i in a:
		if i % x == 0:
			nx += 1
	for i in range(n):
		if a[i] % x == 0:
			nxpref += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x == 0:
			nxsuf += 1
		else:
			break
	s = sum(a)
	if s % x != 0:
		print(n)
	elif nx == n:
		print(-1)
	else:
		print(n - min(nxpref, nxsuf) - 1)


for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	li_set = set(li)
	print(len(li_set))


import sys
input = sys.stdin.readline
t = int(input())
out = []
for _ in range(t):
	n = int(input())
	a = set(input().split())
	out.append(str(len(a)))
print('\n'.join(out))


try:
	tc = int(input())
	for k in range(tc):
		n = int(input())
		lst = [int(x) for x in input().split()]
		lst.sort()
		c = 0
		val = 0
		for i in range(len(lst) - 1):
			if lst[i] != lst[i + 1]:
				c += 1
				val = i
		print(c + 1)
except EOFError:
	pass


t = int(input())
for i in range(t):
	n = int(input())
	lista = [int(x) for x in input().split()]
	ordlista = sorted(lista)
	cont = 0
	for j in range(n - 1):
		if ordlista[j] != ordlista[j + 1]:
			cont += 1
	print(cont + 1)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split(' ')))
	A = list(map(int, input().split(' ')))
	fi = None
	li = None
	prefixes = [0] * (n + 1)
	for i in range(1, n + 1):
		prefixes[i] = (prefixes[i - 1] + A[i - 1]) % x
		if fi == None and prefixes[i] != 0:
			fi = i
		if prefixes[i] != 0:
			li = i
	if fi == None:
		print(-1)
	elif prefixes[n] != 0:
		print(n)
	else:
		print(max(n - fi, li))


from collections import defaultdict
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * n
	b[0] = a[0] % x
	if a[0] % x == 0:
		f = True
	else:
		f = False
	for i in range(1, n):
		b[i] = (b[i - 1] + a[i] % x) % x
		if a[i] % x != 0:
			f = False
	if b[-1] != 0:
		print(n)
	elif f:
		print(-1)
	else:
		f1 = 0
		f2 = 0
		for i in range(n):
			if b[i] != 0:
				f1 = i
				break
		for i in range(n - 1, -1, -1):
			if b[i] != 0:
				f2 = i
				break
		print(max(n - f1 - 1, f2 + 1))


t = int(input())
for tc in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	print(len(s))


t = int(input())
sol = []
for _ in range(t):
	(n, x) = list(map(int, input().strip().split()))
	a = list(map(int, input().strip().split()))
	if sum(a) % x != 0:
		sol.append(n)
		continue
	i = 0
	while i < n:
		if a[i] != 0 and a[i] % x != 0:
			break
		i = i + 1
	j = n - 1
	while j >= 0:
		if a[j] != 0 and a[j] % x != 0:
			break
		j = j - 1
	if i == n and j == -1:
		sol.append(-1)
	else:
		if n - j > i + 1:
			idx = i
		else:
			idx = j
		if idx > n // 2:
			sol.append(idx)
		else:
			sol.append(n - idx - 1)
for o in sol:
	print(o)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	p = s
	if s % m:
		print(n)
	else:
		for i in range(n):
			s = s - l[i]
			p = p - l[-i - 1]
			if s % m:
				print(n - i - 1)
				break
			elif p % m:
				print(n - i - 1)
				break
		else:
			print(-1)


import os
import heapq
import sys
import bisect
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		arr = inar()
		sm = 0
		for i in range(n):
			sm += arr[i]
		len1 = 0
		sm2 = sm
		cnt = 0
		for i in range(n):
			if sm % x == 0:
				sm -= arr[i]
				cnt += 1
			else:
				len1 = max(len1, n - cnt)
				break
		cnt = 0
		len2 = 0
		for i in range(n - 1, -1, -1):
			if sm2 % x == 0:
				sm2 -= arr[i]
				cnt += 1
			else:
				len2 = max(len2, n - cnt)
				break
		res = max(len1, len2)
		if res == 0:
			print(-1)
		else:
			print(res)
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()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
		continue
	else:
		l = 0
		m = n - 1
		ans = -1
		while l <= m:
			if a[m] % x != 0:
				ans = m
				break
			if a[l] % x != 0:
				ans = n - l - 1
				break
			l += 1
			m -= 1
	print(ans)


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

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

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)
debugging = 1
t = intput()
for _ in range(t):
	n = intput()
	a = list(intsput())
	print(len(set(a)))


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, x) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	su = [0]
	for i in arr:
		su.append(su[-1] + i)
	maxi = -1
	for y in range(1, len(su)):
		if su[y] % x != 0:
			maxi = max(maxi, y, n - y)
	print(maxi)


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
t = int(input())
for tc in range(t):
	(n, x) = list(map(int, stdin.readline().split()))
	ar = list(map(int, stdin.readline().split()))
	s = sum(ar)
	if s % x != 0:
		res = n
	else:
		bs = 0
		bc = 0
		while bs % x == 0 and bc < n:
			bc += 1
			bs += ar[bc - 1]
		b1 = bc
		arrev = ar[::-1]
		bs = 0
		bc = 0
		while bs % x == 0 and bc < n:
			bc += 1
			bs += arrev[bc - 1]
		bres = min(bc, b1)
		res = n - bres
		if res == 0:
			res = -1
	stdout.write(str(res) + '\n')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	a = I()
	print(len(set(a)))


t = int(input())
for loop in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	one = 0
	f = 0
	for i in range(n):
		if arr[i] % x == 0:
			one += 1
		else:
			f = 1
			break
	if f == 0:
		print(-1)
		continue
	two = 0
	for i in range(n - 1, -1, -1):
		if arr[i] % x == 0:
			two += 1
		else:
			break
	one = min(one, two)
	print(n - one - 1)


task_number = int(input())
for _ in range(task_number):
	_ = input()
	print(len(set(input().split())))


def get(*arg):
	if arg[0] == 0:
		cnt = int(input())
		flag = 1
	else:
		cnt = 1
		flag = 0
	lst = list()
	for i in range(cnt):
		lst2 = list()
		for ii in range(len(arg) - flag):
			if arg[ii + flag] == 1:
				t = input().split()
				tmp = list()
				for iii in t:
					tmp.append(int(iii))
			elif arg[ii + flag] == 2:
				tmp = input().split()
			else:
				tmp = input()
			lst2.append(tmp)
		lst.append(lst2)
	return lst
a = get(0, 1, 1)
for i in a:
	print(len(set(i[1])))


from collections import Counter
for i in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	cnt = Counter(arr)
	print(len(cnt))


firstline = int(input())
for i in range(firstline):
	length = int(input())
	liste = input().split()
	liste = list(map(int, liste))
	liste = set(liste)
	liste = list(liste)
	liste.sort()
	print(len(liste))


ts = int(input())
for test in range(ts):
	ans = 0
	n = int(input())
	arr = set(map(int, input().split()))
	ans = len(arr)
	print(ans)


t = int(input())
for p in range(0, t):
	q = int(input())
	x = [int(i) for i in input().split()]
	p = set(x)
	print(len(p))


t = int(input())
for p in range(t):
	(n, x) = input().split()
	(n, x) = (int(n), int(x))
	a = [int(m) for m in input().split()]
	b = [w % x for w in a]
	aux = []
	non_div = []
	for (index, val) in enumerate(b):
		aux.append(val == 0)
		if val != 0:
			non_div.append(index)
	if all(aux):
		print(-1)
	else:
		max_len = 0
		if sum(a) % x != 0:
			max_len = n
		else:
			a1 = non_div[0]
			a2 = non_div[-1]
			max_len = max(a2, n - a1 - 1)
		print(max_len)


def Longest(a, n, x):
	i = 0
	j = n - 1
	while a[i] == 0:
		i += 1
	while a[j] == 0:
		j -= 1
		k = 1
	return max(j, n - 1 - i)
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a = [elem % x for elem in a]
	if sum(a) == 0:
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		print(Longest(a, n, x))


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, x) = map(int, stdin.readline().strip().split())
	arr = list(map(int, stdin.readline().strip().split()))
	pre = [arr[0]]
	for i in range(1, n):
		pre.append(pre[-1] + arr[i])
	arr = arr[::-1]
	pre1 = [arr[0]]
	for i in range(1, n):
		pre1.append(pre1[-1] + arr[i])
	ans = n
	flg = 0
	for i in range(n):
		if pre[n - i - 1] % x != 0 or pre1[n - i - 1] % x != 0:
			print(ans)
			flg = 1
			break
		ans = ans - 1
	if flg == 0:
		print(-1)


from functools import reduce
t = int(input())
for _ in range(0, t):
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	left = 0
	right = n - 1
	c_sum = reduce(lambda x, y: x + y, l)
	if c_sum % x != 0:
		print(n)
	else:
		left = -1
		right = -1
		for i in range(0, n):
			if l[i] % x != 0:
				left = i
				break
		for i in range(n - 1, -1, -1):
			if l[i] % x != 0:
				right = i
				break
		left = n - left - 1 if left >= 0 else -1
		right = right if right >= 0 else -1
		print(max(left, right))


p = int(input())
for i in range(p):
	w = int(input())
	b = set(list(map(int, input().split())))
	print(len(b))


n = int(input())
ans = []
for _ in range(n):
	_ = input()
	arr = set(map(int, input().split()))
	ans.append(len(arr))
print(*ans, sep='\n')


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		a = list(map(int, input().split()))
		(c, s) = (0, 0)
		for i in range(n):
			if a[i] % x == 0:
				c += 1
			s += a[i]
			a[i] %= x
		if c == n:
			print('-1')
		elif s % x != 0:
			print(n)
		else:
			for i in range(n):
				if a[i] != 0:
					ans = max(i + 1, n - i - 1)
					break
			a.reverse()
			for i in range(n):
				if a[i] != 0:
					ans = max(ans, i + 1, n - i - 1)
					break
			print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	if sum(A) % x != 0:
		print(n)
		continue
	l = 0
	for i in range(n):
		l += A[i]
		if l % x != 0:
			break
	else:
		print(-1)
		continue
	r = 0
	for j in reversed(range(n)):
		r += A[j]
		if r % x != 0:
			break
	else:
		print(-1)
		continue
	ans = max(n - i - 1, j)
	print(ans)


import sys
import math
from decimal import *

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

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

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))
tt = I()
for ii in range(tt):
	(n, x) = IL()
	l = IL()
	l = [a % x for a in l]
	ss = sum(l)
	if ss == 0:
		print(-1)
		continue
	if ss % x != 0:
		print(len(l))
		continue
	ans = -1
	for i in range(len(l)):
		if l[i] != 0:
			ans = max(ans, len(l) - i - 1)
	for i in range(len(l) - 1, -1, -1):
		if l[i] != 0:
			ans = max(ans, i)
	print(ans)
	pass


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	tot_sum = sum(a)
	f = 0
	b = n - 1
	eq = 0
	while f <= b:
		if tot_sum % x != 0:
			print(eq + n)
			break
		elif a[f] % x != 0:
			n -= 1
			tot_sum -= a[f]
			f += 1
		elif a[b] % x != 0:
			n -= 1
			tot_sum -= a[b]
			b -= 1
		elif a[f] % x == a[b] % x == 0:
			n -= 2
			eq += 1
			tot_sum -= a[f] + a[b]
			f += 1
			b -= 1
	if f > b:
		print(-1)


for j in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	pre = [0] * (n + 1)
	suf = [0] * (n + 1)
	mxx1 = mxx2 = -1
	suf[n] = l[n - 1]
	if suf[n] % x != 0:
		mxx2 = n
	for i in range(1, n + 1):
		pre[i] = pre[i - 1] + l[i - 1]
		if pre[i] % x != 0:
			mxx1 = i
		suf[n - i] = suf[n - i + 1] + l[n - i - 1]
		if suf[n - i] % x != 0 and n - i != 0:
			mxx2 = n - i
	suf[0] = 0
	k = n + 1 - mxx2
	if mxx1 > 0:
		if mxx2 > 0:
			print(max(mxx1, k))
		else:
			print(mxx1)
	else:
		print('-1')


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [*map(int, input().split())]
	(c, d) = (1000000000.0, -1)
	for i in range(n):
		if a[i]:
			a[i] %= x
		if a[i]:
			c = min(i, c)
			d = max(i, d)
	tots = sum(a)
	print(n if tots % x else -1 if c == 1000000000.0 and d == -1 else max(n - c - 1, d))


def process(n, X, a):
	s = int(0)
	for x in a:
		s += x
	if s % X != 0:
		print('%d' % n)
		return
	ans = -1
	s2 = int(0)
	for i in range(n):
		s2 += a[i]
		if (s - s2) % X != 0:
			ans = n - i - 1
			break
	s2 = 0
	for i in range(n - 1, -1, -1):
		s2 += a[i]
		if (s - s2) % X != 0:
			ans = max(ans, i)
			break
	print(ans)
test = int(input())
while test > 0:
	test -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	process(n, x, a)


n = int(input())
Result = []
for i in range(0, n):
	len_ = int(input())
	List = list(map(int, input().strip().split()))[0:len_]
	List = list(dict.fromkeys(List))
	List.sort()
	Result.append(len(List))
for i in Result:
	print(i)


def solve():
	N = int(input())
	L = list(map(int, input().split()))
	print(len(set(L)))
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in map(int, input().split()):
		l.append(i)
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	sum = 0
	for i in d:
		sum += d[i] - 1
	print(n - sum)


t = int(input())
for _ in range(t):
	s = int(input())
	ar = list(map(int, input().split()))
	print(len(set(sorted(ar))))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, x) = I()
	l = I()
	c = 0
	for i in range(n):
		l[i] = l[i] % x
		c += l[i] == 0
	if c == n:
		print(-1)
	else:
		s = sum(l)
		if s % x == 0:
			x = y = -1
			for i in range(n):
				if l[i] and x == -1:
					x = i + 1
				elif l[i]:
					y = i
			print(max(n - x, y))
		else:
			an = n
			print(an)


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


for _ in range(int(input())):
	(n, h) = map(int, input().split())
	l = list(map(int, input().split()))
	t = 0
	i = []
	c = 0
	cc = 1
	if sum(l) % h == 0:
		for x in l:
			c += 1
			if x % h != 0:
				t = 1
				i.append(c)
		if t == 0:
			print(-1)
			t = 1
			cc = 0
	else:
		print(n)
		t = 1
		cc = 0
	if cc == 1:
		print(max(max(i) - 1, n - min(i)))


import sys

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

def iinput():
	return int(input())

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

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

def main():
	input()
	print(len(set(rlinput())))
for i in range(iinput()):
	main()


numberOfTest = int(input())
for _ in range(numberOfTest):
	length = int(input())
	A = sorted(list(map(int, input().split())))
	iteracion = 0
	suma = 0
	last_element = None
	for element in A:
		if element != last_element:
			suma += 1
		iteracion += 1
		if iteracion >= 1:
			last_element = element
	print(suma)


from queue import LifoQueue

def print_sol(c, sol):
	print('Case #{}: {}'.format(c, sol))

def rd_int():
	return int(input())

def rd_str():
	return input()

def rd_str_lst():
	return input().split(' ')

def sp_str_lst():
	return list(input())

def rd_int_lst():
	return [int(i) for i in rd_str_lst()]

def sp_int_lst():
	return [int(i) for i in sp_str_lst()]

def dfs(g, i, v):
	v[i] = True
	for j in g[i]:
		if not v[j]:
			dfs(g, j, v)
	print(i)

def dfs_iter(g, i, n):
	v = [False] * n
	stack = LifoQueue()
	stack.put(i)
	while stack.not_empty:
		u = stack.get()
		v[u] = True
		print(u)
		for i in g[u]:
			if not v[i]:
				stack.put(i)

def main():
	t = rd_int()
	for c in range(1, t + 1):
		(n, x) = rd_int_lst()
		a = rd_int_lst()
		sa = sum(a)
		if sa % x == 0:
			left = 0
			while left < n and a[left] % x == 0:
				left += 1
			if left == n:
				print(-1)
			else:
				right = n - 1
				while right >= 0 and a[right] % x == 0:
					right -= 1
				print(max(left, n - left - 1, right, n - right - 1))
		else:
			print(n)
main()


for i in range(int(input())):
	input()
	print(len(set(map(int, input().split()))))


def solve(arr, x):
	n = len(arr)
	ans = [0] * n
	for i in range(n):
		ans[i] = arr[i] % x
	s = sum(arr)
	if s % x != 0:
		return n
	if sum(ans) == 0:
		return -1
	l = 0
	r = n - 1
	while l < n:
		if ans[l] != 0:
			break
		l = l + 1
	while r >= 0:
		if ans[r] != 0:
			break
		r = r - 1
	return max(max(l + 1, n - l - 1), max(r, n - r))
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	ans = solve(arr, x)
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	flag = 1
	for i in l:
		if i % x:
			flag = 0
	if flag:
		print(-1)
	elif sum(l) % x:
		print(n)
	else:
		j = 0
		while l[j] % x == 0:
			j += 1
		k = n - 1
		while l[k] % x == 0:
			k -= 1
		print(max(n - j - 1, k))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if sum(a) % x != 0:
		print(n)
	else:
		count1 = 0
		for i in a:
			count1 += 1
			if i % x != 0:
				break
		count2 = 0
		for i in a[::-1]:
			count2 += 1
			if i % x != 0:
				break
		val = min(count1, count2)
		ans = n - val
		if ans == 0:
			ans = -1
		print(ans)


T = int(input())
for _ in range(T):
	a = int(input())
	l = list(map(int, input().split()))
	aa = len(set(l))
	print(aa)


import sys
input = sys.stdin.readline
t = int(input())
out = []
for case in range(t):
	n = int(input())
	out.append(str(len(set(list(map(int, input().split()))))))
print('\n'.join(out))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
		continue
	(l, r) = (0, n - 1)
	while l < n and a[l] % x == 0:
		l += 1
	while r >= 0 and a[r] % x == 0:
		r -= 1
	if n - l - 1 >= r:
		mx = n - l - 1
	else:
		mx = r
	if mx == 0:
		print(-1)
		continue
	print(mx)


from collections import defaultdict

def solve():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	mapping = defaultdict(list)
	mod_arr = [0] * n
	s = 0
	last_non_zero_index = -1
	first_non_zero = -1
	non_zero_found = False
	for i in range(n):
		s += arr[i]
		mod_val = s % x
		mod_arr[i] = mod_val
		mapping[mod_val].append(i)
		if mod_val != 0:
			last_non_zero_index = i
			if not non_zero_found:
				first_non_zero = i
				non_zero_found = True
	if mod_arr[-1] != 0:
		return n
	if len(mapping) < 2 and mod_arr[0] == 0:
		return -1
	ans = last_non_zero_index + 1
	ans = max(ans, n - first_non_zero - 1, first_non_zero + 1)
	return ans

def main():
	t = int(input())
	test_case_number = 1
	while test_case_number <= t:
		print(solve())
		test_case_number += 1
main()


t = int(input())
for _ in range(t):
	(n, x) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	s = sum(arr)
	left = 0
	for i in range(0, len(arr)):
		left += 1
		if arr[i] % x != 0:
			break
	right = 0
	for i in range(len(arr) - 1, -1, -1):
		right += 1
		if arr[i] % x != 0:
			break
	if s % x != 0:
		print(len(arr))
	elif left == len(arr):
		print(-1)
	else:
		print(len(arr) - min(left, right))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	ans = []
	if s % x != 0:
		ans.append(n)
	else:
		(si, sj) = (s, s)
		for i in range(n):
			si -= a[i]
			if si % x != 0:
				ans.append(n - i - 1)
				break
		for j in reversed(range(n)):
			sj -= a[j]
			if sj % x != 0:
				ans.append(j)
				break
	if ans == []:
		print(-1)
	else:
		print(max(ans))


for _ in range(int(input())):
	ans = set()
	n = int(input())
	L = list(map(int, input().split()))
	for i in L:
		ans.add(i)
	print(len(ans))


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
rw = lambda : sys.stdin.readline().strip()
for _ in range(int(rw())):
	n = int(rw())
	a = RI()
	s = set()
	for i in a:
		s.add(i)
	print(len(s))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	d = Counter(l1)
	print(len(d))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	knt = 0
	for j in range(1, n):
		if a[j] != a[j - 1]:
			knt += 1
	print(knt + 1)


import sys, math, cmath, time
start_time = time.time()

def solve():
	(n, x) = invr()
	a = inlt()
	q = 0
	w = 0
	qq = 0
	ww = 0
	if sum(a) % x == 0:
		for i in range(len(a)):
			if a[i] % x != 0:
				if sum(a[i + 1:]) % x != 0:
					q = len(a) - i - 1
				if sum(a[:i]) % x != 0:
					w = i
				break
		a.reverse()
		for i in range(len(a)):
			if a[i] % x != 0:
				if sum(a[i + 1:]) % x != 0:
					qq = len(a) - i - 1
				if sum(a[:i]) % x != 0:
					ww = i
				break
	else:
		q = len(a)
	if max(q, w, qq, ww) == 0:
		print(-1)
	else:
		print(max(q, w, qq, ww))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

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

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

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def power_two(n):
	if n == 1:
		return True
	sttr = str(n)
	len_str = len(sttr)
	sttr = list(sttr)
	num = 0
	if len_str == 1 and sttr[len_str - 1] == '1':
		return False
	while len_str != 1 or sttr[len_str - 1] != '1':
		if (ord(sttr[len_str - 1]) - ord('0')) % 2 == 1:
			return False
		j = 0
		for i in range(len_str):
			num = num * 10 + (ord(sttr[i]) - ord('0'))
			if num < 2:
				if i != 0:
					sttr[j] = '0'
					j += 1
				continue
			sttr[j] = chr(num // 2 + ord('0'))
			j += 1
			num = num - num // 2 * 2
		len_str = j
	return True

def log_two(n):
	return math.log(n) / math.log(2)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


for _ in range(int(input())):
	(n, b) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % b != 0:
		print(n)
		continue
	x = y = -1
	for i in range(n):
		if a[i] % b != 0:
			if x == -1:
				x = i
			y = i
	if x == -1 and y == -1:
		print(-1)
	else:
		print(max(n - x - 1, y))


t = int(input())
for j in range(t):
	(n, x) = map(int, input().split())
	su = 0
	stop = 0
	mod = []
	nums = [int(i) for i in input().split()]
	for i in range(n):
		su += nums[i]
		mod.append(nums[i] % x)
	if su % x > 0:
		print(n)
	elif su % x == 0 and max(mod) == 0:
		print(-1)
	else:
		for p in range(n):
			if mod[p] > 0:
				stop = p + 1
				break
			elif mod[-(p + 1)] > 0:
				stop = p + 1
				break
			else:
				pass
		print(n - stop)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % x == 0:
		s = -1
		for i in range(n):
			if arr[i] % x != 0:
				s = i + 1
				break
		if s != -1:
			nr = arr[::-1]
			e = 0
			for i in range(n):
				if nr[i] % x != 0:
					e = i + 1
					break
			if e > s:
				print(n - s)
			else:
				print(n - e)
		else:
			print(s)
	else:
		print(n)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	arr1 = list(map(int, input().split()))
	s = set(arr1)
	print(len(s))


def f(n, a):
	b = set(a)
	return len(b)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [int(i) for i in input().split()]
		print(f(n, a))
main()


t = int(input())
for i in range(t):
	n = int(input())
	st = set(input().strip().split())
	print(len(st))


testn = int(input())
for i in range(testn):
	(arr_len, num) = map(int, input().split())
	arr = list(map(int, input().split()))
	cur = sum(arr)
	ans_len = arr_len
	if cur % num != 0:
		print(ans_len)
	else:
		while ans_len > arr_len // 2:
			if arr[ans_len - 1] % num == 0 and arr[arr_len - ans_len] % num == 0:
				ans_len -= 1
			else:
				break
		if ans_len == arr_len // 2:
			print(-1)
		else:
			print(ans_len - 1)


t = int(input())
while t != 0:
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	(sum, max) = (0, -1)
	for i in range(n):
		sum += l[i]
	if sum % x != 0:
		max = n
	else:
		sum1 = sum
		for j in range(n):
			sum1 = sum1 - l[j]
			if sum1 % x != 0:
				max = n - j - 1
				break
		sum2 = sum
		for k in range(n - 1, -1, -1):
			sum2 = sum2 - l[k]
			if sum2 % x != 0:
				if max < k:
					max = k
				break
	print(max)
	t = t - 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().rstrip('\r\n')
testcases = int(input())

def substrings(elements):
	set1 = set([])
	nums = len(elements)
	for j in range(nums):
		if not elements[j] in set1:
			set1.add(elements[j])
	return set1
for j in range(testcases):
	numel = int(input())
	elements = list(map(int, input().split()))
	set1 = substrings(elements)
	print(len(set1))


T = int(input())
for ab in range(T):
	n = int(input())
	count = 0
	a = [int(i) for i in input().split()]
	for i in set(a):
		count += 1
	print(count)


a = int(input())
for _ in range(a):
	x = int(input())
	li = list(map(int, input().split()))
	li = list(set(li))
	print(len(li))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	(l, r, s) = (-1, 0, 0)
	for i in range(n):
		if a[i] % x:
			if l == -1:
				l = i
			r = i
		s += a[i]
	if s % x:
		print(n)
	elif l == -1:
		print(-1)
	else:
		print(n - min(l + 1, n - r))


t = int(input())
while t != 0:
	n = int(input())
	array = list(map(int, input().strip().split()))[:n]
	unique_list = list(set(array))
	print(len(unique_list))
	t -= 1


for i in range(int(input())):
	num = int(input())
	l1 = list(map(int, input().split()))
	s1 = set(l1)
	print(len(s1))


t = int(input())
for x in range(t):
	n = int(input())
	lista = list(map(int, input().split()))
	s = set(lista)
	print(len(s))


t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	s = list(map(int, input().split()))
	cntr = -1
	cntl = -1
	if sum(s) % x == 0:
		i = 0
		while i < n / 2 and s[i] % x == 0:
			i += 1
		if i < n and s[i] % x:
			cntl = i
		i = n - 1
		while i >= n / 2 and s[i] % x == 0:
			i -= 1
		if s[i] % x:
			cntr = i
		if cntl != -1:
			cntl = n - cntl - 1
		n = max(cntl, cntr)
	print(n)


test = int(input())
for _ in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	s = set()
	for i in arr:
		s.add(i)
	print(len(s))


import sys, random, math
from bisect import bisect_left, bisect_right
input = sys.stdin.readline

def main():
	inf = 10 ** 20
	t = int(input())
	for _ in range(1, t + 1):
		(n, x) = map(int, input().split())
		a = [int(x) for x in input().split()]
		when = []
		(f, l) = (inf, -inf)
		if a[0] % x:
			f = min(f, 0)
			l = max(l, 0)
		for i in range(1, n):
			if a[i] % x != a[i - 1] % x:
				when.append(i)
			if a[i] % x:
				f = min(f, i)
				l = max(l, i)
		if sum(a) % x:
			print(n)
		elif f != inf:
			best = min(f + 1, n - l)
			print(n - best)
		else:
			print(-1)
main()


t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	ans = {arr[0]}
	chance = 1
	for i in range(1, len(arr)):
		if chance > n:
			break
		ans.add(arr[i])
		if arr[i - 1] <= arr[i]:
			continue
		chance += 1
	print(len(ans))


T = int(input())
for Test in range(T):
	n = int(input())
	lst = list(map(int, input().split()))
	s = sorted(list(set(lst)))
	print(len(s))


t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	ans = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			ans += 1
	print(ans)
	t -= 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	cnt_left = -1
	cnt_right = -1
	sum = 0
	flag = True
	for i in range(n):
		sum += arr[i]
		if arr[i] % x != 0:
			flag = False
	if sum % x != 0:
		print(n)
	elif flag:
		print(-1)
	else:
		for i in range(n):
			if arr[i] % x != 0:
				if cnt_left == -1:
					cnt_left = i
				cnt_right = i
		print(n - min(cnt_left + 1, n - cnt_right))


def solve(n, x, ar):
	if sum(ar) % x != 0:
		print(n)
		return
	cnt = 0
	for i in range(n):
		if ar[i] % x == 0:
			cnt += 1
	if cnt == n:
		print(-1)
		return
	ptr_i = 0
	ptr_j = n - 1
	for i in range(n // 2):
		j = n - i - 1
		if ar[i] % x != 0 or ar[j] % x != 0:
			ptr_i = i
			ptr_j = j
			break
	ans = n - min(ptr_i + 1, n - ptr_j)
	print(ans)
	return
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	ar = list(map(int, input().split()))
	solve(n, x, ar)


t = int(input())
while t > 0:
	n = int(input())
	a = map(int, input().split())
	b = set(a)
	print(len(b))
	t -= 1


def main():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = sum(arr)
	if ans % x != 0:
		print(n)
	else:
		index = -1
		index2 = -1
		for i in range(n):
			if arr[i] % x != 0:
				index = n - (i + 1)
				break
		for i in range(n - 1, -1, -1):
			if arr[i] % x != 0:
				index2 = i
				break
		print(max(index, index2))
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


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

def A():
	t = pi()
	while t:
		t -= 1
		[n, x] = ti()
		a = ti()
		for i in range(n):
			a[i] = a[i] % x
		sm = [0 for i in range(n)]
		sm[0] = a[0]
		for i in range(1, n):
			sm[i] = sm[i - 1] + a[i]
		if sm[n - 1] % x != 0:
			print(n)
			continue
		mx = 0
		for i in range(n):
			if sm[i] % x != 0:
				mx = max(mx, i + 1)
			if (sm[n - 1] - sm[i]) % x != 0:
				mx = max(mx, n - i - 1)
		if mx == 0:
			print(-1)
			continue
		print(mx)
main()


t = int(input())
while t:
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sm = 0
	l = 0
	mxl = 0
	for i in range(n):
		sm += a[i]
		l += 1
		if sm % x != 0 and l > mxl:
			mxl = l
	sm = 0
	l = 0
	for i in range(n - 1, -1, -1):
		sm += a[i]
		l += 1
		if sm % x != 0 and l > mxl:
			mxl = l
	if mxl == 0:
		print(-1)
	else:
		print(mxl)
	t = t - 1


def fun(n, x, a):
	s = sum(a)
	if s % x == 0:
		k = 0
		q = 0
		for i in range(n):
			if a[i] % x != 0:
				k = n - i - 1
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				q = i
				break
		if k == q == 0:
			return -1
		else:
			return max(k, q)
	return n
for _ in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	print(fun(n, x, a))


problems = int(input())
for problem in range(problems):
	size = int(input())
	arr = input().split(' ')
	count = 0
	se = set()
	for i in arr:
		if i not in se:
			se.add(i)
			count += 1
	print(count)


a = int(input())
for i in range(a):
	s = input()
	z = list(map(int, input().split()))
	z.sort()
	count = 1
	for i in range(1, len(z)):
		if z[i] != z[i - 1]:
			count = count + 1
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	ls.sort()
	m = n
	for j in range(1, n):
		if ls[j] == ls[j - 1]:
			m = m - 1
	print(m)


import math
from collections import defaultdict
x = int(input())
for _ in range(x):
	n = int(input())
	lol = list(map(int, input().split()))
	print(len(set(lol)))


def solve():
	n = int(input())
	arr = [int(v) for v in input().split()]
	arr.sort()
	cnt = 0
	for i in range(n):
		if i and arr[i] != arr[i - 1]:
			cnt += 1
	print(cnt + 1)
t = int(input())
for _ in range(t):
	solve()


for _ in range(0, int(input())):
	(n, k) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	s = sum(l)
	if s % k != 0:
		print(n)
	else:
		left = 0
		right = 0
		for i in range(0, n):
			if l[i] % k != 0:
				left = i + 1
				break
		l.reverse()
		for i in range(0, n):
			if l[i] % k != 0:
				right = i + 1
				break
		l.reverse()
		if left == 0 or right == 0:
			print(-1)
			continue
		if left <= right:
			print(n - left)
		else:
			print(n - right)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	ele = []
	ele = list(map(int, input().split()))
	resL = 0
	resR = 0
	flagL = -1
	flagR = -1
	for i in range(n):
		resL = resL + ele[i]
		resR = resR + ele[n - 1 - i]
		if resL % x != 0:
			flagL = i
		if resR % x != 0:
			flagR = n - 1 - i
	if flagL == -1 and flagR == -1:
		print(-1)
	if flagL >= n - flagR and flagL != -1 and (flagR != -1):
		print(flagL + 1)
	elif flagL < n - flagR and flagL != -1 and (flagR != -1):
		print(n - flagR)


for _t in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
	else:
		l = None
		r = None
		for i in range(n):
			if a[i] % x != 0:
				l = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				r = i
				break
		if l == None:
			print(-1)
		else:
			print(n - min(l + 1, n - r))


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	print(len(set(map(int, input().split()))))


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	D = {}
	for i in A:
		D[i] = 1
	print(len(D))


from sys import stdin
t = int(stdin.readline())
for z in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	ans = len(set(a))
	print(ans)


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	dat = list(map(lambda x: int(x) % k, input().split()))
	total = sum(dat) % k
	if total == 0 and all([x == 0 for x in dat]):
		print(-1)
		continue
	if total != 0:
		print(n)
		continue
	for i in range(n):
		if dat[i] != 0:
			res = n - (i + 1)
			break
	for i in range(n):
		if dat[n - 1 - i] != 0:
			res = max(res, n - (i + 1))
	print(res)


for t in range(int(input())):
	n = int(input())
	y = 1
	l = [int(i) for i in input().split()]
	l.sort()
	for i in range(1, n):
		if l[i] != l[i - 1]:
			y += 1
	print(y)


def co(arr):
	list_set = set(arr)
	unique_list = list(list_set)
	print(len(unique_list))
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	co(arr)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(1)
		continue
	else:
		a.sort()
		b = set(a)
		print(len(b))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(n)
		continue
	cnt = 0
	o = sum(l)
	for i in l:
		o = o - i
		cnt = cnt + 1
		if o % x == 0:
			pass
		else:
			break
	s1 = n - cnt
	cnt = 0
	o = sum(l)
	l = l[::-1]
	for i in l:
		o = o - i
		cnt = cnt + 1
		if o % x == 0:
			pass
		else:
			break
	s2 = n - cnt
	k = max(s1, s2)
	if k == 0:
		print(-1)
	else:
		print(k)


from collections import defaultdict
import sys
input = sys.stdin.readline

def solve(a):
	print(len(set(a)))

def main():
	t = int(input())
	for i in range(t):
		input()
		a = list(map(int, input().split()))
		solve(a)
main()


n = int(input())
for i in range(n):
	t = int(input())
	s = input().split()
	s = list(dict.fromkeys(s))
	print(len(s))


t = int(input())
while t > 0:
	n = int(input())
	l = [int(x) for x in input().split(' ')]
	s = set(l)
	print(len(s))
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	print(len(set(A)))


n = int(input())
for q in range(n):
	m = int(input())
	set_n = set(map(int, input().split()))
	print(len(set_n))


def solve():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if all([ele % x == 0 for ele in a]):
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		(l, r) = (0, n - 1)
		while a[l] % x == 0:
			l += 1
		while a[r] % x == 0:
			r -= 1
		print(max(n - l - 1, l, r, n - r - 1))
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, x) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	s = sum(arr)
	if s % x != 0:
		print(n)
	else:
		i = 0
		while i < n and arr[i] % x == 0:
			i += 1
		j = n - 1
		while j >= 0 and arr[j] % x == 0:
			j -= 1
		print(max(n - i - 1, j))


import sys
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
tests = inp()
testcount = 0
while testcount < tests:
	n = inp()
	arr = inlt()
	rra = list(set(arr))
	print(len(rra))
	testcount += 1


t = int(input())
b = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()[:n]))
	count = 0
	a.sort()
	a = list(set(a))
	b.append(len(a))
for i in b:
	print(i)


for _ in range(int(input())):
	n = int(input())
	A = [int(x) for x in input().strip().split(' ')]
	print(len(set(A)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	li = list(map(int, input().split()))
	su = sum(li)
	fsum = su
	lsum = su
	if su % x != 0:
		print(len(li))
	else:
		first = 0
		last = 0
		fcount = 1
		lcount = 1
		for i in range(len(li)):
			fsum = fsum - li[i]
			lsum = lsum - li[len(li) - 1 - i]
			if fsum % x != 0:
				break
			else:
				fcount = fcount + 1
			if lsum % x != 0:
				break
			else:
				lcount = lcount + 1
		if fcount != len(li):
			print(max(len(li) - lcount, len(li) - fcount))
		else:
			print('-1')


R = lambda : map(int, input().split())
for _ in ' ' * int(input()):
	(n, x) = R()
	a = (*R(),)
	s = sum(a)
	if s % x:
		print(n)
	else:
		l = -1
		for i in range(n):
			if a[i] % x:
				l = max(l, i, n - i - 1)
		print(l)


t = int(input())
for test in range(t):
	(n, x) = [int(x) for x in input().split()]
	nums = [int(x) for x in input().split()]
	summ = sum(nums)
	if summ % x != 0:
		print(n)
	else:
		p1 = -1
		p2 = -1
		count1 = 1
		for i in range(n):
			if nums[i] % x != 0:
				p1 = count1
				break
			count1 += 1
		count2 = 1
		for i in range(n - 1, -1, -1):
			if nums[i] % x != 0:
				p2 = count2
				break
			count2 += 1
		if p1 == -1:
			print(-1)
		else:
			delta = max(count1, count2, n - count1, n - count2)
			print(delta)


from sys import stdin
input()
for (_, line) in zip(*[iter(stdin)] * 2):
	print(len(set(line.split())))


t = int(input())
answer = []
for a in range(t):
	n = int(input())
	line = set([int(i) for i in input().split()])
	answer.append(len(line))
for b in answer:
	print(str(b))


import os
import sys, math
from io import BytesIO, IOBase

def main():
	t = int(input())
	for case in range(t):
		(n, x) = list(map(int, input().split()))
		l = list(map(int, input().split()))
		s = sum(l)
		if s % x != 0:
			print(n)
			continue
		s1 = 0
		s2 = 0
		i = 0
		while i < n:
			s1 += 1
			if l[i] % x != 0:
				break
			i += 1
		j = n - 1
		while j >= 0:
			s2 += 1
			if l[j] % x != 0:
				break
			j -= 1
		v = n - min(s1, s2)
		print(v) if v != 0 else print(-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
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, s) = list(map(int, input().split()))
		arry = list(map(int, input().split()))
		diu = sum(arry)
		if diu % s:
			yield n
		else:
			frontc = 0
			backc = 0
			(f, b) = (True, True)
			for i in range(n):
				front = arry[i]
				back = arry[n - 1 - i]
				if f:
					frontc += 1
				if front % s:
					f = False
				if b:
					backc += 1
				if back % s:
					b = False
			diulei = n - min(frontc, backc)
			if diulei:
				yield diulei
			else:
				yield (-1)
t = int(input())
ans = gift()
print(*ans, sep='\n')


cases = int(input())
for case in range(cases):
	n = int(input())
	l = set(sorted(list(map(int, input().split()))))
	print(len(l))


out = []
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	if sum(a) % x != 0:
		out.append(n)
		continue
	l = 0
	while l < n and a[l] % x == 0:
		l += 1
	if l == n:
		out.append(-1)
		continue
	r = n - 1
	while r > -1 and a[r] % x == 0:
		r -= 1
	out.append(max(n - l - 1, r))
for i in out:
	print(i)


def main():
	n = int(input())
	a = [int(s) for s in input().split()]
	a.sort()
	count = 1
	for i in range(len(a) - 1):
		if a[i] != a[i + 1]:
			count += 1
	return count
t = int(input())
for i in range(t):
	print(main())


t = int(input())
while t:
	(n, x) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	tot = sum(a)
	init = n
	flag = 0
	ans = -1
	if tot % x != 0:
		ans = init
	else:
		start = 0
		end = n - 1
		while start <= end:
			if a[start] % x != 0:
				ans = init - 1
				break
			if a[end] % x != 0:
				ans = init - 1
				break
			start += 1
			end -= 1
			init -= 1
	print(ans)
	t -= 1


for i in range(int(input())):
	d = int(input())
	s = [int(i) for i in input().split()]
	s = set(s)
	print(len(s))


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = Counter(l)
	print(len(c.keys()))


import math
for i in range(int(input())):
	(n, x) = (int(i) for i in input().split())
	a = [int(i) for i in input().split()]
	sa = sum(a)
	if n == 1 and a[0] % x == 0:
		print(-1)
	elif sa % x != 0:
		print(n)
		continue
	else:
		d = False
		A = 0
		B = 0
		for i in range(n):
			A += a[i]
			B += a[n - i - 1]
			if A % x != 0 or B % x != 0:
				print(n - i - 1)
				d = True
				break
		if not d:
			print(-1)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % x != 0:
		print(n)
	else:
		left = -1
		right = -1
		for i in range(n):
			if arr[i] % x != 0:
				left = i
				break
		for i in range(n - 1, -1, -1):
			if arr[i] % x != 0:
				right = i
				break
		if left == -1:
			print(-1)
			continue
		maxlen = min(left + 1, n - right)
		print(n - maxlen)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	for i in l:
		if i % k == 0:
			c += 1
	if c == n:
		print(-1)
	else:
		s = sum(l)
		if s % k != 0:
			print(n)
		else:
			f = False
			m = n
			for i in l:
				s -= i
				m -= 1
				if s % k != 0:
					break
			s = sum(l)
			for i in l[::-1]:
				s -= i
				n -= 1
				if s % k != 0:
					break
			print(max(m, n))


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		arr.sort()
		res = 0
		for i in range(len(arr)):
			if i == 0:
				res += 1
				continue
			if arr[i] != arr[i - 1]:
				res += 1
		stdout.write(str(res) + '\n')
main()


import sys
inp = sys.stdin.readline

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

def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		a = set(lin())
		print(len(a))
main()


t = int(input())
for test in range(t):
	(n, x) = [int(k) for k in input().split()]
	arr = [int(k) for k in input().split()]
	tot = 0
	finish = False
	finish2 = False
	for i in arr:
		tot += i
	if tot % x != 0:
		print(n)
	else:
		num = n
		ans = 0
		for i in range(n):
			if (tot - arr[i]) % x != 0:
				num -= 1
				tot -= arr[i]
				ans = num
				finish = True
				break
			else:
				num -= 1
		if finish == False:
			ans = -1
		ans2 = 0
		num = n
		arr = arr[::-1]
		tot = sum(arr)
		for i in range(n):
			if (tot - arr[i]) % x != 0:
				num -= 1
				tot -= arr[i]
				ans2 = num
				finish2 = True
				break
			else:
				num -= 1
		if finish2 == False:
			ans2 = -1
		print(max(ans, ans2))


for T in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	i = 0
	j = n - 1
	if s % k != 0:
		print(j - i + 1)
	else:
		for i in range(n // 2 + 1):
			if a[i] % k != 0 or a[-i - 1] % k != 0:
				print(n - i - 1)
				break
		else:
			print(-1)


a = int(input())
for i in range(a):
	b = int(input())
	c = input()
	myset1 = set(c.split())
	print(len(myset1))


import io
import os
import sys
from atexit import register
import random
import math
import itertools
DEBUG = False
STRESSTEST = False
if not DEBUG:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	if type(tokens[tokens_next - 1]) == str:
		return tokens[tokens_next - 1]
	return tokens[tokens_next - 1].decode()

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(*argv, end='\n'):
	for arg in argv:
		sys.stdout.write((str(arg) + ' ').encode())
	sys.stdout.write(end.encode())

def genTestCase():
	raise NotImplementedError

def bruteforce(a):
	raise NotImplementedError

def doStressTest():
	while True:
		curTest = genTestCase()
		mySoln = solve(curTest)
		bruteforceSoln = bruteforce(curTest)
		if mySoln != bruteforceSoln:
			print('### Found case ###')
			print(curTest)
			print(f'{mySoln} should have been: {bruteforceSoln}')
			return

def solve(a):
	return len(set(a))
if not DEBUG and STRESSTEST:
	raise Exception('Wrong flags!')
if STRESSTEST:
	doStressTest()
else:
	t = nextInt()
	for _ in range(t):
		a = nextIntArr(nextInt())
		res = solve(a)
		print(res)
sys.stdout.flush()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [0]
	s = set(l)
	print(len(s))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	(s, k) = (0, -1)
	for (i, x) in enumerate(map(int, input().split())):
		s += x
		if x % m:
			k = max(k, max(n - 1 - i, i))
	print([n, k][s % m == 0])


for i in range(int(input())):
	t = int(input())
	l = [int(x) for x in input().split()]
	l.sort()
	k = set(l)
	print(len(k))


T = int(input())
for i in range(T):
	n = int(input())
	l = [int(x) for x in input().split()]
	l.sort()
	c = 0
	for j in range(0, len(l)):
		if j != 0 and l[j] == l[j - 1]:
			continue
		c = c + 1
	print(c)


t = int(input())
while t != 0:
	a = int(input())
	b = list(map(int, input().split(' ')))
	c = set(b)
	print(len(c))
	t = t - 1


t = int(input())
L = []
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	L.append(len(set(A)))
for i in L:
	print(i)


t = int(input())
for _ in range(t):
	(n, x) = [int(i) for i in input().split(' ')]
	a = [int(i) for i in input().split(' ')]
	min_div = -1
	max_div = -1
	sum = 0
	for i in range(n):
		sum += a[i]
		if min_div == -1 and a[i] % x != 0:
			min_div = i
			max_div = i
		if min_div != -1 and a[i] % x != 0:
			max_div = max(i, max_div)
	if sum % x != 0:
		print(n)
	elif min_div == -1:
		print(-1)
	else:
		nearest = min(min_div + 1, n - max_div)
		print(n - nearest)


def answer(arr, x):
	n = len(arr)
	_sum = sum(arr)
	if _sum % x != 0:
		return n
	_max = -1
	rightSum = _sum
	leftSum = 0
	for i in range(n - 1):
		leftSum += arr[i]
		rightSum -= leftSum
		if leftSum % x != 0:
			_max = max(_max, i + 1)
		if rightSum % x != 0:
			_max = max(_max, n - (i + 1))
	return _max
testCount = int(input())
for _ in range(testCount):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(answer(arr, x))


from sys import stdin, stdout
in1 = int(stdin.readline())
for i in range(in1):
	in2 = stdin.readline()
	in3 = stdin.readline()
	in3 = in3.split()
	l = len(set(in3))
	stdout.write(str(l) + '\n')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
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
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

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

def out(*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(l()[0]):
	(n, x) = l()
	A = l()
	s = sum(A)
	if s % x:
		print(n)
		continue
	i = 0
	j = n - 1
	while i < n and A[i] % x == 0:
		i += 1
	i += 1
	while j >= 0 and A[j] % x == 0:
		j -= 1
	ans = max(n - i, j)
	if ans == 0:
		ans = -1
	print(ans)


t = int(input())
ans = []
while t:
	n = int(input())
	a = list(map(int, input().split()))
	k = -1
	cum = 0
	a.sort()
	for i in range(n):
		if a[i] > k:
			k = a[i]
			cum += 1
	print(cum)
	t -= 1


s = int(input())
while s != 0:
	(n, x) = map(int, input().split())
	li = list(map(int, input().split()))
	(sum3, max3) = (0, -1)
	for i in range(n):
		sum3 += li[i]
	if sum3 % x != 0:
		max3 = n
	else:
		sum1 = sum3
		for j in range(n):
			sum1 = sum1 - li[j]
			if sum1 % x != 0:
				max3 = n - j - 1
				break
		sum2 = sum3
		for k in range(n - 1, -1, -1):
			sum2 = sum2 - li[k]
			if sum2 % x != 0:
				if max3 < k:
					max3 = k
				break
	print(max3)
	s = s - 1


def longestSequence(arr, n):
	mp = {}
	for i in range(n):
		if arr[i] in mp:
			mp[arr[i]] += 1
		else:
			mp[arr[i]] = 1
	return len(mp)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(longestSequence(arr, n))


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

def solve():
	n = int(input().strip())
	A = [int(s) for s in input().strip().split()]
	result = len(set(A))
	print(result)

def main():
	for _ in range(int(input().strip())):
		solve()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


m = int(input())
for i in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	cnt = 0
	x = -1
	a.sort()
	for j in a:
		if j != x:
			cnt += 1
		x = j
	print(cnt)


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	ret = i = 0
	while i < n - 1 and arr[i] % x == 0:
		i += 1
	ret = n - i - 1
	i = n - 1
	while i > 0 and arr[i] % x == 0:
		i -= 1
	ret = max(ret, i)
	if ret == 0:
		ret = -1
	print(ret)


t = int(input())
for k in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	print(len(list(set(arr))))


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints
t = read_int()
for i in range(t):
	n = read_int()
	a = read_ints()
	print(len(set(a)))


t = int(input())
s = ''
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	li1 = list(set(li))
	s += str(len(li1)) + ' '
print(s.replace(' ', '\n'))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	(f, i) = (0, 0)
	j = n - 1
	if sum(lst) % x != 0:
		print(n)
	else:
		for i in range(n // 2 + 1):
			if lst[i] % x != 0 or lst[n - 1 - i] % x != 0:
				print(n - 1 - i)
				break
		else:
			print(-1)


t = int(input())
while t != 0:
	n = input()
	print(len(set(input().split())))
	t -= 1


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

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

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l
import statistics

def main():
	t = inin()
	for _ in range(t):
		n = inin()
		a = ain()
		a = list(set(a))
		print(len(a))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


def merge(arr, l, m, r):
	arr1 = []
	arr2 = []
	i = 0
	j = 0
	k = 0
	n1 = m - l + 1
	n2 = r - m
	for i in range(n1):
		arr1.append(arr[l + i])
	for j in range(n2):
		arr2.append(arr[m + j + 1])
	i = 0
	j = 0
	k = l
	while i < n1 and j < n2:
		if arr1[i] <= arr2[j]:
			arr[k] = arr1[i]
			i += 1
		else:
			arr[k] = arr2[j]
			j += 1
		k += 1
	while i < n1:
		arr[k] = arr1[i]
		i += 1
		k += 1
	while j < n2:
		arr[k] = arr2[j]
		j += 1
		k += 1

def merge_sort(arr, l, r):
	if l < r:
		m = l + (r - l) / 2
		merge_sort(arr, l, m)
		merge_sort(arr, m + 1, r)
		merge(arr, l, m, r)
t = int(input())
for q in range(t):
	n = int(input())
	arr = []
	arr = [int(i) for i in input().split()][:n]
	arr.sort()
	ctr = 0
	last_one = -1
	for i in range(len(arr)):
		if last_one != arr[i]:
			last_one = arr[i]
			ctr += 1
	print(ctr)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	data = [int(x) for x in input().split()]
	temp = sum(data)
	if temp % x:
		print(n)
		continue
	(l, r) = (0, 0)
	while l < n and data[l] % x == 0:
		l += 1
	while r < n and data[n - r - 1] % x == 0:
		r += 1
	print(n - min(l, r) - 1)


t = int(input())

def prefix(n, l, sums):
	for i in range(n):
		sums -= l[i]
		if sums % x != 0:
			return n - i - 1
	else:
		return -1

def suffix(n, l, sums):
	for i in range(n):
		sums -= l[n - i - 1]
		if sums % x != 0:
			return n - i - 1
	else:
		return -1
for _ in range(t):
	(n, x) = map(int, input().split())
	l = [*map(int, input().split())]
	sums = sum(l)
	if sums % x != 0:
		print(n)
	else:
		print(max(suffix(n, l, sums), prefix(n, l, sums)))


import re
t = int(input())
for testcase in range(t):
	n = int(input())
	a = input().split()
	newa = list(dict.fromkeys(a))
	print(len(newa))


T = int(input())
for t in range(T):
	x = int(input())
	A = list(map(int, input().split()))
	mp = {}
	count = 0
	for a in A:
		if a not in mp.keys():
			count += 1
			mp.update({a: 1})
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = len(set(a))
	print(s)


t = int(input())
sol = []
set1 = set()
for i in range(t):
	set1.clear()
	n = int(input())
	s = input()
	s = s.split()
	set1 = set(s)
	sol.append(len(set1))
for i in sol:
	print(i)


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split())
t = read_int()
for _ in range(t):
	(n, x) = read_ints()
	a = []
	a = list(read_ints())
	y = 99999999999
	sum = 0
	yy = 0
	xx = 0
	for i in range(n):
		sum += a[i]
	if sum % x != 0:
		print(n)
	else:
		d = sum
		for i in range(n):
			sum -= a[i]
			if sum % x != 0:
				xx = n - i - 1
				break
		sum = d
		for i in range(n - 1, -1, -1):
			sum -= a[i]
			if sum % x != 0:
				yy = i
				break
		xx = max(xx, yy)
		if xx > 0:
			print(xx)
		else:
			print(-1)


from sys import stdin
a = int(stdin.readline())
for k in range(0, a):
	b = int(stdin.readline())
	c = stdin.readline().split()
	d = set(c)
	e = len(d)
	print(e)


for xyz in range(0, int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	r = []
	s = 0
	for i in range(0, n):
		if l[i] % x != 0:
			r.append(i)
		s += l[i]
	if len(r) == 0:
		print(-1)
	else:
		st = r[0]
		en = r[-1]
		if s % x != 0:
			print(n)
		else:
			print(max(st + 1, n - st - 1, en, n - en))


for pratyush in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] %= x
	l = list(set(a))
	if len(l) == 1 and l[0] == 0:
		print(-1)
	elif sum(a) % x:
		print(n)
	else:
		for i in range(n):
			if a[i] != 0:
				m = i
				break
		a = a[::-1]
		for i in range(n):
			if a[i] != 0:
				m = min(m, i)
				break
		print(n - m - 1)


t = input()
for q in range(int(t)):
	x = input()
	s = set(input().split(' '))
	print(len(s))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % k != 0:
		print(n)
		continue
	else:
		left = 0
		right = n - 1
		ans = -1
		while left <= right:
			if arr[right] % k != 0:
				ans = right
				break
			if arr[left] % k != 0:
				ans = n - left - 1
				break
			left += 1
			right -= 1
	print(ans)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

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

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	l = 0
	res1 = n
	while l < n and s % x == 0:
		res1 -= 1
		s -= arr[l]
		l += 1
	s = sum(arr)
	r = n - 1
	res2 = n
	while r >= 0 and s % x == 0:
		res2 -= 1
		s -= arr[r]
		r -= 1
	if max(res1, res2) == 0:
		print(-1)
	else:
		print(max(res1, res2))
t = int(input())
for _ in range(t):
	main()


def solve(seq, n):
	print(len(sorted(set(seq))))

def citire():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = [int(x) for x in input().split()]
		solve(arr, n)
citire()


for i in range(int(input())):
	(a, b) = map(int, input().split())
	t = list(map(int, input().split()))
	y = []
	if sum(t) % b != 0:
		print(a)
	else:
		(x, y) = (0, 0)
		d = 0
		for k in range(a):
			d += 1
			if t[k] % b != 0:
				break
			if t[-(k + 1)] % b != 0:
				break
		if d == 0 or d == a:
			print(-1)
		else:
			print(len(t) - d)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	al = list(map(int, input().split()))
	sal = list(set(al))
	sal.sort()
	d = defaultdict(lambda : 0)
	for (i, a) in enumerate(al):
		d[str(a)] = min(i, d[str(a)])
	pre_i = -1
	ans = 0
	i = 0
	for a in sal:
		if i > n:
			break
		elif pre_i < d[str(a)]:
			pre_i = d[str(a)]
			ans += 1
		else:
			i += 1
	print(i + 1)


for i in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	d = set(x)
	print(len(d))


t = int(input())
for oo in range(t):
	n = int(input())
	a = [int(aaa) for aaa in input().split()]
	m = len(set(a))
	print(m)


import math as m

def f1():
	Testcases = int(input())
	for i in range(0, Testcases):
		x = int(input())
		print(str(x - 1) + str(' ') + str(1))

def f2():
	Testcases = int(input())
	for i in range(0, Testcases):
		n = int(input())
		array = [int(j) for j in input().split(' ')]
		answer = len(array)
		dict1 = dict()
		for k in array:
			if k in dict1:
				answer = answer - 1
			else:
				dict1[k] = 1
		print(answer)
f2()


from math import *
import sys, random

def nextInt():
	return int(input())

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

def nextInts():
	return list(map(int, nextStrs()))

def main():
	t = nextInt()
	for _ in range(t):
		n = nextInt()
		print(len(set(nextInts())))
exit(main())


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 0
	s = sum(a)
	p = n
	flag = 0
	l = -1
	r = -1
	if s % x != 0:
		print(p)
	else:
		while i < n:
			if a[i] % x != 0:
				if flag == 0:
					l = i
					r = i
					flag = 1
				else:
					r = i
			i += 1
		if l == r == -1:
			print(-1)
		else:
			print(n - min(l + 1, n - r))


R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
for _ in range(R2()):
	(n, x) = R1()
	A = R1()
	s = 0
	(f, l) = (-1, 0)
	for i in range(n):
		s += A[i]
		if A[i] % x != 0:
			if f == -1:
				f = i
			l = i
	if s % x != 0:
		print(n)
	elif f == -1:
		print(f)
	else:
		print(n - min(f + 1, n - l))


t = int(input())
out = list()
for item in range(t):
	n = int(input())
	a_list = input().split()
	out.append(len(set(a_list)))
for item in out:
	print(item)


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


for testcase in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	start = 0
	for i in arr:
		if not i % x:
			start += 1
		else:
			break
	end = 0
	for i in arr[::-1]:
		if not i % x:
			end += 1
		else:
			break
	if start == end == len(arr):
		print(-1)
		continue
	else:
		total = sum(arr)
		if not total % x:
			print(len(arr) - min(start, end) - 1)
		else:
			print(len(arr))


t = int(input())
while t > 0:
	n = int(input())
	a = str(input())
	a = list(set(a.split()))
	print(len(a))
	t -= 1


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, x) = [int(x) for x in inp().split()]
	a = [int(x) for x in inp().split()]
	ans = len(a)
	l = 0
	h = n - 1
	if sum(a) % x != 0:
		print(ans)
	else:
		b = -1
		c = -1
		for i in range(n):
			if a[i] % x != 0:
				b = i
				break
		if b == -1:
			print(-1)
			continue
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				c = i
				break
		best = ans - min(b + 1, c + 1, n - b, n - c)
		print(best)


for _ in range(int(input())):
	t = int(input())
	q = len(list(set([int(x) for x in input().split()])))
	print(q)


for nt in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
		continue
	(f, s) = (-1, -1)
	for i in range(n):
		if a[i] % x != 0:
			f = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x != 0:
			s = i
			break
	if f == -1:
		print(-1)
		continue
	print(n - min(f + 1, n - s))


t = int(input().strip())
for _ in range(t):
	(n, x) = [int(a) for a in input().strip().split()]
	l = [int(a) for a in input().strip().split()]
	f = 0
	temp = 0
	for i in range(n):
		temp += l[i]
	if temp % x != 0:
		print(n)
		continue
	left = 0
	right = 0
	for i in range(n):
		if l[i] % x != 0:
			break
		left += 1
	left += 1
	for i in range(n - 1, -1, -1):
		if l[i] % x != 0:
			break
		right += 1
	right += 1
	print(n - min(left, right))


T = int(input())
for _ in range(T):
	(N, X) = map(int, input().split())
	A = list(map(int, input().split()))
	arr = [0]
	for a in A:
		arr.append((arr[-1] + a) % X)
	tmp = tmp2 = -1
	for i in range(N + 1):
		if arr[i] != arr[-1]:
			tmp = N - i
			break
	for i in range(N + 1):
		if arr[N - i] != arr[0]:
			tmp2 = N - i
			break
	print(max(tmp, tmp2))


import math
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = len(set(l))
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(map(int, input().split()))
	ans = -1
	cs = 0
	for i in range(n):
		cs += s[i]
		if cs % x:
			ans = max(ans, i + 1)
	cs = 0
	for i in range(n - 1, -1, -1):
		cs += s[i]
		if cs % x:
			ans = max(ans, n - i)
	print(ans)


import math
import sys
import re
n = int(input())
for y in range(n):
	a = int(input())
	l = list(map(int, input().rstrip().split()))
	setl = set(l)
	print(len(list(setl)))


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	d = 1
	c.sort()
	for j in range(b - 1):
		if c[j] != c[j + 1]:
			d += 1
	print(d)


def cast(cre, typ):
	return type(typ)(map(cre, typ))

def solution():
	for t in range(int(input())):
		(n, x) = cast(int, input().split())
		arr = cast(int, input().split())
		val = sum(arr)
		d1 = 0
		d2 = 0
		if val % x == 0:
			for e in arr:
				d1 += 1
				if e % x != 0:
					break
			for e in arr[::-1]:
				d2 += 1
				if e % x != 0:
					break
		d = min([d1, d2])
		if n == d:
			print(-1)
		else:
			print(n - d)
solution()


t = int(input())
while t:
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	ans = 0
	flag = 0
	if s % m == 0:
		for i in range(n // 2):
			if a[i] % m != 0 or a[n - i - 1] % m != 0:
				ans = i
				flag = 1
				break
		if flag == 0:
			print(-1)
		else:
			print(n - ans - 1)
	else:
		print(n)
	t = t - 1


def solve():
	(n, x) = [int(i) for i in input().split()]
	lst = [int(j) for j in input().split()]
	s = sum(lst)
	if s % x != 0:
		print(n)
	else:
		flag1 = flag2 = 0
		for j in range(n):
			if lst[j] % x != 0:
				flag1 = j + 1
				break
		for j in range(n - 1, -1, -1):
			if lst[j] % x != 0:
				flag2 = n - j
				break
		if flag1:
			print(n - min(flag1, flag2))
		else:
			print(-1)
q = int(input())
for k in range(q):
	solve()


def longestIncreasingSubsequence(arr):
	return len(set(arr))
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(longestIncreasingSubsequence(arr))


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % r
	x = -1
	for i in range(n):
		if a[i] != 0:
			x = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] != 0:
			y = i
			break
	if x == -1:
		print(-1)
	else:
		z = sum(a)
		if z % r != 0:
			print(n)
		else:
			print(max(n - x - 1, y))


t = int(input())
while t:
	x = int(input())
	l = set(map(int, input().split()))
	print(len(l))
	t -= 1


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	if sum(lst) % x != 0:
		print(len(lst))
	else:
		for s in lst:
			if s % x != 0:
				n1 = len(lst) - lst.index(s) - 1
				break
			else:
				continue
		else:
			n1 = 0
		lst.reverse()
		for s in lst:
			if s % x != 0:
				n2 = len(lst) - lst.index(s) - 1
				break
			else:
				continue
		else:
			n2 = 0
		if n1 == 0 and n2 == 0:
			print(-1)
		else:
			print(max(n1, n2))


b = []
x = []
from collections import OrderedDict
w = int(input())
for i in range(w):
	n = int(input())
	b.extend((int(x) for x in input().split()))
	x.append(len(list(OrderedDict.fromkeys(b))))
	b = []
for i in x:
	print(i)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = len(set(arr))
	print(ans)


t = int(input())
for case in range(t):
	input()
	nums = set(map(int, input().split()))
	print(len(nums))


test_case = int(input())
for _ in range(test_case):
	(size, div) = map(int, input().split())
	arr = list(map(int, input().split()))
	total = sum(arr)
	if total % div:
		print(len(arr))
	else:
		(start, end) = (0, len(arr) - 1)
		total_sum = total
		for i in range(len(arr)):
			if total_sum % div == 0:
				start += 1
				total_sum -= arr[i]
			else:
				break
		for i in range(len(arr) - 1, -1, -1):
			if total % div == 0:
				end -= 1
				total -= arr[i]
			else:
				break
		start = len(arr) - start
		final = max(start, end + 1)
		if final:
			print(final)
		else:
			print(-1)


p = []
t = int(input())
for i in range(t):
	n = int(input())
	l = []
	l = [int(x) for x in input().split()]
	d = len(set(l))
	p.append(d)
for x in p:
	print(x)


t = int(input())
while t:
	(n, s) = map(int, input().split())
	l = []
	l = list(map(int, input().split()))
	ss = sum(l)
	if ss % s != 0:
		print(n)
	else:
		ans = n
		ans2 = n
		for i in range(0, n):
			ans = ans - 1
			if l[i] % s != 0:
				break
		for i in range(n - 1, -1, -1):
			ans2 -= 1
			if l[i] % s != 0:
				break
		if ans == 0 and ans2 == 0:
			print(-1)
		else:
			print(max(ans, ans2))
	t -= 1


kr = int(input())
for tkr in range(kr):
	(n, m) = map(int, input().split())
	b = []
	s = 0
	for i in input().split():
		i = int(i)
		b += [i]
		s += i
	if s % m != 0:
		print(n)
	else:
		pr = 0
		for i in range((n + 1) // 2):
			if b[i] % m != 0 or b[n - 1 - i] % m != 0:
				pr = 1
				break
		if pr:
			print(n - i - 1)
		else:
			print(-1)


def longest(n, x, a):
	i = 0
	j = n - 1
	if sum(a) % x != 0:
		return n
	a = [elem % x for elem in a]
	if sum(a) == 0:
		return -1
	else:
		while a[i] == 0:
			i += 1
		while a[j] == 0:
			j -= 1
	return max(j, n - 1 - i)
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	print(longest(n, x, a))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = [int(x) for x in input().split()]
	d = [c[0] % b]
	e = [c[-1] % b]
	for x in c[1:]:
		d.append((d[-1] + x) % b)
	for x in reversed(c[:-1]):
		e.append((e[-1] + x) % b)
	if d[-1] > 0 or e[-1] > 0:
		print(a)
		continue
	if sum(d) == 0:
		print(-1)
		continue
	cnt = a
	for x in range(a - 1, -1, -1):
		if d[x] > 0 or e[x] > 0:
			print(cnt)
			break
		else:
			cnt -= 1


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, x) = [int(i) for i in sys.stdin.readline().split()]
	arr = [int(i) for i in sys.stdin.readline().split()]
	cur = sum(arr)
	if cur % x != 0:
		print(n)
	else:
		front_removed = 0
		for i in arr:
			front_removed += 1
			if i % x != 0:
				break
		back_removed = 0
		for i in arr[::-1]:
			back_removed += 1
			if i % x != 0:
				break
		if min(back_removed, front_removed) == n:
			print(-1)
		else:
			print(n - min(back_removed, front_removed))


import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	(n, k) = ip()
	x = ip()
	rem = [0] * n
	for i in range(n):
		rem[i] = x[i] % k
	if rem == [0] * n:
		print(-1)
		continue
	if sum(x) % k:
		print(n)
		continue
	for i in range(n):
		if rem[i]:
			break
	ans = n - 1 - i
	for i in reversed(range(n)):
		if rem[i]:
			break
	ans = max(ans, i)
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	strt_sum = []
	end_sum = []
	m = 0
	k = 0
	for i in range(n):
		m += l[i]
		k += l[-1 - i]
		strt_sum.append(m)
		end_sum.append(k)
	flag = 0
	ct = 0
	if strt_sum[-1] % x != 0 or end_sum[-1] % x != 0:
		flag = 2
		print(n)
	n = n - 1
	while n > 0 and flag == 0:
		if (strt_sum[-1] - strt_sum[ct]) % x != 0:
			flag = 1
		elif (end_sum[-1] - end_sum[ct]) % x != 0:
			flag = 1
		ans = n
		n -= 1
		ct += 1
	if flag == 1:
		print(ans)
	elif flag == 0:
		print(-1)


t = int(input())
anss = [0] * t
for i in range(t):
	_ = input()
	anss[i] = len(set(map(int, input().split())))
for ans in anss:
	print(ans)


import sys
from fractions import gcd
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _t in range(cin()):
	(n, x) = mi()
	a = li()
	sm = sum(a)
	if sm % x != 0:
		print(n)
		continue
	ans1 = n
	ans2 = n
	(i, j) = (0, n - 1)
	for i in range(n):
		ans1 -= 1
		if a[i] % x != 0:
			break
	for i in range(n - 1, -1, -1):
		ans2 -= 1
		if a[i] % x != 0:
			break
	if max(ans1, ans2) != 0:
		print(max(ans2, ans1))
	else:
		print(-1)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
li = lambda : list(map(int, input().split()))

def case():
	n = int(input())
	a = li()
	print(len(set(a)))
for _ in range(int(input())):
	case()


n = int(input())
for i in range(n):
	m = int(input())
	a = list(set(map(int, input().split())))
	a.sort()
	print(len(a))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	op = -1
	if sum(a) % x != 0:
		print(n)
	elif sum(a) % x == 0:
		c = 0
		for i in range(n):
			if a[i] % x == 0:
				c += 1
		if c == n:
			print('-1')
		else:
			l = 0
			r = 0
			i = 0
			while a[i] % x == 0:
				l += 1
				i += 1
			i = n - 1
			while a[i] % x == 0:
				i -= 1
				r += 1
			print(n - min(l + 1, r + 1))


from collections import Counter
t = int(input())
for tests in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = len(Counter(a).keys())
	print(l)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % x != 0:
		print(n)
	else:
		eigen1 = -1
		eigen2 = -1
		for i in range(n):
			if arr[i] % x != 0:
				eigen1 = i
				break
		if eigen1 == -1:
			print(eigen1)
			continue
		for i in range(n - 1, -1, -1):
			if arr[i] % x != 0:
				eigen2 = i
				break
		print(max(n - eigen1 - 1, eigen2))


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
krish = 1
raj = krish * 100
ans = krish - 90
for _ in range(t):
	(n, x) = [int(x) for x in input().split()]
	l = list([int(x) for x in input().split()])
	f = 0
	sum = 0
	for i in l:
		sum += i
		if i % x != 0:
			f = 1
	if f == 0:
		print('-1')
	elif sum % x != 0:
		print(n)
	else:
		lb = 0
		ub = n - 1
		while l[lb] % x == 0:
			lb += 1
		while l[ub] % x == 0:
			ub -= 1
		ub = n - ub - 1
		print(n - min(lb, ub) - 1)
		ans -= 5


for cas in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x:
		print(n)
	else:
		for i in range(n):
			if a[i] % x or a[n - i - 1] % x:
				print(n - i - 1)
				break
		else:
			print(-1)


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	print(len(set(a)))


a = int(input())
for _ in range(a):
	(b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % c != 0:
		print(b)
		continue
	x = 0
	z = 0
	y = 0
	for i in range(b):
		if l[i] % c != 0:
			z += 1
			x += i
			break
		if l[b - i - 1] % c != 0:
			y += b - i - 1
			break
	if z == 0 and y == 0:
		print(-1)
	if z == 1:
		print(b - x - 1)
	if y > 1:
		print(y)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x == 0:
		ans = -1
		for i in range(n):
			if a[i] % x:
				ans = max(ans, n - i - 1, i)
		print(ans)
	else:
		print(n)


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

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

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		k = I()
		l = list(set(LI()))
		ans.append(len(l))
	for x in ans:
		print(x)
main()


n = int(input())
for i in range(n):
	x = int(input())
	a = list(map(int, input().split()))
	a.sort()
	p = 1
	for w in range(len(a) - 1):
		if a[w] != a[w + 1]:
			p += 1
	print(p)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) % x for i in input().split()]
	if sum(a) == 0:
		print(-1)
	elif sum(a) % x:
		print(n)
	else:
		b = [i for i in range(n) if a[i]]
		print(max(n - b[0] - 1, b[-1]))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = 0
	r = 0
	s = a[0]
	ans = -1
	while l <= r and r < n:
		if s % x == 0 and r < n - 1:
			s += a[r + 1]
			r += 1
		elif s % x == 0 and r == n - 1:
			s -= a[l]
			l += 1
		elif s % x != 0 and r < n - 1:
			ans = max(ans, r - l + 1)
			s += a[r + 1]
			r += 1
		elif s % x != 0 and r == n - 1:
			ans = max(ans, r - l + 1)
			break
	print(ans)


def solve():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	i = 0
	j = n - 1
	s = sum(arr)
	if s % x != 0:
		return n
	while i < j:
		if arr[i] % x != 0:
			return n - i - 1
		elif arr[j] % x != 0:
			return j
		i += 1
		j -= 1
	return -1
for _ in range(int(input())):
	print(solve())


t = int(input())
for i in range(t):
	s = input().split()
	n = int(s[0])
	x = int(s[1])
	s = input().split()
	for j in range(n):
		s[j] = int(s[j])
	l = []
	for j in range(n):
		if s[j] % x == 0:
			l.append(0)
		else:
			l.append(1)
	d = sum(s)
	c = sum(l)
	if c == 0:
		print('-1')
		continue
	if d % x != 0:
		print(n)
		continue
	a = -1
	b = -1
	a = l.index(1)
	l1 = l[::-1]
	b = l1.index(1)
	p = n - min(a, b) - 1
	print(p)


kl = int(input())
for l in range(kl):
	n = int(input())
	A = set()
	for i in input().split():
		i = int(i)
		A.add(i)
	print(len(A))


for _ in range(int(input())):
	n = int(input())
	a = [int(__) for __ in input().split()]
	print(len(set(a)))


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

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

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

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

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	l = sorted(li())
	ans = 1
	for i in range(1, n):
		if l[i] > l[i - 1]:
			ans += 1
	print(ans)


t = int(input())
alen = []
data = []
for x in range(t):
	alen.append(int(input()))
	data.append(list(map(int, input().split(None, alen[x])[:alen[x]])))
	print(len(list(set(data[x]))))


from sys import stdin as cin
lmap = lambda f, v: list(map(f, v))
OPC = {2 ** i: (i - 1) // 3 + 1 for i in range(60)}

def len_of_subarray(a, x):
	l = len(a)
	if sum(a) % x != 0:
		return l
	for i in range(l // 2 + 1):
		if a[i] % x != 0 or a[l - 1 - i] % x != 0:
			return l - i - 1
	return -1

def main():
	t = int(next(cin).strip())
	for i in range(t):
		(n, x) = lmap(int, next(cin).strip().split())
		a = lmap(int, next(cin).strip().split())
		print(len_of_subarray(a, x))
main()


t = int(input())
for test in range(t):
	n = int(input())
	a = input().split()
	without_copies = set(a)
	print(len(without_copies))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = -1
	sum = 0
	c = 0
	for i in range(n):
		if a[i] % x != 0:
			if l == -1:
				l = i
			k = i
			c += 1
		sum += a[i]
	if sum % x != 0:
		print(n)
	elif l == -1:
		print(-1)
	else:
		print(n - min(l + 1, n - k))


t = int(input())
while t != 0:
	n = int(input())
	x = [int(i) for i in input().split()]
	y = set(x)
	print(len(y))
	t = t - 1


a = int(input())
for i in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	print(len(set(c)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	T = [0]
	P = [0]
	T += list(map(int, input().split()))
	suma = 0
	for i in range(1, n + 1):
		suma += T[i]
		suma %= x
		P.append(suma)
	wynik = -1
	for i in range(n, 0, -1):
		if P[i] != 0:
			wynik = max(wynik, i)
	for i in range(0, n + 1):
		if P[i] != P[n]:
			wynik = max(wynik, n - i)
	print(wynik)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	hi = 1 if a[0] % x else -1
	seenR = {a[0] % x: 0}
	for i in range(1, n):
		if a[i] % x:
			hi = max(hi, 1)
		a[i] += a[i - 1]
		r = a[i] % x
		if r not in seenR:
			seenR[r] = i
		if r:
			hi = i + 1
			continue
		for k in seenR:
			if k != r:
				break
		else:
			continue
		hi = max(hi, i - seenR[k])
	print(hi)


def solve(n, x, arr):
	k = 0
	for i in range(n):
		if arr[i] % x != 0:
			k = 1
	if k == 0:
		return -1
	if sum(arr) % x != 0:
		return n
	(l, r) = (-1, -1)
	for i in range(n):
		if arr[i] % x != 0:
			l = i
			break
	for i in range(-1, -n, -1):
		if arr[i] % x != 0:
			r = i
			break
	l += 1
	return n - min(abs(r), l)
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(n, x, arr))


t = int(input())
while t:
	(n, x) = map(int, input().split())
	l1 = list(map(int, input().split()))
	max1 = 0
	max2 = 0
	sum = 0
	for i in range(0, n):
		sum = sum + l1[i]
		sum = sum % x
		if sum != 0:
			max1 = i + 1
	sum = 0
	for i in range(n - 1, 0, -1):
		sum = sum + l1[i]
		sum = sum % x
		if sum != 0:
			max2 = n - i
	ans = max(max1, max2)
	if ans == 0:
		ans = -1
	print(ans)
	t = t - 1


def main():
	t = int(input())
	for i in range(t):
		input()
		s = set(list(map(int, input().split())))
		print(len(s))
main()


num = int(input())
answers = []
for i in range(0, num):
	a = input()
	l = input().split()
	s = set(l)
	answers.append(len(s))
for i in answers:
	print(i)


def findab(x):
	if x % 2 == 0:
		return (x // 2, x // 2)
	else:
		return (1, x - 1)

def maxseq(x):
	return len(set(x))
cases = int(input())
for _ in range(cases):
	l = int(input())
	x = list(map(int, input().split()))
	print(maxseq(x))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] %= x
	count = l.count(0)
	if count == n:
		print(-1)
	elif sum(l) % x != 0:
		print(n)
	else:
		count = n
		s = sum(l)
		(ind1, ind2, f, m) = (0, 0, 0, 0)
		for i in range(n):
			if l[i] != 0 and f == 0:
				ind1 = i
				f = 1
			if l[n - i - 1] != 0 and m == 0:
				ind2 = i
				m = 1
		dif = min(ind1 + 1, ind2 + 1)
		print(count - dif)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = sorted(a)
	max_num = 0
	l = []
	for i in range(0, n):
		if max_num < k[i]:
			l.append(k[i])
			max_num = k[i]
	print(len(l))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if sum(a) % x != 0:
		print(n)
	else:
		an = -1
		for j in range(n):
			if a[j] % x != 0:
				an = j
				break
		an12 = -1
		for j in range(n - 1, -1, -1):
			if a[j] % x != 0:
				an12 = j
				break
		if an != -1 and an12 != -1:
			print(max(n - an - 1, an12))
		else:
			print(-1)


n = int(input())
arr = [0] * n
for i in range(n):
	ele = input()
	arr[i] = [int(n) for n in input().split(' ')]
for i in arr:
	print(len(set(i)))


test_case = int(input())
for i in range(test_case):
	length = int(input())
	values = list(map(int, input().split(' ')))
	values = set(values)
	print(len(values))


n = int(input())
b = []
for i in range(n):
	x = int(input())
	a = list(map(int, input().split()))
	b.append(len(list(set(a))))
for i in b:
	print(i)


def solution(arr):
	return len(set(arr))
for _ in range(int(input())):
	a = int(input())
	array = map(int, input().split())
	print(solution(array))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		cnt = ct = 0
		for i in range(n):
			cnt += 1
			if a[i] % x != 0:
				break
		for i in range(n - 1, -1, -1):
			ct += 1
			if a[i] % x != 0:
				break
		if ct == cnt == n:
			print('-1')
		else:
			print(n - min(cnt, ct))


t = int(input())
t = range(t)
for _ in t:
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	add = sum(a)
	if add % x != 0:
		print(n)
	else:
		c = 0
		f = 0
		s = 0
		for i in range(len(a)):
			if a[i] % x != 0:
				f = n - (i + 1)
				c = 1
				break
		for i in range(len(a) - 1, -1, -1):
			if a[i] % x != 0:
				s = i
				c = 1
				break
		if c == 0:
			print(-1)
		else:
			print(s if s > f else f)


for _ in range(int(input())):
	(n, k) = map(int, input().rstrip().split(' '))
	l = list(map(int, input().rstrip().split(' ')))
	s = z = 0
	r = -1
	for i in range(n):
		s += l[i]
		z += l[i]
	if s % k:
		print(n)
	else:
		for i in range(n // 2):
			s = s - l[i]
			if s % k:
				r = n - i - 1
				break
			z = z - l[n - i - 1]
			if z % k:
				r = n - i - 1
				break
		print(r)


n = int(input())
for i in range(0, n):
	n1 = int(input())
	arr = list(map(int, input().split()))
	s = set(arr)
	print(len(s))


from collections import defaultdict
import math
from functools import reduce
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(len(set(arr)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	pos = -1
	for i in range(n):
		if l[i] % x != 0:
			pos = n - i - 1
		if l[n - i - 1] % x != 0:
			pos = n - i - 1
		if pos != -1:
			break
	if sum(l) % x != 0:
		print(len(l))
	elif pos != -1:
		print(pos)
	else:
		print(-1)


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	su = 0
	MA = [0]
	ans = -1
	for i in range(n):
		su = su + A[i]
		if su % x != 0:
			ans = max(ans, i + 1)
	su = 0
	A = A[::-1]
	for i in range(n):
		su = su + A[i]
		if su % x != 0:
			ans = max(ans, i + 1)
	print(ans)


n = int(input())
arrays = []
for i in range(n):
	x = int(input())
	a = []
	a = input().split()
	a = [int(i) for i in a]
	arrays.append(a)
for i in range(n):
	a = []
	a = set(arrays[i])
	print(len(a))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	b = list(map(int, input().split()))
	k = sum(b)
	c = []
	p = -1
	for j in range(n):
		if b[j] % x != 0:
			p = j + 1
			break
	j = n - 1
	q = -1
	while j >= 0:
		if b[j] % x != 0:
			q = n - j
			break
		j += -1
	if k % x != 0:
		print(n)
	elif p == -1 and q == -1:
		print(-1)
	else:
		print(n - min(p, q))


T = int(input())

def main():
	(n, x) = tuple(map(int, input().split()))
	arr = list(map(int, input().split()))
	mod_arr = []
	for i in range(n):
		var = arr[i] % x
		mod_arr.append(var)
	if sum(mod_arr) == 0:
		return -1
	elif sum(arr) % x != 0:
		return n
	else:
		prefix_total = 0
		prefix_maxlen = 0
		for i in range(n - 1):
			prefix_total = prefix_total + arr[i]
			if prefix_total % x != 0:
				prefix_maxlen = i + 1
		suffix_total = 0
		suffix_maxlen = 0
		for i in range(n - 1, 0, -1):
			suffix_total = suffix_total + arr[i]
			if suffix_total % x != 0:
				suffix_maxlen = n - i
		return max(prefix_maxlen, suffix_maxlen)
for _ in range(T):
	print(main())


def program():
	n = int(input())
	print(len(set(map(int, input().split()))))
t = int(input())
for i in range(t):
	program()


for _ in range(int(input())):
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	lst = list(map(int, input().split()))
	if sum(lst) % x:
		print(len(lst))
		continue
	flag = 0
	for (j, e) in enumerate(lst, 0):
		if e % x:
			flag += 1
	if not flag:
		print(-1)
		continue
	l = 0
	r = n - 1
	while lst[l] % x == 0:
		l += 1
	while lst[r] % x == 0:
		r -= 1
	print(max(n - l - 1, r))


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


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sumA = sum(a)
	if sumA % x:
		print(n)
	else:
		l = -1
		r = n
		for (idx, ele) in enumerate(a):
			if ele % x != 0:
				if l == -1:
					l = idx
				r = idx
		if l == -1:
			print('-1')
		else:
			print(n - min(l + 1, n - r))


from sys import stdin, stdout

def solve():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		lis = set(map(int, stdin.readline().split()))
		print(len(lis))
solve()


def task_A():
	t = int(input())
	for _ in range(t):
		(n, x) = map(int, input().split())
		array = list(map(int, input().split()))
		remained_array = []
		for curr in array:
			remained_array.append(curr % x)
		if sum(remained_array) == 0:
			print(-1)
		elif sum(remained_array) % x == 0:
			for i in range(n):
				if remained_array[i]:
					print(n - i - 1)
					break
				if remained_array[n - i - 1]:
					print(n - i - 1)
					break
		else:
			print(n)

def main():
	task_A()
main()


t = int(input())
for cas in range(t):
	n = int(input())
	a = [int(e) for e in input().split()]
	a.sort()
	ans = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			ans += 1
	print(ans)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

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

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

def main():

	def solve():
		(n, x) = map(int, inputi().split())
		aa = [int(a) for a in inputi().split()]
		rem = sum(aa) % x
		if rem != 0:
			print(n)
			return
		res = n - 1
		for i in range(n // 2 + 1):
			if aa[i] % x == 0 and aa[-i - 1] % x == 0:
				res -= 1
			else:
				print(res)
				return
		else:
			print(-1)
			return
	t = int(inputi())
	for _ in range(t):
		solve()
main()


n = int(input())
for i in range(n):
	m = int(input())
	arr = list(map(int, input().split()))
	arrn = arr + arr
	setar = set(arrn)
	print(len(setar))


def sub(array, n, x):
	s = sum(array)
	if not s:
		return -1
	if s % x:
		return n
	(p1, p2) = (0, n - 1)
	while True:
		if array[p1] or array[p2]:
			return p2
		p1 += 1
		p2 -= 1
for _ in range(int(input())):
	(n, x) = list(map(int, input().split(' ')))
	array = map(int, input().split(' '))
	array = [i % x for i in array]
	print(sub(array, n, x))


for i in range(int(input())):
	n = int(input())
	lst = sorted(list(set(list(map(int, input().split())))))
	print(len(lst))


t = int(input())
for test in range(1, t + 1):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	s1 = sum(arr)
	ans = -1
	ans1 = -1
	if s % x != 0:
		print(n)
	else:
		for i in range(n):
			s -= arr[i]
			if s % x != 0:
				ans = n - i - 1
				break
		for i in range(n - 1, -1, -1):
			s1 -= arr[i]
			if s1 % x != 0:
				ans1 = i
				break
		print(max(ans, ans1))


from sys import stdin

def func(arr, l, r, x):
	while l < r:
		mid = (l + r) // 2
		if arr[mid] + x > 0:
			r = mid
		else:
			l = mid + 1
	return l
for _ in range(int(stdin.readline())):
	x = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	print(len(set(arr)))


n = int(input())
for w in range(n):
	a = input()
	b = input().split()
	print(len(set(b)))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
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')
for t in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	l = n
	if s % x == 0:
		c1 = 0
		sm = 0
		for i in range(n):
			sm += a[i]
			c1 += 1
			if sm % x != 0:
				break
		sm = 0
		c2 = 0
		for i in range(n - 1, -1, -1):
			sm += a[i]
			c2 += 1
			if sm % x != 0:
				break
		l = max(n - c1, n - c2)
	if l == 0:
		l = -1
	print(l)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	curSum = sum(arr)
	if curSum % x != 0:
		print(n)
	else:
		left = 0
		right = n - 1
		while left < n and arr[left] % x == 0:
			left += 1
		while right > -1 and arr[right] % x == 0:
			right -= 1
		if left == n:
			print(-1)
		else:
			mn = min(left + 1, n - right)
			print(n - mn)


def solve(li, k):
	su = sum(li)
	le = len(li)
	if su % k != 0:
		return le
	else:
		temp = su
		temp_le = le
		for i in li:
			if temp % k != 0:
				break
			temp -= i
			temp_le -= 1
		temp1 = su
		temp1_le = le
		for i in range(le - 1, 0, -1):
			if temp1_le <= temp_le:
				return temp_le
			elif temp1 % k != 0:
				return temp1_le
			else:
				temp1 -= li[i]
				temp1_le -= 1
		else:
			return -1
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	result = solve(li, m)
	print(result)


def listint():
	a = input().split()
	for i in range(len(a)):
		a[i] = int(a[i])
	return a
t = int(input())
for i in range(t):
	n = int(input())
	arra = listint()
	arra.sort()
	ans = len(arra)
	for i in range(len(arra) - 1):
		if arra[i] == arra[i + 1]:
			ans = ans - 1
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	data = list(map(int, input().split()))
	if sum(data) % x == 0:
		left = -1
		for i in range(n):
			if data[i] % x != 0:
				left = i
				break
		right = -1
		for i in range(n):
			if data[n - 1 - i] % x != 0:
				right = i
				break
		if left == -1 and right == -1:
			print(-1)
		else:
			print(n - min(left, right) - 1)
	else:
		print(n)


def fun(a):
	for i in range(len(a)):
		if a[i] % x == 0:
			pass
		else:
			return len(a[i + 1:])
	return -1
for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(n)
	else:
		l1 = fun(l)
		l2 = fun(l[::-1])
		if l1 > l2:
			print(l1)
		else:
			print(l2)


n = int(input())
count = 0
f = []
while count < n:
	d = []
	c = 0
	num = int(input())
	s = input()
	for x in s.split(' '):
		d.append(int(x))
	sd = set(d)
	f.append(len(sd))
	count += 1
for x in f:
	print(x)


for _ in range(int(input())):
	u = input()
	print(len(set(list(map(int, input().split())))))


N = int(input())
for _ in range(N):
	_ = int(input())
	nums = [a for a in input().split()]
	print(len(set(nums)))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x > 0:
		print(n)
		continue
	mi = n
	for i in range(n // 2 + 1):
		if a[i] % x > 0 or a[n - i - 1] % x > 0:
			mi = i + 1
			break
	if mi == n:
		print(-1)
	else:
		print(n - mi)


t = int(input())
for _ in range(t):
	n = int(input())
	al = list(map(int, input().split()))
	ll = set()
	cnt = 0
	for i in range(n):
		ll.add(al[i])
	print(len(ll))


def parseint():
	ln = input().split()
	for i in range(len(ln)):
		ln[i] = int(ln[i])
	return ln

def solve(x, a):
	if sum(a) % x != 0:
		return len(a)
	mult = [True for _ in range(len(a))]
	for i in range(len(a)):
		if a[i] % x != 0:
			mult[i] = False
	inds = [i for i in range(len(a)) if not mult[i]]
	if len(inds) == 0:
		return -1
	trim = min(len(a) - max(inds), min(inds) + 1)
	return len(a) - trim
t = int(input())
for i in range(t):
	nx = parseint()
	a = parseint()
	x = nx[1]
	print(solve(x, a))


import math
from math import gcd, floor, sqrt, log

def iin():
	return int(input())

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

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

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

def ceill(x):
	return int(x) if x == int(x) else int(x) + 1

def ceilldiv(x, d):
	x // d if x % d == 0 else x // d + 1

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

def solve():
	n = iin()
	x = listin()
	print(len(set(x)))
t = 1
t = int(input())
for hula in range(t):
	solve()


for test_case in range(int(input())):
	(size, hate_num) = map(int, input().split())
	array = list(map(int, input().split()))
	indexes = []
	if sum(array) % hate_num != 0:
		print(size)
	else:
		for (index, num) in enumerate(array):
			if num % hate_num != 0:
				indexes.append(index)
		if not indexes:
			print('-1')
		else:
			left = indexes[0] - 0 + 1
			right = size - indexes[-1]
			print(size - min(left, right))


I = lambda : map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	l = list(I())
	print(len(set(l)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) % x for i in input().split()]
	if sum(a) == 0:
		print(-1)
	elif sum(a) % x:
		print(n)
	else:
		b = [i for i in range(n) if a[i]]
		print(max(n - b[0] - 1, b[-1]))


def fun(arr, n):
	arr.sort()
	res = 0
	i = 0
	while i < n:
		while i < n - 1 and arr[i] == arr[i + 1]:
			i += 1
		res += 1
		i += 1
	return res
t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	print(fun(arr, n))
	t -= 1


t = int(input())
for r in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		d[i] = 0
	print(len(d))


def solve():
	n = int(input())
	st = {int(v) for v in input().split()}
	print(len(st))
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	bad = True
	max1 = -1
	s1 = 0
	s2 = 0
	max2 = -1
	for i in range(n):
		if a[i] % x != 0:
			bad = False
		s1 += a[i]
		s2 += a[-i - 1]
		if s1 % x != 0:
			max1 = i + 1
		if s2 % x != 0:
			max2 = i + 1
	if bad:
		print(-1)
		continue
	print(max(max1, max2))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x:
		print(n)
	else:
		ans = 0
		for i in range((n + 1) // 2):
			if a[i] % x or a[-(i + 1)] % x:
				ans = i + 1
				break
		if ans:
			print(n - ans)
		else:
			print(-1)


def main():
	testcases = int(input())
	for i in range(testcases):
		n = int(input())
		elements = input()
		elements = [int(n) for n in elements.split(' ')]
		elements = set(elements)
		print(len(elements))
main()


for _ in range(int(input())):
	n = int(input())
	x = set([int(d) for d in input().split()])
	print(len(x))


for i in range(int(input())):
	n = int(input())
	seq = [int(i) for i in input().split()]
	m = len(set(seq))
	print(min(m, n))


test = int(input())
for t in range(test):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	print(len(s))


import math
a = int(input())
for i in range(0, a):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	summ = [0] * len(arr)
	summ[0] = arr[0]
	for i in range(1, len(arr)):
		summ[i] = summ[i - 1] + arr[i]
	first = -1
	for i in range(0, len(summ)):
		if not arr[i] % x == 0:
			first = i
			break
	if first == -1:
		print(-1)
	else:
		trr = []
		for i in range(len(arr) - 1, -1, -1):
			if summ[i] % x == 0:
				trr.append(i - first)
			else:
				trr.append(i + 1)
		print(max(trr))


def getN():
	return int(input())

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

def getList():
	return list(map(int, input().split()))
from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys
INF = 10 ** 17
MOD = 1000000007
from fractions import *

def inverse(f):
	return 1 / f

def make_next(n, nums):
	imos = [0 for i in range(n)]
	for (i, num) in enumerate(nums):
		if num > i:
			imos[0] += 1
		else:
			imos[i - num] += 1
		if i + num + 1 < n:
			imos[i + num + 1] -= 1
	nx = []
	tmp = 0
	for im in imos:
		tmp += im
		nx.append(tmp)
	return nx

def mantan_check(n, nums):
	if sum(nums) == n ** 2:
		return True
	else:
		return False

def knapsack(tree, vx, l):
	dp = [0 for i in range(l + 1)]
	while True:
		dpcp = copy.copy(dp)
		(v, w) = tree[vx - 1]
		for (i, d) in enumerate(dp):
			if w + i < l + 1:
				if dpcp[w + i] < v + d:
					dpcp[w + i] = v + d
		dp = copy.copy(dpcp)
		vx //= 2
		dp = dpcp
		if vx == 0:
			break
	return max(dp)

def solve():
	(n, x) = getList()
	nums = getList()
	acc = [0]
	tmp = 0
	for num in nums:
		tmp += num
		tmp %= x
		acc.append(tmp)
	if acc[-1] != 0:
		print(n)
		return
	res = []
	for (i, ac) in enumerate(acc):
		if ac != 0:
			res.append(i)
	if not res:
		print(-1)
		return
	print(max(res[-1], n - res[0]))
	return
	return

def main():
	n = getN()
	for _ in range(n):
		solve()
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	ans = 1
	for i in range(1, n):
		if l[i] != l[i - 1]:
			ans += 1
	print(ans)


for i in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = 10 ** 10
	for i in range(n):
		if a[i] % x != 0:
			l = i
			for i in range(1, n + 1):
				if a[-i] % x != 0:
					r = n - i
					break
			break
	if l == 10 ** 10:
		print(-1)
	elif sum(a) % x != 0:
		print(len(a))
	else:
		b = a[l + 1:]
		c = a[:r]
		if len(b) >= len(c):
			print(len(b))
		else:
			print(len(c))


def p1323A():
	t = int(input())
	l = []
	for i in range(t):
		n = int(input())
		a = input().split()
		a = [int(j) for j in a]
		if len(a) == 1 and a[0] % 2 != 0:
			l.append('-1')
			continue
		for k in range(2):
			if a[k] % 2 == 0:
				l.append(1)
				l.append(k + 1)
				break
			elif k > 0:
				l.append('2')
				l.append('1 2')
				break
	for i in l:
		print(i)
t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = input().split()
	a = set(a)
	ans.append(len(a))
for i in ans:
	print(i)


t = int(input())
for t1 in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(set(l)))


t = int(input())
for _ in range(t):
	l = int(input())
	ans = len(set([int(x) for x in str(input()).split()]))
	print(ans)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = [int(i) for i in input().split()]
	cnt = 0
	for i in l:
		if i % x == 0:
			cnt += 1
	if cnt == n:
		print(-1)
	else:
		sm = sum(l)
		if sm % x != 0:
			print(n)
		else:
			ind1 = -1
			ind2 = -1
			for i in range(n):
				if l[i] % x:
					ind1 = i
					break
			for i in range(n - 1, -1, -1):
				if l[i] % x:
					ind2 = i
					break
			print(max(n - ind1 - 1, ind2))


temp = [int(i) for i in input().split(' ')]
t = temp[0]
result = ''
for i in range(t):
	n = int(input())
	array = [int(x) for x in input().split(' ')]
	result += str(len(set(array))) + '\n'
print(result)


def count():
	x = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	print(len(b))
t = int(input())
for i in range(t):
	count()


for t in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	done = False
	r = sum(l)
	while not done:
		if r % x == 0 and len(l) > 0:
			if l[0] % x != 0:
				r -= l[0]
				del l[0]
			elif l[len(l) - 1] % x != 0:
				r -= l[len(l) - 1]
				del l[len(l) - 1]
			else:
				i = 0
				j = len(l) - 1
				while i < len(l) and l[i] % x == 0:
					i += 1
				while j >= 0 and l[j] % x == 0:
					j -= 1
				if i >= len(l) - j:
					l = l[:j + 1]
				else:
					l = l[i:]
		else:
			done = True
	if len(l) > 0:
		print(len(l))
	else:
		print(-1)


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	set_arr = set(arr)
	print(len(set_arr))


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	q = list(set(list(map(int, input().split()))))
	ans.append(len(q))
for a in ans:
	print(a)


def main():
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	sm = 0
	x_cnt = 0
	for i in lst:
		if i % x == 0:
			x_cnt += 1
		sm += i
	if x_cnt == n:
		print(-1)
		return
	if sm % x == 0:
		for i in range(n // 2):
			if lst[i] % x != 0 or lst[n - i - 1] % x != 0:
				print(n - i - 1)
				return
		print(1)
	else:
		print(n)
t = int(input())
for i in range(t):
	main()


import sys
t = int(sys.stdin.readline())
for i in range(t):
	a = int(sys.stdin.readline())
	aa = map(int, sys.stdin.readline().strip().split())
	b = set()
	for num in aa:
		b.add(num)
	print(len(b))


def process_test_case(i_t):
	(n, x) = map(int, input().split())
	a_vec = list(map(int, input().split()))
	out = -1
	if sum(a_vec) % x != 0:
		out = n
	else:
		i = 0
		while i < (n + 1) // 2:
			if a_vec[i] % x != 0 or a_vec[n - 1 - i] % x != 0:
				out = n - 1 - i
				break
			i += 1
	print(out)
	return None
n_tests = int(input())
for i_test in range(1, n_tests + 1):
	process_test_case(i_test)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(map(int, input().split()))
	summ = sum(s)
	if summ % x != 0:
		print(len(s))
	else:
		minl = -1
		minr = -1
		for i in range(len(s)):
			if s[i] % x != 0:
				if minl == -1:
					minl = i
				minr = i
		minr = len(s) - minr - 1
		if minl == -1:
			print(-1)
		else:
			print(len(s) - min(minl, minr) - 1)


for t in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
	else:
		i = 0
		while i < n and a[i] % x == 0:
			i += 1
		j = n - 1
		while j >= 0 and a[j] % x == 0:
			j -= 1
		print(max(n - i - 1, j))


t = int(input())
for _ in range(t):
	(n, x) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	subsum = sum(arr)
	if subsum % x != 0:
		print(n)
		continue
	no_sol = True
	for i in range(n // 2 + 1):
		if arr[i] % x != 0 or arr[-1 - i] % x != 0:
			print(n - i - 1)
			no_sol = False
			break
	if no_sol:
		print(-1)


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	if sum(A) % x != 0:
		print(n)
	else:
		count = 0
		for i in range(n):
			if A[i] % x == 0:
				count += 1
		if count == n:
			print(-1)
		else:
			pre = [A[0]]
			sup = [A[-1]]
			for i in range(1, n):
				pre.append(A[i] + pre[-1])
			for i in range(n - 2, -1, -1):
				sup.append(A[i] + sup[-1])
			check1 = 0
			check2 = 0
			for i in range(n):
				if pre[i] % x != 0:
					check1 = i + 1
					break
			for i in range(n):
				if sup[i] % x != 0:
					check2 = i + 1
					break
			print(max(check1, n - check1, check2, n - check2))


from itertools import accumulate
import operator
for _ in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	arrs = [int(x) for x in input().split()]
	sums = sum(arrs)
	if sums % x > 0:
		answer = n
	else:
		acc = accumulate(arrs, operator.add)
		acr = accumulate(arrs[::-1], operator.add)
		answer = -1
		answer1 = -1
		answer2 = -1
		for (i, v) in enumerate(acc):
			if (sums - v) % x > 0:
				answer1 = n - i - 1
				break
		for (i, v) in enumerate(acr):
			if (sums - v) % x > 0:
				answer2 = n - i - 1
				break
		if answer1 != -1:
			if answer2 != -1:
				answer = max(answer1, answer2)
		elif answer2 != -1:
			answer = answer2
	print(answer)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ts = sum(a)
	ans = -1
	aage = -1
	piche = -1
	if ts % x == 0:
		for i in range(n):
			if a[i] % x != 0:
				aage = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				piche = i
				break
		if aage != -1 and piche != -1:
			if aage < n - piche:
				ans = n - aage - 1
			else:
				ans = piche
	else:
		ans = n
	print(ans)


for _ in ' ' * int(input()):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	z = sum(c)
	k = 0
	z1 = 0
	for i in range(a):
		z1 += c[i]
		if z1 % b:
			k = max(k, i + 1)
		if (z - z1) % b:
			k = max(k, a - i - 1)
	print([-1, k][k != 0])


I = input
for _ in range(int(I())):
	I()
	s = set(map(int, I().split()))
	print(len(s))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	v1 = 0
	v2 = 0
	s = sum(a)
	if s % x == 0:
		for i in range(n):
			if a[i] % x == 0:
				v1 += 1
			else:
				break
		a = a[::-1]
		for i in range(n):
			if a[i] % x == 0:
				v2 += 1
			else:
				break
		if v1 == v2 and v2 == n - 1:
			print(-1)
		else:
			print(n - min(v1, v2) - 1)
	else:
		print(n)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	f = -1
	la = -1
	s = 0
	for i in range(n):
		s += l[i]
		if l[i] % x != 0 or (l[i] < x and l[i] != 0):
			if f == -1:
				f = i
			la = i
	if s % x != 0:
		print(n)
	elif la != -1 or f != -1:
		print(max(n - f - 1, la))
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	mod = [0] * n
	ans = -1
	cur = 0
	maxlen = -1
	for i in range(n):
		cur += a[i]
		mod[i] = cur % x
	first_0 = -1
	last_0 = -1
	for i in range(n):
		if mod[i] == 0:
			first_0 = i
			break
	for i in range(n - 1, -1, -1):
		if mod[i] == 0:
			last_0 = i
			break
	first = -1
	last = -1
	for i in range(n):
		if mod[i] != 0:
			first = i
			break
	for i in range(n - 1, -1, -1):
		if mod[i] != 0:
			last = i
			maxlen = i + 1
			break
	if first == -1 and last == -1:
		print(-1)
	elif first_0 == -1 and last_0 == -1:
		print(n)
	else:
		if first != -1 and first_0 != -1:
			ans = abs(first - first_0)
		if first != -1 and last_0 != -1:
			v = abs(first - last_0)
			ans = max(ans, v)
		if last != -1 and first_0 != -1:
			w = abs(last - first_0)
			ans = max(ans, w)
		if last != -1 and last_0 != -1:
			x = abs(last - last_0)
			ans = max(ans, x)
		print(max(ans, maxlen))


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	s = set(arr)
	print(len(s))


from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
	n = stdin.readline()
	arr = set(stdin.readline().strip().split(' '))
	print(len(arr))


def convert_into_int(arr):
	for i in range(len(arr)):
		arr[i] = int(arr[i])
	return arr

def compute_longest_subarr(data_arr, undesired):
	total = 0
	length = len(data_arr)
	for i in data_arr:
		total += i
	if total % undesired > 0:
		return length
	x = 0
	for i in range(len(data_arr)):
		if data_arr[i] % undesired == 0:
			length -= 1
		else:
			x = i
	if length == 0:
		return -1
	elif x >= len(data_arr) - 1 - x:
		return x
	else:
		return len(data_arr) - 1 - x
cases_num = int(input())
undesired_nums = []
inputs_data = []
for i in range(cases_num):
	undesired_input = int(input().split(' ')[1])
	input_data = input().split(' ')
	input_data = convert_into_int(input_data)
	undesired_nums.append(undesired_input)
	inputs_data.append(input_data)
for x in range(len(inputs_data)):
	x1 = compute_longest_subarr(inputs_data[x], undesired_nums[x])
	z = inputs_data[x]
	z.reverse()
	x2 = compute_longest_subarr(z, undesired_nums[x])
	if x1 > x2:
		print(x1)
	else:
		print(x2)


import sys
from collections import deque
inp = sys.stdin.readline
ans = ''
for _ in range(int(inp())):
	n = int(inp())
	arr = set(map(int, inp().split()))
	ans += str(len(arr)) + '\n'
print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	a.sort()
	sol = 1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			sol += 1
	print(sol)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	nums = list(map(int, input().split()))
	if all((a % x == 0 for a in nums)):
		print(-1)
	elif sum(nums) % x != 0:
		print(n)
	else:
		(dropLeft, dropRight) = (1, 1)
		while nums[dropLeft - 1] % x == 0:
			dropLeft += 1
		while nums[-dropRight] % x == 0:
			dropRight += 1
		print(n - min(dropLeft, dropRight))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		(su, su1, f) = (0, 0, 0)
		for i in range(n):
			su += l[i]
			su1 += l[-1 * (i + 1)]
			if (s - su) % x != 0:
				print(n - i - 1)
				f += 1
				break
			elif (s - su1) % x != 0:
				print(n - i - 1)
				f += 1
				break
			elif (s - su1 - su) % x != 0:
				print(n - i - 2)
				f += 1
				break
		if f == 0:
			print(-1)


tests = int(input())
for _ in range(tests):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = []
	x1 = []
	for i in range(n):
		if arr[i] % x != 0:
			d.append(arr[i])
			x1.append(i)
	if d == []:
		print(-1)
		continue
	if sum(d) % x != 0:
		print(n)
	else:
		print(max(n - x1[0] - 1, x1[-1]))


n = int(input())
ans = [0] * n
for i in range(n):
	L = int(input())
	a = set(map(int, input().split()))
	ans[i] = len(a)
for i in ans:
	print(i)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	s = set(arr)
	print(len(s))


from sys import stdin

def readline():
	return stdin.readline()
tests = int(readline())

def solve(n, x, a):
	summa = sum(a)
	if summa % x != 0:
		return n
	for i in range(0, n // 2):
		if (summa - a[i]) % x != 0 or (summa - a[n - i - 1]) % x != 0:
			return n - i - 1
		summa -= a[i] - a[n - i - 1]
	return -1
for t in range(0, tests):
	(n, x) = list(map(int, readline().rstrip('\n').split(' ')))
	a = list(map(int, readline().split(' ')))
	print(solve(n, x, a))


import sys
ip = lambda : sys.stdin.readline().rstrip()
for _ in range(int(ip())):
	(n, x) = map(int, ip().split())
	a = list(map(int, ip().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
		continue
	l = 0
	while l < n and a[l] % x == 0:
		l += 1
	l += 1
	if l == n:
		print(-1)
		continue
	r = n - 1
	while r >= 0 and a[r] % x == 0:
		r -= 1
	r -= 1
	print(max(n - l, r + 1))


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

def solve(N, X, A):
	if sum(A) % X != 0:
		return N
	for i in range(N):
		j = N - 1 - i
		if i > j:
			break
		if A[i] % X != 0:
			return N - i - 1
		if A[j] % X != 0:
			return j
	return -1
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, X) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, X, A)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	uniq = 0
	seen = set()
	for num in input().split(' '):
		v = int(num)
		if not v in seen:
			seen.add(v)
			uniq += 1
	print(uniq)


def read_int_array():
	return [int(x) for x in input().split(' ')]

def solve(a):
	return len(set(a))
t = int(input())
for i in range(t):
	n = int(input())
	a = read_int_array()
	print(solve(a))


t = int(input())
out = []
for i in range(0, t):
	n = int(input())
	lis = list(map(int, input().split(' ')))
	lis2 = set(lis)
	lis2 = list(lis2)
	out.append(len(lis2))
for k in out:
	print(k)


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')
for _ in range(int(input())):
	(i_liczb, x) = map(int, input().split())
	liczby = [int(y) % x for y in input().split()]
	if sum(liczby) % x != 0:
		print(i_liczb)
		continue
	for y in range(i_liczb // 2 + 1):
		if liczby[y] != 0 or liczby[i_liczb - y - 1] != 0:
			print(i_liczb - y - 1)
			break
	else:
		print(-1)


def main():
	t = int(input())
	for _ in range(t):
		(n, x) = map(int, input().split())
		a = list(map(int, input().split()))
		l = []
		suma = 0
		for (c, el) in enumerate(a):
			if el % x != 0:
				l.append(c)
			suma += el
		lenl = len(l)
		if lenl == 0:
			print(-1)
			continue
		if suma % x != 0:
			print(n)
			continue
		if lenl == 1:
			before = l[0] + 1
			after = n - l[0]
			cutoffs = [before, after]
		else:
			before = l[0] + 1
			after = n - l[0]
			before2 = l[-1] + 1
			after2 = n - l[-1]
			cutoffs = [before, after, before2, after2]
		cutoff = min(cutoffs)
		print(n - cutoff)
main()


import math
t = int(input())

def findFromStart(arr, x):
	currSum = 0
	max_size = 0
	for i in range(len(arr)):
		currSum += arr[i]
		if currSum % x != 0:
			max_size = max(max_size, i + 1)
	return max_size
for i in range(t):
	inp = input().split(' ')
	(n, x) = (int(inp[0]), int(inp[1]))
	arr = [int(xx) for xx in input().split(' ')]
	ans = max(findFromStart(arr, x), findFromStart(arr[::-1], x))
	if ans == 0:
		print(-1)
	else:
		print(ans)


def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		N = int(input())
		A = list(map(int, input().split()))
		A = set(A)
		print(len(A))
main()


t = int(input())
for test in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	oarr = []
	iarr = []
	for i in range(n):
		if arr[i] % x != 0:
			oarr.append(arr[i])
			iarr.append(i)
	if len(oarr) == 0:
		print(-1)
		continue
	ans = 0
	if sum(oarr) % x != 0:
		ans = n
	else:
		ans = max(ans, iarr[len(iarr) - 1])
		ans = max(ans, n - (iarr[0] + 1))
	print(ans)


t = int(input())
for x in range(t):
	n = int(input())
	sample = set(map(int, input().split()))
	print(len(sample))


t = int(input())
for __ in range(t):
	n = int(input())
	ls = set(map(int, input().split()))
	print(len(ls))


for i in range(int(input())):
	user = input()
	print(len(set(list(map(int, input().split())))))


from sys import stdin, stdout
import math
input = stdin.readline

def print(x='', end='\n'):
	stdout.write(str(x) + end)

def solve():
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	pref = [0] * n
	pref[0] = l[0]
	for i in range(1, n):
		pref[i] = pref[i - 1] + l[i]
	suf = [0] * n
	suf[n - 1] = l[n - 1]
	for i in range(n - 2, -1, -1):
		suf[i] += suf[i + 1] + l[i]
	(ans1, ans2) = (-1, -1)
	for i in range(n - 1, -1, -1):
		if pref[i] % x != 0:
			ans1 = i + 1
			break
	for i in range(n):
		if suf[i] % x != 0:
			ans2 = n - i
			break
	print(max(ans1, ans2))
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


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


def binary(arr, ele):
	first = 0
	last = len(arr) - 1
	flag = 0
	while first <= last:
		mid = (first + last) // 2
		if arr[mid] == ele:
			return 0
		elif ele < arr[mid]:
			last = mid - 1
		else:
			first = mid + 1
	return 1
t = int(input())
for sai in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.sort()
	l = []
	for i in a:
		if binary(l, i):
			l.append(i)
	print(len(l))


n = int(input())
for _ in range(n):
	g = int(input())
	x = list(map(int, input().split()))
	l = list(dict.fromkeys(x))
	print(len(l))


for i in range(int(input())):
	am = int(input())
	arr = list(map(int, input().split()))
	print(am - (am - len(set(arr))))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = set()
	for elem in a:
		d.add(elem)
	print(len(d))


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def solution(A):
	return len(set(A))

def main():
	T = read_int()
	for i in range(T):
		n = read_int()
		A = read_int_array()
		x = solution(A)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


o = []
t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	o.append(len(set(nums)))
for l in o:
	print(l)


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

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

def IO():
	return 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 readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

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

def sieve():
	li = [True] * 1000001
	(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 = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	(n, x) = IP()
	a = L()
	pref = [0] * n
	pref[0] = a[0]
	for i in range(1, n):
		pref[i] = pref[i - 1] + a[i]
	if pref[n - 1] % x != 0:
		print(n)
		return
	else:
		ans = -sys.maxsize
		for i in range(n):
			if pref[i] % x != 0:
				note = i
				break
		else:
			print(-1)
			return
		ans = max(ans, n - 1 - note)
		for j in range(n - 1, -1, -1):
			if pref[j] % x != 0:
				r = j
				break
		for j in range(n):
			if (pref[r] - pref[j]) % x != 0:
				ans = max(ans, r - j + 1)
				break
		print(ans)
		return
t = II()
for i in range(t):
	solve()


for _ in ' ' * int(input()):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	f = -1
	lst = []
	s = 0
	for i in range(n):
		s += a[i]
		lst.append(s)
	mn = -1
	for i in range(n):
		if lst[i] % x:
			mn = max(mn, i + 1)
		if (lst[-1] - lst[i]) % x:
			mn = max(mn, n - (i + 1))
	print(mn)


num = int(input())
for i in range(num):
	nn = int(input())
	need = set(list(map(int, input().split())))
	print(len(need))


t = int(input())
while t > 0:
	t -= 1
	a = input().split()
	n = int(a[0])
	x = int(a[1])
	a = [int(x) for x in input().split()]
	s = 0
	cx = 0
	for i in a:
		s += i
		if i % x == 0:
			cx += 1
	if s % x != 0:
		print(n)
		continue
	if cx == n:
		print(-1)
		continue
	ll = n
	lr = n
	sl = s
	sr = s
	for i in range(n):
		sl -= a[i]
		sr -= a[n - i - 1]
		ll -= 1
		lr -= 1
		if sl % x != 0:
			ans = ll
			break
		if sr % x != 0:
			ans = lr
			break
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) % x for i in input().split()]
	sumi = 0
	for i in range(n):
		sumi += a[i]
	if sumi % x != 0:
		print(n)
		continue
	maxx = 0
	for i in range(n):
		if a[i] % x != 0:
			maxx = max(maxx, max(i, n - i - 1))
	if maxx:
		print(maxx)
	else:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	mp = {int(x): True for x in input().split()}
	print(len(mp))


t = int(input())
for i in range(t):
	n = input() + '\n'
	s = input()
	a = s.split()
	str = set(a)
	print(len(str))


for i in range(int(input())):
	N = int(input())
	lst = list(map(int, input().split()))
	print(len(set(lst)))


for _ in range(int(input())):
	(i_liczb, x) = map(int, input().split())
	liczby = [int(y) % x for y in input().split()]
	if sum(liczby) % x != 0:
		print(i_liczb)
		continue
	for y in range(i_liczb // 2 + 1):
		if liczby[y] != 0 or liczby[i_liczb - y - 1] != 0:
			print(i_liczb - y - 1)
			break
	else:
		print(-1)


t = input()
for case in range(int(t)):
	(n, x) = map(int, input().split())
	array = list(input().split())
	for i in range(n):
		array[i] = int(array[i]) % x
	add = 0
	for i in range(n):
		add = add + int(array[i])
	if add % x != 0:
		print(len(array))
	else:
		counter = 0
		a = False
		for i in array:
			if int(i) != 0:
				a = False
				break
			else:
				a = True
		if a == True:
			print(-1)
			continue
		b = True
		while b == True:
			if array[counter] != 0 or array[n - 1 - counter] != 0:
				b = False
			counter = counter + 1
		if b == False:
			print(n - counter)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

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

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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)))
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, x) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	ans = sum(a)
	k = 0
	if ans % x != 0:
		print(n)
		continue
	flag = True
	(s, e) = (0, n - 1)
	(fsum, bsum) = (a[s], a[e])
	while flag:
		if (ans - fsum) % x != 0:
			k = 1
			print(n - 1 - s)
			break
		elif (ans - bsum) % x != 0:
			k = 1
			print(e)
			break
		else:
			s += 1
			e -= 1
			if s > n - 1 or e < 0:
				flag = False
			else:
				fsum += a[s]
				bsum += a[e]
	if k == 0:
		print(-1)


t = int(input())
for _ in range(t):
	(n, x) = [int(p) for p in input().split()]
	arr = list(map(int, input().split()))
	c = 0
	for i in range(0, len(arr)):
		if arr[i] % x == 0:
			c += 1
	if c == n:
		print(-1)
	elif sum(arr) % x != 0:
		print(n)
	else:
		suffix = 0
		q = 0
		for i in range(0, len(arr)):
			if arr[i] % x == 0:
				continue
			else:
				q = i + 1
				break
		suffix = n - q
		prefix = 0
		q = 0
		for i in range(0, len(arr)):
			if arr[n - i - 1] % x == 0:
				continue
			else:
				q = i + 1
				break
		prefix = n - q
		max1 = max(prefix, suffix)
		print(max1)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	inp = [int(j) for j in input().split()]
	sum = 0
	multiples = 0
	for num in inp:
		sum = sum + num
		if num % x == 0:
			multiples = multiples + 1
	if multiples == n:
		print(-1)
		continue
	if sum % x != 0:
		print(n)
		continue
	(temp, temp1) = (0, 0)
	for j in range(n):
		if inp[j] % x != 0:
			temp = n - 1 - j
			break
	for j in range(n - 1, -1, -1):
		if inp[j] % x != 0:
			temp1 = j
			break
	print(max(temp, temp1))


import math
import collections
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2 ** 20)
t = 1
t = int(stdin.readline())
for _ in range(t):
	(n, x) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	d = {}
	s = 0
	pos = []
	for i in range(n):
		d[a[i] % x] = True
		s += a[i]
		if a[i] % x != 0:
			pos.append(i)
	if s % x != 0:
		print(n)
	elif len(d) == 1 and 0 in d:
		print(-1)
	else:
		if len(pos) >= 2:
			ans = max(n - 1 - pos[0], pos[-1])
		else:
			ans = 1
		print(ans)


t = input()
for i in range(int(t)):
	m = input()
	arr = input()
	arr1 = arr.split(' ')
	dic1 = {}
	c = 0
	for item in arr1:
		if item in dic1:
			pass
		else:
			c += 1
			dic1[item] = True
	print(c)


t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = arr[i] % x
	modsum = sum(arr)
	if modsum % x:
		print(n)
		continue
	else:
		p1 = -1
		p2 = -1
		itr1 = 0
		itr2 = 0
		for i in range(n):
			itr1 += 1
			if arr[i]:
				p1 = i
				break
		for i in range(n - 1, -1, -1):
			itr2 += 1
			if arr[i]:
				p2 = i
				break
		if p1 == -1 and p2 == -1:
			print('-1')
			continue
		if itr1 > itr2:
			print(p2)
			continue
		else:
			print(n - p1 - 1)
			continue


a = int(input())
k = []
t = []
r = 1
for i in range(a):
	p = int(input())
	n = list(map(int, input().split()))
	y = set(n)
	e = len(y)
	print(e)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	from collections import defaultdict
	visited = defaultdict(int)
	for num in arr:
		if visited[num] == True:
			n -= 1
		else:
			visited[num] = True
	print(n)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	sum = 0
	ans = 0
	B = []
	for i in range(n):
		if A[i] % x != 0:
			B.append(i)
			ans = 1
		sum += A[i]
	if sum % x != 0:
		print(n)
		continue
	if sum % x == 0 and ans == 0:
		print('-1')
	elif sum % x == 0 and ans == 1:
		print(max(n - B[0] - 1, B[-1]))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	q = sum(a) % x
	if q != 0:
		print(n)
	else:
		r = [s % x for s in a]
		left = 0
		right = 0
		while left < n and r[left] == 0:
			left += 1
		while right < n and r[-1 - right] == 0:
			right += 1
		k = min(left, right)
		k += 1
		if k >= n:
			print(-1)
		else:
			print(n - k)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, x) = inp()
	arr = list(inp())
	for i in range(n):
		arr[i] %= x
	if arr.count(0) == n:
		ans = -1
	else:
		cur = sum(arr)
		if cur % x == 0:
			left = 0
			right = 0
			for i in range(n):
				if cur % x == 0:
					cur -= arr[i]
					left += 1
				else:
					break
			cur = sum(arr)
			for i in range(n - 1, -1, -1):
				if cur % x == 0:
					cur -= arr[i]
					right += 1
				else:
					break
			ans = n - min(left, right)
		else:
			ans = n
	print(ans)


t = int(input())
q = []
for i in range(t):
	n = int(input())
	l = list(input().split())
	l = [int(j) for j in l]
	s = {0}
	for i in l:
		s.add(i)
	s.remove(0)
	q.append(len(s))
for i in q:
	print(i)


for _ in range(int(input())):
	input()
	x = [int(x) for x in input().split()]
	print(len(set(x)))


def countDistinct(arr, n):
	arr.sort()
	res = 0
	i = 0
	while i < n:
		while i < n - 1 and arr[i] == arr[i + 1]:
			i += 1
		res += 1
		i += 1
	return res
t = int(input())
for i in range(1, t + 1):
	n = int(input())
	arr = list(map(int, input().split()))
	print(countDistinct(arr, n))


import sys
input = sys.stdin.readline
for ti in range(int(input())):
	n = int(input())
	a = list(set([int(x) for x in input().strip().split()]))
	a.sort()
	print(len(a))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	a = 0
	(d, k) = (0, 0)
	p = sum(arr)
	if p % x != 0:
		print(n)
	else:
		for i in range(n):
			p = p - arr[i]
			if p % x != 0:
				a = 1
				print(n - i - 1)
				break
			p += arr[i] - arr[n - i - 1]
			if p % x != 0:
				a = 1
				print(n - i - 1)
				break
			if a == 1:
				break
		if a == 0:
			print(-1)


def nrepeat(n, a):
	return len(list(set(a)))
test = int(input())
for i in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	print(nrepeat(n, a))


import sys, math

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')
INF = float('inf')
mod = 998244353
for t in range(int(data())):
	(n, x) = mdata()
	a = mdata()
	cnt = 0
	ind = INF
	for i in range(n):
		if a[i] % x == 0:
			cnt += 1
		else:
			ind = min(ind, i + 1, n - i)
	if cnt == n:
		out(-1)
		continue
	s = sum(a)
	if s % x == 0:
		out(n - ind)
	else:
		out(n)


T = int(input())
for _ in range(T):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	su = sum(a)
	(xx, yy) = (-1, -1)
	zero = 0
	for i in range(n):
		if a[i] % x != 0:
			xx = i
			break
	for i in range(n):
		if a[n - 1 - i] % x != 0:
			yy = i
			break
	if su % x != 0:
		print(n)
	elif n == 1:
		print(-1)
	elif xx == -1 and yy == -1:
		print(-1)
	else:
		print(max(n - xx - 1, n - yy - 1))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lis = list(map(int, input().split()))
	pre = [lis[0]]
	for i in range(1, n):
		pre.append(pre[-1] + lis[i])
	l1 = []
	l2 = []
	for i in range(n):
		if pre[i] % x == 0:
			l2.append(i)
		else:
			l1.append(i)
	try:
		c = max(l1) + 1
	except:
		print(-1)
		continue
	for i in l2:
		c = max(c, i - l1[0])
	print(c)


test = int(input())
for i in range(test):
	n = int(input())
	arr = list(map(int, input().split()))
	a = set(arr)
	print(len(a))


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()

def unique(sequence):
	seen = set()
	return [x for x in sequence if not (x in seen or seen.add(x))]
for _ in range(int(I1())):
	(n, x) = I()
	l = list(I())
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		(a, b, ans, a1, b1) = (0, 0, -1, -1, -1)
		for i in range(n):
			a += l[i]
			if a % x != 0:
				a1 = i
				break
		for j in range(n - 1, -1, -1):
			b += l[j]
			if b % x != 0:
				b1 = j
				break
		if a1 == -1 and b1 == -1:
			print(-1)
		else:
			print(max(n - a1 - 1, b1))


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	for i in a:
		if i % x != 0:
			c = 1
			break
	if c:
		s = 0
		for i in a:
			s += i
		if s % x != 0:
			print(n)
		else:
			for i in range(0, n):
				if a[i] % x != 0:
					l = i
					break
			for i in range(n - 1, -1, -1):
				if a[i] % x != 0:
					r = i
					break
			ans = max(r, n - l - 1)
			print(ans)
	else:
		print(-1)
	t -= 1


t = int(input())
while t > 0:
	n = int(input())
	li = list(map(int, input().split(' ')))
	li = sorted(list(set(li)))
	print(len(li))
	t -= 1


from collections import Counter

def countDistinct(arr):
	return len(Counter(arr).keys())
t = int(input())
while t > 0:
	inp_int = int(input())
	inp = list(map(int, input().split()))
	print(countDistinct(inp))
	t -= 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	check = [a % x == 0 for a in arr]
	if all(check):
		print(-1)
	elif sum(arr) % x != 0:
		print(n)
	else:
		print(n - min(check.index(False), check[::-1].index(False)) - 1)


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


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [int(i) for i in stdin.readline().split(' ')]
	a = sorted(set(a))
	print(len(a))


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		n = int(input())
		A = list(map(int, input().split()))
		ans = len(set(A))
		print(ans)
main()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		if a[0] % x == 0:
			print(-1)
		else:
			print(1)
	else:
		s = sum(a)
		if s % x == 0:
			p = -1
			q = -1
			for i in range(n):
				if a[i] % x != 0:
					p = n - 1 - i
					break
			for i in range(n - 1, -1, -1):
				if a[i] % x != 0:
					q = i
					break
			print(max(p, q))
		else:
			print(n)


w = int(input())
a = []
for i in range(0, w):
	z = int(input())
	p = input().split(' ')
	a.append(p)
for i in range(0, w):
	r = a[i]
	t = list(set(r))
	print(len(t))


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, X) = [int(x) for x in input().split()]
		A = [int(x) for x in input().split()]
		if sum(A) % X != 0:
			print(N)
			continue
		ans = float('inf')
		for i in range(N):
			if A[i] % X != 0:
				ans = i + 1
				break
		for i in range(N):
			if A[-i - 1] % X != 0:
				ans = min(ans, i + 1)
				break
		if ans == float('inf'):
			print(-1)
		else:
			print(N - ans)

def __starting_point():
	main()
__starting_point()


t = int(input())
while t > 0:
	l = int(input())
	li = list(map(int, input().split()))
	s = set(li)
	print(len(s))
	t -= 1


cases = int(input())
for w in range(cases):
	x = int(input())
	num = [int(i) for i in input().split()]
	num.sort()
	count = 1
	for i in range(1, x):
		if num[i - 1] != num[i]:
			count += 1
	print(count)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x:
		print(n)
	else:
		k = s
		(m1, m2) = (-1, -1)
		for i in range(n):
			s -= a[i]
			if s % x:
				m1 = n - i - 1
				break
		for i in range(n - 1, i, -1):
			k -= a[i]
			if k % x:
				m2 = i
				break
		print(max(m1, m2))


t = int(input())
for i in range(t):
	line = input().split()
	n = int(line[0])
	x = int(line[1])
	arr = []
	line = input().split()
	ct = 0
	for j in range(n):
		arr.append(int(line[j]))
		ct += arr[j]
	if ct % x != 0:
		print(n)
	else:
		ptLeft = 0
		ptRight = 0
		for j in range(n):
			if arr[j] % x == 0:
				ptLeft += 1
			else:
				break
		for j in range(n - 1, -1, -1):
			if arr[j] % x == 0:
				ptRight += 1
			else:
				break
		if ptLeft == n:
			print(-1)
		else:
			print(n - min(ptLeft, ptRight) - 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
		continue
	elif x == 1:
		print(-1)
		continue
	(i1, i2) = (-1, -1)
	for i in range(n):
		if a[i] % x != 0:
			i1 = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x != 0:
			i2 = i
			break
	if i1 == -1:
		print(-1)
	else:
		print(n - min(i1 + 1, n - i2))


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 pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	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, x) = map(int, input().split())
	a = list(map(int, input().split()))
	found = False
	total = 0
	(m1, m2) = (0, 0)
	for i in range(n):
		if a[i] % x != 0:
			if not found:
				found = True
				m1 = m2 = i
			else:
				m2 = i
		total += a[i]
	if not found:
		print(-1)
		continue
	if total % x:
		print(n)
		continue
	print(max(n - m1 - 1, m2))


tc = int(input())
while tc:
	n = int(input())
	l = set(map(int, input().split()))
	print(len(l))
	tc -= 1


for _ in range(int(input())):
	input()
	l = list(map(int, input().split()))
	w = {}
	count = 0
	for i in l:
		if i in w.keys():
			continue
		w[i] = 1
		count += 1
	print(str(count))


for _ in range(int(input())):
	a = input()
	print(len(sorted(set(input().split()))))


def solve(n, x):
	arr = [int(i) for i in input().split(' ')]
	s = sum(arr)
	l = 0
	h = n - 1
	flag = False
	if s % x != 0:
		return n
	for l in range(n):
		if arr[l] % x != 0:
			flag = True
			break
	for h in range(n - 1, -1, -1):
		if arr[h] % x != 0:
			flag = True
			break
	if (l != 0 or h != 0) and flag:
		return n - min(n - h - 1, l) - 1
	return -1
t = int(input())
for _ in range(t):
	(n, x) = (int(i) for i in input().split(' '))
	print(solve(n, x))


import sys
input = sys.stdin.readline

def solve():
	(n, x) = map(int, input().split())
	lista = list(map(int, input().split()))
	contn = 0
	soma = 0
	esq = -1
	direita = 0
	for k in range(n):
		if lista[k] % x != 0:
			if esq == -1:
				esq = k
			direita = k
		soma += lista[k]
	if soma % x != 0:
		print(n)
	elif esq == -1:
		print(-1)
	else:
		print(n - min(esq + 1, n - direita))
test = int(input())
while test != 0:
	solve()
	test -= 1


test_cases = int(input())
while test_cases > 0:
	(arrLen, divide) = map(int, input().split())
	data = list(map(int, input().split()))
	total = sum(data)
	flag = False
	for element in data:
		if element % divide != 0:
			flag = True
	if flag == True:
		tempEnd = total
		tempBegin = total
		i = 0
		while tempBegin % divide == 0:
			tempBegin -= data[i]
			i += 1
		j = arrLen - 1
		toEraseEnd = 0
		while tempEnd % divide == 0:
			tempEnd -= data[j]
			j -= 1
			toEraseEnd += 1
		print(arrLen - min(i, toEraseEnd))
	else:
		print(-1)
	test_cases -= 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	L = list(map(int, input().split()))
	P = []
	m = (len(L) - 1) / 2
	cost = []
	if sum(L) % x != 0:
		print(n)
	else:
		for k in range(len(L)):
			if L[k] % x != 0:
				P.append(k)
		if P == []:
			print(-1)
		else:
			cost = [abs(m - i) for i in P]
			print(int(m + max(cost)))


import sys
input = sys.stdin.buffer.readline

def prog():
	for _ in range(int(input())):
		(n, x) = map(int, input().split())
		nums = list(map(int, input().split()))
		total = sum(nums)
		if total % x == 0:
			found = False
			left = 0
			for i in range(n):
				if nums[i] % x != 0:
					left = i
					found = True
					break
			right = n - 1
			if found:
				found2 = False
				for i in range(n - 1, -1, -1):
					if nums[i] % x != 0:
						right = i
						found2 = True
						break
				print(max(n - (left + 1), right))
			else:
				print(-1)
		else:
			print(n)
prog()


t = int(input())
for i in range(0, t):
	input()
	inp = input().split()
	print(len(set(inp)))


from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
rli = lambda : map(int, stdin.readline().split())
rlf = lambda : map(float, stdin.readline().split())
(INF, NINF) = (float('inf'), float('-inf'))

def main():
	T = int(rl())
	for _ in range(T):
		(n, x) = rli()
		A = list(rli())
		flag = True
		tot = 0
		for (i, a) in enumerate(A):
			if a % x != 0:
				flag = False
			tot += a
		if flag:
			print(-1)
			continue
		if tot % x != 0:
			print(n)
			continue
		(L, R) = (-1, n)
		for (i, a) in enumerate(A):
			if a % x != 0:
				L = i
				break
		for i in range(n - 1, -1, -1):
			if A[i] % x != 0:
				R = i
				break
		(a, b) = (NINF, NINF)
		if L > -1:
			a = n - 1 - L
		if R < n:
			b = R
		ans = max(a, b)
		print(ans if ans > NINF else -1)
	stdout.close()
main()


t = int(input())
res = []
for i in range(t):
	n = int(input())
	inp = sorted(list(map(int, input().split(' '))))
	unq = set()
	for i in range(n):
		unq.add(inp[i])
	res.append(len(unq))
for i in res:
	print(i)


from collections import defaultdict as dd
import math
import sys
import string
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

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

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	(n, x) = mi()
	nums = lm()
	s = sum(nums)
	if not s % x == 0:
		print(n)
	else:
		found = False
		front_sum = n
		for i in range(len(nums)):
			if not nums[i] % x == 0:
				front_sum = i + 1
				found = True
				break
		back_sum = n
		for i in range(len(nums)):
			if not nums[-i - 1] % x == 0:
				back_sum = i + 1
				found = True
				break
		if found:
			print(max(n - front_sum, n - back_sum))
		if not found:
			print(-1)


tc = int(input())
for _ in range(tc):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if sum(arr) % x != 0:
		print(len(arr))
	else:
		ans = 0
		total = totalb = sum(arr)
		i = 0
		while total % x == 0 and i < len(arr):
			total -= arr[i]
			i += 1
		if i != len(arr) - 1:
			ans = max(ans, len(arr) - i)
		j = len(arr) - 1
		while totalb % x == 0 and j >= 0:
			totalb -= arr[j]
			j -= 1
		if j >= 0:
			ans = max(ans, j + 1)
		if ans == 0:
			print(-1)
		else:
			print(ans)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
(t,) = mp()
for _ in range(t):
	(n, x) = mp()
	a = mp()
	if sum(a) % x:
		cout(str(n) + '\n')
		continue
	l = []
	for i in range(n):
		if a[i] % x:
			l += [i]
	if not l:
		cout('-1\n')
		continue
	cout(str(n - min(l[0] + 1, n - l[-1])) + '\n')


import math
import sys
from collections import defaultdict, Counter
from itertools import groupby
rt = lambda : map(int, input().split())
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))

def main():
	t = ri()
	for _ in range(t):
		n = ri()
		print(len(set(rl())))
main()


for b in range(int(input())):
	n = int(input())
	g = i = 0
	x = sorted([int(j) for j in input().split()])
	while n - 1 > i:
		if x[i] == x[i + 1]:
			i += 1
		else:
			g += 1
			i += 1
	g += 1
	print(g)


import sys
input = sys.stdin.readline

def solve():
	(n, x) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	if sum(arr) % x:
		print(n)
		return
	for i in range(n // 2):
		if arr[i] % x or arr[n - i - 1] % x:
			print(n - i - 1)
			return
	print(-1)
tt = int(input())
for test in range(tt):
	solve()


import os
import sys
from io import BytesIO, IOBase
from math import sqrt
from bisect import bisect_left

def solution(n, arr):
	print(len(set(arr)))

def main():
	for _ in range(r_int()):
		n = r_int()
		arr = r_array()
		solution(n, arr)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def p_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


tests = int(input())
for t in range(tests):
	n = int(input())
	s = set([int(i) for i in input().strip().split()])
	print(len(s))


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	ans = [None for i in range(t)]
	for q in range(t):
		(n, x) = map(int, stdin.readline().split())
		a = [int(x) for x in stdin.readline().split()]
		r = -1
		l = -1
		s = 0
		for i in range(n):
			if a[i] % x != 0:
				if l == -1:
					l = i
				r = i
			s += a[i]
		if s % x != 0:
			ans[q] = n
		elif l == -1:
			ans[q] = -1
		else:
			ans[q] = n - min(l + 1, n - r)
	for i in range(t):
		print(ans[i])
main()


from sys import exit as sys_return
requests = int(input())
while requests > 0:
	requests -= 1
	amount = int(input())
	cur_set = set(map(int, input().split()))
	print(len(cur_set))


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % k != 0:
		print(n)
		continue
	start = -1
	end = 0
	for j in range(n):
		if a[j] % k != 0:
			if start == -1:
				start = j
			end = j
	if start == -1:
		print(-1)
	else:
		print(max(n - start - 1, end))


def solve():
	(n, x) = input().split()
	x = int(x)
	n = int(n)
	l = list(map(int, input().split()))
	pref = [0] * n
	pref[0] = l[0]
	suff = [0] * n
	suff[n - 1] = l[n - 1]
	for i in range(1, n):
		pref[i] = pref[i - 1] + l[i]
	for i in range(n - 2, -1, -1):
		suff[i] = suff[i + 1] + l[i]
	max1 = 0
	max2 = 0
	for i in range(n - 1, -1, -1):
		if pref[i] % x != 0:
			max1 = i + 1
			break
	for i in range(n):
		if suff[i] % x != 0:
			max2 = n - i
			break
	if max1 == 0 and max2 == 0:
		print(-1)
	else:
		print(max(max1, max2))
t = int(input())
while t > 0:
	solve()
	t -= 1


T = int(input())
for _ in range(T):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if sum(arr) % x != 0:
		print(n)
	else:
		su = 0
		ans = -1
		for i in range(n):
			if arr[i] % x != 0:
				ans = max(ans, max(i, n - i - 1))
		print(ans)


def solve(n, mod, A):
	if not A:
		return -1
	s = sum(A)
	if s % mod != 0:
		return len(A)
	else:
		ret = -1
		for (i, x) in enumerate(A):
			if x % mod != 0:
				ret = max(ret, len(A) - i - 1)
		for (i, x) in enumerate(A[::-1]):
			if x % mod != 0:
				ret = max(ret, len(A) - i - 1)
		return ret
from os import sys
ncases = int(sys.stdin.readline().strip())
for _ in range(ncases):
	(n, x) = sys.stdin.readline().split()
	A = sys.stdin.readline().split()
	print(solve(int(n), int(x), [*map(lambda x: int(x), A)]))


from collections import defaultdict
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	l1 = [0] * n
	d = defaultdict(int)
	c = 0
	c1 = 0
	for j in range(n):
		c += l[j] % x
		c %= x
		if c == 0:
			c1 += 1
		l1[j] = c
		d[c] = max(d[c], j)
	l2 = []
	for j in d:
		l2.append([d[j], j])
	l2.sort()
	if c1 == n:
		print(-1)
	else:
		if l2[-1][1] == 0:
			ans = l2[-2][0] + 1
		else:
			ans = l2[-1][0] + 1
		for j in range(1, n):
			if l2[-1][1] == l1[j - 1]:
				ans = max(ans, l2[-2][0] - j + 1)
			else:
				ans = max(ans, l2[-1][0] - j + 1)
		print(ans)


t = int(input())
for i in range(t):
	(n, k) = [int(n) for n in input().split()]
	arr = list(map(int, input().strip().split()))[:n]
	s = 0
	le = 0
	for i in range(n):
		s = s + arr[i]
	if s % k != 0:
		le = n
	else:
		j = n - 1
		p = s
		i = 0
		while j >= 0:
			s = s - arr[j]
			j = j - 1
			if s % k != 0:
				le = max(le, j + 1)
		s = p
		while i < n:
			s = s - arr[i]
			i = i + 1
			if s % k != 0:
				le = max(le, n - i)
		i = 0
		j = n - 1
		s = p
		while i <= j:
			s = s - arr[i]
			i = i + 1
			if s % k != 0:
				le = max(le, j - i + 1)
			s = s - arr[j]
			j = j - 1
			if s % k != 0:
				le = max(le, j - i + 1)
	if le == 0:
		print(-1)
	else:
		print(le)


def CeilIndex(A, l, r, key):
	while r - l > 1:
		m = l + (r - l) // 2
		if A[m] >= key:
			r = m
		else:
			l = m
	return r

def Lo(A, size):
	tailTable = [0 for i in range(size + 1)]
	len = 0
	tailTable[0] = A[0]
	len = 1
	for i in range(1, size):
		if A[i] < tailTable[0]:
			tailTable[0] = A[i]
		elif A[i] > tailTable[len - 1]:
			tailTable[len] = A[i]
			len += 1
		else:
			tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]
	return len
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	x = Lo(a, n)
	print(max(x, 0))


def sol(l, no):
	s = sum(l)
	if s % no != 0:
		return len(l)
	if len(l) % 2 == 0:
		for x in range(len(l) // 2):
			if (s - l[x]) % no != 0 or (s - l[len(l) - x - 1]) % no != 0:
				return len(l) - x - 1
			s = s - l[x] - l[len(l) - x - 1]
			if s % no != 0:
				return len(l) - 2 * x - 2
		return -1
	elif len(l) % 2 == 1:
		for x in range(len(l) // 2):
			if (s - l[x]) % no != 0 or (s - l[len(l) - x - 1]) % no != 0:
				return len(l) - x - 1
			s = s - l[x] - l[len(l) - x - 1]
			if s % no != 0:
				return len(l) - 2 * x - 2
		if l[len(l) // 2] % no == 0:
			return -1
		else:
			return 1
t = int(input())
for _ in range(t):
	(_, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	v = sol(l, x)
	print(v)


for ti in range(int(input())):
	n = int(input())
	print(len(set(input().split())))


t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % x != 0:
		print(n)
		continue
	f = 0
	while f < n and l[f] % x == 0:
		f += 1
	g = 0
	while g < n and l[n - g - 1] % x == 0:
		g += 1
	print(n - 1 - min(f, g))


try:
	t = int(input())
	i = 0
	while i < t:
		n = int(input())
		l = list(map(int, input().split()))
		l = list(set(l))
		print(len(l))
		i += 1
except:
	pass


import sys
sys.setrecursionlimit(100000)
n = int(sys.stdin.readline())
for _ in range(n):
	(length, x) = map(int, sys.stdin.readline().split())
	arr = list(map(int, sys.stdin.readline().split()))
	l = -1
	r = len(arr) - 1
	if sum(arr) % x != 0:
		print(len(arr))
		continue
	for i in range(len(arr)):
		if arr[i] % x != 0:
			if l == -1:
				l = i
			r = i
	if l == -1:
		print(-1)
		continue
	else:
		print(length - min(l + 1, length - r))
		continue


for _ in 'o' * int(input()):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(set(l)))


for _ in range(int(input())):
	(n, x) = [int(c) for c in input().split()]
	arr = [int(c) for c in input().split()]
	ar = [i % x for i in arr]
	if ar.count(0) == len(arr):
		print(-1)
	else:
		mod = [i % x for i in arr]
		if sum(arr) % x != 0:
			print(n)
			continue
		else:
			r = -1
			l = -1
			for i in range(n):
				if mod[i] != 0:
					l = i
					break
			for i in range(n - 1, -1, -1):
				if mod[i] != 0:
					r = i
					break
			print(max(r, n - (l + 1)))


import sys

class AXXXXX:

	def solve(self, tc=0):
		for _ in range(int(input())):
			(n, x) = [int(_) for _ in input().split()]
			a = [int(_) for _ in input().split()]
			pre = [0] * (n + 1)
			for i in range(1, n + 1):
				pre[i] = (pre[i - 1] + a[i - 1]) % x
			d = {i: [] for i in range(x)}
			for i in range(n + 1):
				d[pre[i]].append(i)
			ans = -1
			for i in range(x):
				(mn, mx) = (x, -1)
				for j in range(len(d[i])):
					if d[i][j] != j:
						mn = j
						break
				c = n
				for j in range(len(d[i]) - 1, -1, -1):
					if d[i][j] != c:
						mx = j
						break
					c -= 1
				if mn == x and mx == -1:
					continue
				ans = max(ans, d[i][-1] - mn, mx - d[i][0])
			print(ans)
solver = AXXXXX()
input = sys.stdin.readline
solver.solve()


for i in range(int(input())):
	a = list(map(int, input().strip().split()))[:2]
	b = list(map(int, input().strip().split()))[:a[0]]
	sum = 0
	for j in b:
		sum += j
	sum1 = sum
	if sum % a[1] != 0:
		print(a[0])
	else:
		for k in range(len(b)):
			sum -= b[k]
			if sum % a[1] != 0:
				break
		b.reverse()
		for l in range(len(b)):
			sum1 -= b[l]
			if sum1 % a[1] != 0:
				break
		t = 0
		if l > k:
			t = len(b) - k - 1
		else:
			t = len(b) - l - 1
		if t == 0:
			print(-1)
		else:
			print(t)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	a = []
	for i in l:
		a.append(i % x)
	if sum(a) % x != 0:
		print(n)
	elif set(a) == {0}:
		print('-1')
	else:
		for i in range(n):
			if a[i] or a[-i - 1]:
				print(n - i - 1)
				break


t = int(input())
while t:
	t -= 1
	n = int(input())
	lst = list(map(int, input().split()))
	s = set(lst)
	print(len(s))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	t = sum(l)
	r = 0
	for j in range(len(l)):
		if t % x != 0:
			break
		else:
			t = t - l[j]
			r = r + 1
	z = n - r
	t = sum(l)
	r = 0
	for j in range(n - 1, -1, -1):
		if t % x != 0:
			break
		else:
			t = t - l[j]
			r = r + 1
	z = max(z, n - r)
	if z == 0:
		print(-1)
	else:
		print(z)


for x in range(int(input())):
	(n, h) = list(map(int, input().split()))
	m = list(map(int, input().split()))
	b = sum(m) % h
	if b != 0:
		print(n)
	else:
		r = 'NO'
		k = 0
		for i in range(n // 2):
			if m[i] % h != 0:
				k = n - i - 1
				r = 'YES'
				break
			elif m[n - i - 1] % h != 0:
				k = n - i - 1
				r = 'YES'
				break
		if r == 'NO':
			print(-1)
		else:
			print(k)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	count = 0
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			count += 1
	print(count + 1)


import time, math
from sys import stdin, stdout
from collections import deque
import bisect
from fractions import Fraction
pi = 3.141592653589793

def I():
	return stdin.readline()

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

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

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

def Si():
	return sorted(list(map(int, stdin.readline().split())), reverse=True)

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 solve():
	n = int(input())
	li = L()
	li.sort()
	s = set(li)
	print(len(s))
t = int(input())
for i in range(t):
	solve()


n = int(input())
for _ in range(n):
	b = int(input())
	numbers = list(map(int, input().split()))
	s = set()
	for (index, number) in enumerate(numbers):
		s.add(number)
	print(len(s))


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		ar = list(map(int, input().split()))
		for i in range(1, n):
			ar[i] += ar[i - 1]
		ans = -1
		first = (0, -1)[ar[0] % k == 0]
		for (i, x) in enumerate(ar):
			if x % k == 0:
				if first != -1:
					ans = max(ans, i - first)
			else:
				ans = max(ans, i + 1)
				if first == -1:
					first = i
		print(ans)
main()


from collections import deque
from copy import deepcopy
for _ in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	a = deque([int(i) for i in input().split()])
	if sum(a) % x != 0:
		print(n)
		continue
	temp = deepcopy(a)
	while temp:
		cur = temp.popleft()
		if cur % x != 0:
			break
	temp2 = deepcopy(a)
	while temp2:
		cur = temp2.pop()
		if cur % x != 0:
			break
	ans = max(len(temp), len(temp2))
	ans = ans if ans else -1
	print(ans)


t = int(input())
for i in range(t):
	a = int(input())
	arr = list(map(int, input().split()))
	b = set(arr)
	p = list(b)
	print(len(p))


t = int(input())
for i in range(t):
	a = int(input())
	arr = [int(i) for i in input().split()]
	print(len(set(arr)))


t_count = int(input().strip())
while t_count > 0:
	len_0 = int(input().strip())
	list_0 = list(map(int, input().strip().split(' ')))
	out_len = len(set(list_0))
	print(out_len)
	t_count -= 1


for i in range(int(input())):
	n = int(input())
	mp = set()
	arr = [int(a) for a in input().split()]
	for a in arr:
		mp.add(a)
	print(len(mp))


t = int(input())
for z in range(t):
	n = int(input())
	a = input()
	l = a.split(' ')
	s = set(l)
	print(len(s))


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	(n, x) = map(int, input().split())
	ar = list(map(int, input().split()))
	p = [0]
	for i in range(n):
		p.append(p[-1] + ar[i])
	m = [0] * (n + 1)
	for i in range(1, n + 1):
		m[i] = p[i] % x
	ans = 0
	nn = -1
	for i in range(1, n + 1):
		if m[i] != 0:
			ans = max(i, ans)
			if nn == -1:
				nn = i
		elif nn != -1:
			ans = max(i - nn, ans)
	if ans == 0:
		print(-1)
		continue
	print(ans)


t = int(input())
for case in range(t):
	dic = set()
	ans = 0
	n = int(input())
	for i in (int(k) for k in input().split()):
		if i not in dic:
			ans += 1
			dic.add(i)
	print(ans)


t = int(input())
for i in range(t):
	(n, h) = map(int, input().split())
	l = list(map(int, input().split()))
	left = -1
	flag = 0
	for j in range(n):
		if l[j] % h != 0:
			left = j
			break
	else:
		flag = 1
		print('-1')
	if flag == 0:
		right = -1
		j = n - 1
		while j >= 0:
			if l[j] % h != 0:
				right = j
				break
			j -= 1
		s = sum(l)
		if s % h != 0:
			print(n)
		else:
			m = min(left + 1, n - right)
			print(n - m)


t = int(input())
while t != 0:
	(n, x) = map(int, input().split())
	list1 = list(map(int, input().split()))
	for i in range(len(list1)):
		list1[i] = list1[i] % x
	s = sum(list1)
	if s % x == 0:
		st = 0
		ed = 0
		for i in range(n):
			if list1[i] % x != 0:
				st = i
				break
		for j in range(n - 1, -1, -1):
			if list1[j] % x != 0:
				ed = j
				break
		if st == ed == 0:
			print(-1)
		else:
			print(max(n - (st + 1), ed))
	else:
		print(n)
	t -= 1


def check(arr, x):
	n = len(arr)
	total = sum(arr)
	for ind in range(n):
		if total % x != 0:
			return n - ind
		total -= arr[ind]
	return -1
t = int(input())
for _ in range(t):
	(n, x) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	reversed_arr = [elem for elem in reversed(arr)]
	print(max(check(arr, x), check(reversed_arr, x)))


def max_len(lst, x):
	mx = -1
	s = 0
	for i in range(len(lst)):
		s = s + lst[i]
		if s % x != 0:
			mx = max(mx, i + 1)
	for i in range(len(lst)):
		s -= lst[i]
		if s % x != 0:
			mx = max(mx, len(lst) - i - 1)
	return mx
t = int(input())
for _ in range(t):
	(n, x) = input().split()
	lst = input().split()
	lst = [int(i) for i in lst]
	print(max_len(lst, int(x)))


from sys import *
for _ in range(int(stdin.readline())):
	(n, h) = map(int, input().split())
	l = [int(x) for x in input().split()]
	flag = 0
	i = 0
	j = n
	x = sum(l)
	x1 = x
	y1 = x
	if not x % h == 0:
		print(n)
		flag = 1
	while i < n // 2 and j >= n // 2 and (not flag):
		x1 = x1 - l[i]
		y1 = y1 - l[j - 1]
		if not x1 % h == 0:
			print(n - i - 1)
			flag = 1
			break
		if not y1 % h == 0 and (not flag):
			print(j - 1)
			flag = 1
			break
		i += 1
		j -= 1
	if not flag:
		print(-1)


for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	print(len(set(l)))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	index = []
	for i in range(n):
		if arr[i] % x != 0:
			index.append(i)
			break
	for j in range(n - 1, -1, -1):
		if arr[j] % x != 0:
			index.append(j)
			break
	if sum(arr) % x != 0:
		print(n)
	elif index == []:
		print(-1)
	else:
		print(max(n - index[0] - 1, index[1]))


def sol():
	T = int(input())
	for i in range(T):
		size = int(input())
		A = list(map(int, input().split(' ')))
		num_set = set()
		for n in A:
			num_set.add(n)
		print(len(num_set))
sol()


from collections import Counter as ctr
from collections import defaultdict as dd
from sys import stdin, stdout
for t in range(int(stdin.readline().strip())):
	(n, x) = map(int, stdin.readline().strip().split())
	a = list(map(int, stdin.readline().strip().split()))
	s = sum(a)
	l1 = l2 = -1
	m = s % x
	if m:
		print(n)
		continue
	for i in range(n):
		if a[i] % x:
			l1 = n - i - 1
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x:
			l2 = i
			break
	print(max(l1, l2))


from math import *

def binarySearch(arr, x, i):
	l = i
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def js(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] <= x:
			ans = m
			l = m + 1
		else:
			r = m - 1
	return ans

def jg(arr, x, i):
	l = i
	r = len(arr) - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if arr[m] >= x:
			ans = m
			r = m - 1
		else:
			l = m + 1
	return ans
for i in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ar = list(set(ar))
	print(len(ar))


import math
for _ in range(int(input())):
	n = int(input())
	data = list(map(int, input().split()))
	data.sort()
	repCount = 0
	val = data[0]
	for i in range(1, n):
		if val == data[i]:
			repCount += 1
		val = data[i]
	print(n - repCount)


from sys import stdin, exit
input = stdin.readline

def i():
	return input()

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

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

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

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	(n, x) = iis()
	a = liis()
	soma = sum(a)
	if soma % x != 0:
		print(n)
	else:
		for i in range(n):
			if a[i] % x != 0:
				break
		for j in range(n):
			if a[-j - 1] % x != 0:
				break
		if (i != n or j != n) and n - min(i, j) - 1 != 0:
			print(n - min(i, j) - 1)
		else:
			print(-1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	ar = list(map(int, input().split()))
	sumi = sum(ar)
	if sumi % x == 0:
		front = 0
		end = 0
		fl = 0
		el = 0
		for i in range(0, n):
			front += ar[i]
			fl += 1
			if front % x != 0:
				break
		for i in range(n - 1, -1, -1):
			end += ar[i]
			el += 1
			if end % x != 0:
				break
		mini = min(fl, el)
		if mini == n:
			print(-1)
		else:
			print(n - mini)
	else:
		print(n)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	y = sum(arr)
	if y % x == 0:
		nd = []
		for i in range(len(arr)):
			if arr[i] % x != 0:
				nd.append(i)
		if nd == []:
			print(-1)
		else:
			print(max(n - min(nd) - 1, max(nd)))
	else:
		print(len(arr))


from sys import stdin, stdout, setrecursionlimit
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	ok = []
	for i in range(n):
		if a[i] % x != 0:
			ok.append(i)
	if len(ok) == 0:
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		print(max(n - ok[0] - 1, ok[-1]))


import math
import itertools
mp = lambda : map(int, input().split())
mod = 998244353
mod = int(mod)

def main():
	t = int(input())
	while t:
		t -= 1
		input()
		x = {}
		for i in list(mp()):
			if i not in x.keys():
				x[i] = 1
		print(len(x))
main()


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	lengt = []
	if s % k != 0:
		print(n)
	else:
		ini = 0
		while ini < n and l[ini] % k == 0:
			ini += 1
		final = n - 1
		while final >= 0 and l[final] % k == 0:
			final -= 1
		if ini == n:
			print(-1)
		else:
			length = max(n - 1 - ini, final)
			print(length)


for _ in range(int(input())):
	a = int(input())
	l = set(list(map(int, input().split())))
	ll = sorted(l)
	print(len(ll))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
		continue
	first = -1
	for i in range(n):
		if a[i] % x != 0:
			first = i
			break
	if first == -1:
		print(-1)
		continue
	last = 0
	for i in range(n - 1, -1, -1):
		if a[i] % x != 0:
			last = i
			break
	print(max(n - first - 1, last))


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	x = stdin.readline()
	y = set(map(int, stdin.readline().split()))
	print(len(y))


for _ in range(int(input())):
	n = int(input())
	d = {i: True for i in input().split()}
	print(len(d))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for _ in range(get_int()):
	n = get_int()
	print(len(set(get_list())))


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from collections import *
for _ in range(ii()):
	(n, x) = f()
	a = il()
	c = 0
	k = []
	if sum(a) % x != 0:
		print(n)
	else:
		l = sum(a)
		for i in range(0, n):
			if (l - a[i]) % x != 0:
				k.append(n - i - 1)
				c = c + 1
				break
		for i in range(n - 1, -1, -1):
			if (l - a[i]) % x != 0:
				k.append(i)
				c = c + 1
				break
		if c == 0:
			print('-1')
		else:
			print(max(k))


t = int(input())
for test in range(t):
	(n, x) = map(int, input().rstrip().split())
	a = list(map(int, input().rstrip().split()))
	if x == 1:
		print(-1)
	else:
		s = sum(a) % x
		counter = 0
		for el in a:
			if el % x == 0:
				counter += 1
		if s != 0:
			print(n)
		elif counter == n:
			print(-1)
		else:
			massimaLunghezza = 0
			for i in range(n):
				if a[i] % x != 0:
					massimaLunghezza = max([massimaLunghezza, n - 1 - i, i])
			print(massimaLunghezza)


for _ in range(int(input())):
	d = {}
	inp1 = input()
	inp2 = list(map(int, input().split()))
	for num in inp2:
		if num not in d:
			d[num] = num
	print(len(d))


for _ in range(int(input())):
	(n, x) = map(int, input().split(' '))
	a = [i for i in map(int, input().split(' '))]
	ans = n
	start = n
	end = -1
	for i in range(len(a)):
		if a[i] % x != 0:
			start = min(start, i)
			end = max(end, i)
	if start != n:
		if sum(a) % x == 0:
			print(n - min(start + 1, n - end))
		else:
			print(n)
	else:
		print(-1)


testCases = int(input())
for i1 in range(testCases):
	length = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	print(len(b))


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda : input()
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()
for _ in range(t):
	(n, x) = iia()
	a = iia()
	cur = 0
	maxi = 0
	pre = [0] * n
	pos = [0] * n
	for i in range(0, n):
		pre[i] = pre[i - 1] + a[i]
	pos[n - 1] = a[n - 1]
	for i in range(n - 2, -1, -1):
		pos[i] = pos[i + 1] + a[i]
	for i in range(n):
		if pre[i] % x != 0:
			maxi = max(maxi, i + 1)
	for i in range(n):
		if pos[i] % x != 0:
			maxi = max(maxi, n - i)
	if maxi == 0:
		maxi = -1
	print(maxi)


def arr_copy(arr):
	return len(set(arr))
t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().rstrip().split()))
	print(arr_copy(x))


from collections import defaultdict, Counter
import copy, math
from copy import deepcopy
s = 'abcdefghijklmnopqrstuvwxyz' * 7
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(n)
		continue
	s = 0
	for i in range(n // 2):
		if l[i] % x != 0:
			s = n - i - 1
			break
		if l[-1 - i] % x != 0:
			s = n - i - 1
			break
	if s == 0:
		print(-1)
	else:
		print(s)


def ques2(n, a):
	a = set(a)
	print(len(a))
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = ques2(n, a)
	ans


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sumA = sum(a)
	if sumA % x != 0:
		print(len(a))
	else:
		firstNonZero = len(a)
		lastNonZero = -1
		for i in range(len(a)):
			if a[i] % x != 0:
				if firstNonZero > i:
					firstNonZero = i
				if lastNonZero < i:
					lastNonZero = i
		smallestRemoval = min(firstNonZero, len(a) - 1 - lastNonZero)
		if smallestRemoval == len(a):
			print(-1)
		else:
			print(len(a) - smallestRemoval - 1)


t = int(input())
rez = []
for i in range(t):
	A = input().split(' ')
	n = int(A[0])
	x = int(A[1])
	a = input().split(' ')
	k = 0
	sum = 0
	ll = n + 1
	rr = n + 1
	l = []
	for j in range(n):
		a[j] = int(a[j])
		if a[j] % x == 0:
			l.append(1)
			k += 1
		else:
			l.append(0)
		sum += a[j]
	if k == n:
		rez.append(-1)
	elif sum % x != 0:
		rez.append(n)
	else:
		for j in range(n // 2):
			if l[j] == 0:
				ll = j + 1
				break
		for j in range(1, n - n // 2 + 1):
			if l[n - j] == 0:
				rr = j
				break
		rez.append(n - min(ll, rr))
for i in range(len(rez)):
	print(rez[i])


def fun(x):
	return list(dict.fromkeys(x))
p = input
n = int
for i in range(n(p())):
	p()
	lis = fun(list(map(n, p().split())))
	print(len(lis))


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	Query.append((N, K, A))
MAX = 10 ** 4 + 3
for (N, K, A) in Query:
	nonzero = -1
	t = 0
	ans = 0
	for (i, a) in enumerate(A):
		t = (t + a) % K
		if t != 0:
			ans = max(ans, i + 1)
			if nonzero == -1:
				nonzero = i
		elif nonzero != -1:
			ans = max(ans, i - nonzero)
	if nonzero == -1:
		ans = -1
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	s = 0
	ans1 = 0
	ans2 = 0
	for i in range(n):
		if a[i] % x == 0:
			c += 1
		s += a[i]
	if c == n:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		for i in range(n):
			if a[i] % x != 0:
				ans1 = i + 1
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				ans2 = n - i
				break
		print(n - min(ans1, ans2))


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


t = int(input())
for ti in range(1, t + 1):
	n = int(input())
	a = list(map(int, input().split()))
	s = set()
	for num in a:
		s.add(num)
	print(len(s))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	array = list(map(int, input().split()))
	check = True
	s = 0
	for a in array:
		if a % x != 0:
			check = False
		s += a
	if s % x != 0:
		print(n)
	elif not check:
		for i in range(n):
			if array[i] % x != 0:
				ans1 = n - i - 1
				break
		for i in range(n - 1, -1, -1):
			if array[i] % x != 0:
				ans2 = i
				break
		print(max(ans1, ans2))
	else:
		print(-1)


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		N = int(input())
		A = map(int, input().split())
		print(len(set(A)))
main()


for tc in range(int(input())):
	n = int(input())
	lis = [int(i) for i in input().split()]
	l = set()
	for i in lis:
		l.add(i)
	print(len(l))


from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	i = 0
	j = n - 1
	su = sum(l)
	if su % m != 0:
		print(n)
	else:
		ss = su
		cou1 = 0
		while i < n and ss % m == 0:
			ss -= l[i]
			i += 1
			cou1 += 1
		ss = su
		cou2 = 0
		while j >= 0 and ss % m == 0:
			ss -= l[j]
			j -= 1
			cou2 += 1
		cou = min(cou1, cou2)
		if n - cou == 0:
			print(-1)
		else:
			print(n - cou)
	t -= 1


t = int(input())
for loop in range(t):
	a = int(input())
	c = list(map(int, input().split()))
	print(len(set(c)))


q = int(input())
for i in range(q):
	no = int(input())
	a = set(list(map(int, input().split())))
	print(len(a))


test_case = int(input())
for i in range(test_case):
	n = int(input())
	l = list(map(int, input().split(' ')))
	print(len(set(l)))


for _ in range(int(input())):
	n = int(input())
	liStr = input().split()
	s = set()
	for i in liStr:
		a = int(i)
		s.add(a)
	print(len(s))


t = int(input())
for v in range(t):
	n = int(input())
	li = list(map(int, input().split(' ')))
	dic = {}
	for item in li:
		dic.update({item: 1})
	print(len(dic))


from sys import stdin, stdout
t = int(stdin.readline().rstrip())
for tests in range(t):
	(n, x) = map(int, stdin.readline().rstrip().split())
	a = [int(x) for x in stdin.readline().rstrip().split()]
	if sum(a) % x == 0:
		max_length = 0
		for i in range(0, n):
			if a[i] % x != 0:
				candidate = max(i, n - 1 - i)
				max_length = max(candidate, max_length)
		if max_length == 0:
			max_length = -1
	else:
		max_length = len(a)
	print(max_length)


t = int(input())
for _ in range(t):
	(n, x) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	(count, sum, c1, c2) = (0, 0, 0, 0)
	for i in range(n):
		if a[i] % x == 0:
			count += 1
	if count == n:
		print(-1)
	else:
		(l, r) = (-1, -1)
		for i in range(n):
			sum += a[i]
		if sum % x != 0:
			print(n)
		else:
			for i in range(n):
				if a[i] % x != 0:
					l = i
					break
			for i in reversed(range(n)):
				if a[i] % x != 0:
					r = i
					break
			if l == -1:
				ans1 = n
			else:
				ans1 = l + 1
			if r == -1:
				ans2 = n
			else:
				ans2 = n - r
			ans = min(ans1, ans2)
			print(n - ans)


for _ in [0] * int(input()):
	(n, ans) = (input(), len(set(map(int, input().split()))))
	print(ans)


import os, sys
from io import IOBase, BytesIO
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
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
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

def outarr(*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(m, val) for j in range(n)]
for _ in range(int(data())):
	(n, x) = sp()
	arr = l()
	if sum(arr) % x != 0:
		out(n)
		continue
	r = arr[0] % x == 0
	for i in range(1, n):
		if arr[i] % x != 0:
			r = False
		arr[i] += arr[i - 1]
	if r:
		out(-1)
		continue
	answer = 1
	for i in range(n):
		if i == 0:
			if (arr[-1] - arr[0]) % x != 0:
				answer = n - 1
				break
		if (arr[-1] - arr[i]) % x != 0:
			answer = max(answer, n - i - 1)
		if arr[i - 1] % x != 0:
			answer = max(answer, i)
	out(answer)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(n, x) = [int(zz) for zz in input().split()]
	a = [int(zz) for zz in input().split()]
	summ = 0
	for zz in a:
		summ += zz
		summ %= x
	if summ != 0:
		print(n)
		continue
	nonMultipleIndexes = []
	for i in range(n):
		if a[i] % x != 0:
			nonMultipleIndexes.append(i)
	if len(nonMultipleIndexes) == 0:
		print(-1)
		continue
	print(max(n - 1 - nonMultipleIndexes[0], nonMultipleIndexes[-1]))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	array = [int(x) for x in input().split()]
	sum_array = sum(array)
	res = sum_array
	tmp = -1
	if sum_array % x != 0:
		print(n)
		continue
	for i in range(n):
		res -= array[i]
		if res % x != 0:
			tmp = max(n - i - 1, tmp)
			break
	res = sum_array
	for i in range(n):
		res -= array[n - 1 - i]
		if res % x != 0:
			tmp = max(tmp, n - i - 1)
			break
	print(tmp if tmp != -1 else -1)


import sys

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

def get():
	return int(sys.stdin.readline().strip())

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

def getli():
	return list(map(int, sys.stdin.readline().strip().split()))
for _ in range(get()):
	(n, x) = geti()
	A = getli()
	Sum = sum(A)
	i = 0
	S = Sum
	while Sum % x == 0 and Sum > 0:
		Sum -= A[i]
		i += 1
	j = n
	while S % x == 0 and S > 0:
		j -= 1
		S -= A[j]
	if S or Sum:
		print(max(n - i, j))
	else:
		print(-1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	ar = list(map(int, input().split()))
	li = []
	su = 0
	for i in range(n):
		su += ar[i]
		li.append(su)
	ans = 0
	flag = False
	for i in range(n):
		if li[i] % x != 0:
			flag = True
			break
	for j in range(n):
		if li[j] % x != 0:
			ans = max(ans, j + 1)
		elif flag and i < j:
			ans = max(ans, j - i)
	if ans == 0:
		print(-1)
	else:
		print(ans)


import sys

def main():
	t = int(sys.stdin.readline())
	count = {}
	for i in range(t):
		sys.stdin.readline()
		ans = tuple(map(int, sys.stdin.readline().split()))
		for i in ans:
			count[i] = count.get(i, 0) + 1
		sys.stdout.write(f'{len(count)}\n')
		count.clear()
main()


for count in range(int(input())):
	size = int(input())
	a = list(map(int, input().split()))
	a = set(a)
	print(len(a))


for k in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	ar.sort()
	ctr = 1
	for k in range(1, n):
		if ar[k] != ar[k - 1]:
			ctr += 1
	print(ctr)


t = int(input())
for h in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = set(a)
	print(len(b))


from collections import Counter
for t in range(int(input())):
	length = int(input())
	lis = list(map(int, input().split()))
	lis = Counter(lis)
	print(len(lis))


sum_n = 0
testcase_num = int(input())
result = []
while testcase_num > 0:
	n = int(input())
	sum_n += n
	if sum_n > pow(10, 5):
		break
	if 1 <= n and n <= pow(10, 5):
		a = input()
		list_num = a.split()
		for (stt, item) in enumerate(list_num):
			list_num[stt] = int(item)
			if list_num[stt] < 1 or list_num[stt] > pow(10, 9):
				pass
		out = set(list_num)
		result.append(len(out))
	testcase_num -= 1
for r in result:
	print(r)


T = int(input())
while T > 0:
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	c = 1
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			c += 1
	print(c)
	T -= 1


from collections import Counter

def count(l):
	return len(Counter(l).keys())
t = int(input())
for i in range(t):
	n = int(input())
	l = [int(j) for j in input().split()]
	print(count(l))


import sys

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

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, x, a):
	if sum([1 for ai in a if ai % x == 0]) == n:
		return -1
	s = sum(a)
	if s % x > 0:
		return n
	mm = n + 1
	left = mm
	right = mm
	for i in range(n):
		if left == mm and a[i] % x > 0:
			left = i
		if right == mm and a[n - i - 1] % x > 0:
			right = i
	return n - min(left + 1, right + 1)

def main():
	for _ in range(ri()):
		(n, x) = ria()
		a = ria()
		wi(solve(n, x, a))
main()


res = []
t = int(input())
for z in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l = set(l)
	res.append(len(l))
for z in res:
	print(z)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	print(len(set(a)))


import sys
readline = sys.stdin.readline

def solve():
	(N, X) = map(int, readline().split())
	A = list(map(int, readline().split()))
	if sum(A) % X != 0:
		print(N)
		return
	l = -1
	for i in range(N):
		if A[i] % X != 0:
			l = i
			break
	r = -1
	for i in range(N):
		if A[N - 1 - i] % X != 0:
			r = i
			break
	if l == -1:
		print(-1)
	else:
		print(N - min(l, r) - 1)
T = int(readline())
for t in range(T):
	solve()


t = int(input())
for i in range(t):
	y = int(input())
	max = set(list(map(int, input().split())))
	print(len(max))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	count = 1
	for i in range(len(l)):
		if i == len(l) - 1:
			break
		if l[i] != l[i + 1]:
			count += 1
	print(count)


test = int(input())
for _ in range(test):
	n = int(input())
	l = list(map(int, input().split()))
	res = len(set(l))
	print(res)


from math import ceil
n = int(input())
for i in range(n):
	t = int(input())
	a = set(list(map(int, input().split())))
	print(len(a))


for _ in [0] * int(input()):
	x = int(input())
	a = set(map(int, input().split()))
	print(len(a))


import sys
input = sys.stdin.readline
from math import *
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	print(len(set(a)))


from sys import stdin
T = int(input())
for _ in range(T):
	(n,) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	print(len(set(arr)))


t = int(input())
for b in range(t):
	n = int(input())
	array = [int(x) for x in input().split()]
	print(len(set(array)))


from sys import stdin, stdout

def input():
	a = stdin.readline()
	if a[-1] == '\n':
		a = a[:-1]
	return a

def print(*argv, end='\n', sep=' '):
	n = len(argv)
	for i in range(n):
		if i == n - 1:
			stdout.write(str(argv[i]))
		else:
			stdout.write(str(argv[i]) + sep)
	stdout.write(end)
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def comb(lst, x):
	return list(c(lst, x))

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

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def smaller(lst, x):
	return bisect_left(lst, x) - 1

def smallerEq(lst, x):
	return bisect_right(lst, x) - 1

def solve(n, lst):
	se = set()
	for i in lst:
		se.add(i)
	return len(se)
for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	print(solve(n, lst))


for i in range(int(input())):
	n = int(input())
	a = set(sorted(map(int, input().split())))
	d = len(a)
	if d > n:
		print(n)
	else:
		print(d)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s1 = s2 = sum(arr)
	str = rev = n
	for i in range(n):
		if s1 % x == 0:
			s1 -= arr[i]
			str -= 1
		else:
			break
		if s2 % x == 0:
			s2 -= arr[n - 1 - i]
			rev -= 1
		else:
			break
	ans = max(str, rev)
	if ans == 0:
		print(-1)
	else:
		print(ans)


dct = dict()

def main():
	n = int(input())
	a = set(map(int, input().split()))
	print(len(a))
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(t):
	(nn, xx) = map(int, input().split())
	aa = list(map(int, input().split()))
	if sum(aa) % xx != 0:
		print(nn)
		continue
	else:
		ll = 0
		mm = nn - 1
		anss = -1
		while ll <= mm:
			if aa[mm] % xx != 0:
				anss = mm
				break
			if aa[ll] % xx != 0:
				anss = nn - ll - 1
				break
			ll += 1
			mm -= 1
	print(anss)


for t in range(int(input())):
	n = list(map(int, input().split()))
	q = n[0]
	x = n[1]
	boo = False
	a = list(map(int, input().split()))
	if sum(a) % x == 0:
		for i in range(q):
			if a[i] % x != 0 or a[q - i - 1] % x != 0:
				print(q - i - 1)
				boo = True
				break
		if not boo:
			print('-1')
	else:
		print(q)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if len(a) == 0:
		res = -1
	else:
		s = sum(a)
		if s % k:
			res = len(a)
		elif len(a) == 1:
			res = -1
		else:
			ind = -1
			i = 0
			j = len(a) - 1
			while i < j:
				if a[i] % k:
					ind = i
					break
				if a[j] % k:
					ind = j
					break
				i += 1
				j -= 1
			if ind == -1:
				res = -1
			elif ind < len(a) // 2:
				res = len(a) - ind - 1
			else:
				res = ind
	print(res)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	for i in range(1, len(s)):
		s[i] = s[i] + s[i - 1]
	len_sub = -1
	curr_ind = -1
	if s[0] % m != 0:
		curr_ind = 0
		len_sub = 1
	for i in range(1, len(s)):
		if s[i] % m != 0:
			len_sub = i + 1
			if curr_ind == -1:
				curr_ind = i
		elif curr_ind != -1:
			len_sub = max(len_sub, i - curr_ind)
	print(len_sub)


n = int(input())
for j in range(n):
	a = int(input())
	b = list(map(int, input().split()))
	c = set(b)
	print(len(c))


t = int(input())
for case in range(t):
	(n, x) = list(map(int, input().split(' ')))
	arr_a = list(map(int, input().split(' ')))
	lowest_nondiv = -1
	for i in range(n):
		if arr_a[i] % x != 0:
			lowest_nondiv = i
			break
	if lowest_nondiv == -1:
		print(-1)
	else:
		highest_nondiv = -1
		for i in range(n - 1, -1, -1):
			if arr_a[i] % x != 0:
				highest_nondiv = i
				break
		if sum(arr_a) % x != 0:
			print(n)
		else:
			print(max(n - lowest_nondiv - 1, highest_nondiv))


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	(n, x) = map(int, inp().split())
	a = list(map(int, inp().split()))
	f = False
	for i in a:
		if i % x != 0:
			f = True
			break
	if not f:
		print(-1)
		continue
	pre = 0
	mxl = 1
	prev = -1
	for i in range(n):
		pre += a[i]
		mod = pre % x
		if mod != 0:
			mxl = max(mxl, i + 1)
			if prev == -1:
				prev = i
		elif prev != -1:
			mxl = max(mxl, i - prev)
	print(mxl)


for _ in range(int(input())):
	(n, x) = [int(_) for _ in input().split()]
	A = [int(_) for _ in input().split()]
	if all([not int(_) % x for _ in A]):
		print(-1)
	elif sum(A) % x != 0:
		print(n)
	else:
		for _ in range(n):
			if A[_] % x != 0:
				i = _
				break
		for _ in range(n - 1, -1, -1):
			if A[_] % x != 0:
				j = _
				break
		print(max(n - i - 1, j))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split(' '))
	oddmod = False
	arr = [v for v in map(int, input().split(' '))]
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	numdelfront = 0
	for v in arr:
		numdelfront += 1
		if v % x != 0:
			break
	numdelback = 0
	for v in arr[::-1]:
		numdelback += 1
		if v % x != 0:
			break
	mindel = min(numdelfront, numdelback)
	if n - mindel != 0:
		print(n - mindel)
	else:
		print(-1)


def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	a = set(A)
	print(len(a))
T = int(input())
for t in range(T):
	f()


def lis(arr):
	return len(sorted(set(arr)))

def main():
	t = int(input())
	for i in range(t):
		input()
		print(lis(list(map(int, input().split()))))
main()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	line = sys.stdin.readline().split()
	print(len(set(line)))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	hashset = {l[0]}
	for i in l:
		if i not in hashset:
			hashset.add(i)
	print(len(hashset))


def copy(s):
	return len(set(s))
tc = int(input())
for i in range(tc):
	n = int(input())
	cc = list(map(int, input().split()))
	print(copy(cc))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi, log
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from functools import cmp_to_key, reduce
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def solve():
	T = int(sys.stdin.readline())
	for _ in range(T):
		(n, k) = map(int, sys.stdin.readline().split())
		a = list(map(int, sys.stdin.readline().split()))
		c = 0
		for i in a:
			if i % k == 0:
				c += 1
		if c == n:
			print(-1)
		elif sum(a) % k != 0:
			print(n)
		else:
			(l, r) = (None, None)
			for i in range(n):
				if a[i] % k != 0:
					l = i
					break
			for i in range(n - 1, -1, -1):
				if a[i] % k != 0:
					r = i
					break
			print(n - min(l + 1, n - r))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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 main():
	t = int(input())
	for i in range(t):
		nx = list(map(int, input().split()))
		(n, x) = (nx[0], nx[1])
		a = list(map(int, input().split()))
		(pre, suf) = ([0], [0])
		cnt = 0
		s = sum(a)
		for j in range(len(a)):
			pre.append(pre[-1] + a[j])
			if a[j] % x == 0:
				cnt += 1
		for k in a[::-1]:
			suf.append(suf[-1] + k)
		if cnt == n:
			print(-1)
			continue
		mx = 0
		for l in range(len(pre)):
			if pre[l] % x != s % x:
				mx = max(mx, n - l)
				break
		for r in range(len(suf)):
			if suf[r] % x != s % x:
				mx = max(mx, n - r)
				break
		print(mx)
main()


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, x) = stdin.readline().strip().split(' ')
	(n, x) = (int(n), int(x))
	arr = list(map(int, stdin.readline().strip().split(' ')))
	if sum(arr) % x != 0:
		stdout.write(str(n) + '\n')
		continue
	l = -1
	r = -1
	for i in range(len(arr)):
		if arr[i] % x != 0:
			l = i
			break
	for i in range(len(arr)):
		if arr[n - 1 - i] % x != 0:
			r = i
			break
	ans = min(l, r) + 1
	if ans == 0:
		stdout.write(str(-1) + '\n')
	else:
		stdout.write(str(n - ans) + '\n')


from sys import stdin
t = int(input())
o = []
for i in range(t):
	ne = int(input())
	e = [int(x) for x in stdin.readline().split()]
	print(len(set(e)))


t = int(input())
for u in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % k
	sumi = sum(a)
	if sumi % k != 0:
		print(n)
	else:
		st = -1
		en = -1
		for i in range(n):
			if a[i] != 0:
				st = i + 1
				break
		for i in range(n - 1, -1, -1):
			if a[i] != 0:
				en = n - i
				break
		if st != -1:
			print(n - min(st, en))
		else:
			print(st)


list_ans = []
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list2 = list1[:][::-1]
	if sum(list1) % x != 0:
		list_ans.append(n)
	else:
		for i in range(n // 2 + 1):
			if list1[i] % x != 0 or list2[i] % x != 0:
				list_ans.append(n - i - 1)
				break
		else:
			list_ans.append(-1)
for item in list_ans:
	print(item)


t = int(input())
for test in range(t):
	(n, x) = map(int, input().split())
	nums = list(map(int, input().split()))
	sumS = sum(nums)
	sumE = sumS
	i = 0
	j = n - 1
	if not sumS % x:
		while n > 0:
			if sumS % x == 0 and sumE % x == 0:
				sumS -= nums[i]
				sumE -= nums[j]
				i += 1
				j -= 1
				n -= 1
			elif sumS % x != 0 or sumE % x != 0:
				break
	if n:
		print(n)
	else:
		print(-1)


from sys import stdin
input = stdin.readline
for xoxo in range(1):
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		print(len(set(a)))


from sys import stdin

def r():
	return stdin.readline().strip()

def r_t(tp):
	return map(tp, r().strip().split())

def r_a(tp):
	return list(r_t(tp))

def solve(n, x, A):
	sm = sum(A)
	if sm % x != 0:
		return n
	(ans, ac) = (-1, 0)
	for i in range(n):
		ac += A[i]
		if ac % x != 0:
			ans = max(ans, i + 1)
	ac = 0
	for i in range(n - 1, -1, -1):
		ac += A[i]
		if ac % x != 0:
			ans = max(ans, n - i)
	return ans

def main():
	cases = int(r())
	for case in range(cases):
		(n, x) = r_t(int)
		A = list(r_t(int))
		print(solve(n, x, A))
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = r = 0
	flag = False
	for j in range(n):
		l += a[j]
		if l % x != 0:
			flag = True
			l = j + 1
			break
	if not flag:
		l = 100001
	flag = False
	for j in range(n):
		r += a[n - j - 1]
		if r % x != 0:
			flag = True
			r = j + 1
			break
	if not flag:
		r = 100001
	if sum(a) % x != 0:
		print(n)
	elif l == 100001 and r == 100001:
		print(-1)
	else:
		print(n - min(l, r))


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	rem = []
	for i in arr:
		rem.append(i % x)
	if sum(rem) % x != 0:
		print(n)
	elif set(rem) == {0}:
		print(-1)
	else:
		for i in range(n):
			if rem[i] or rem[-1 - i]:
				print(n - i - 1)
				break


import sys
Input = sys.stdin.readline
lst = []
x = int(input())
for i in range(x):
	n = input()
	l = set(list(map(int, input().split())))
	k = len(l)
	print(k)


t = int(input())
for jack in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
		continue
	(l, r) = (-1, -1)
	for i in range(n):
		if l == -1 and a[i] % x != 0:
			l = i
		if r == -1 and a[n - 1 - i] % x != 0:
			r = n - i - 1
	if l != -1:
		print(max(n - l - 1, r))
	else:
		print(-1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	div = 0
	lis = []
	if sum(arr) % k != 0:
		print(n)
	else:
		for i in range(n):
			if arr[i] % k != 0:
				lis.append(min(i + 1, n - i))
			else:
				div += 1
		if div == n:
			print(-1)
		else:
			print(n - min(lis))


def copy_str(arr):
	s = len(set(arr))
	return s
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(copy_str(arr))


t = int(input())
for j in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	flag = 0
	if sum(l) % x == 0:
		for i in range(n):
			if l[i] % x != 0:
				print(n - (i + 1))
				flag += 1
				break
			elif l[-(i + 1)] % x != 0:
				print(n - (i + 1))
				flag += 1
				break
		if flag == 0:
			print(-1)
	else:
		print(n)


from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(stdin.readline())
	l = [int(i) for i in stdin.readline().split()]
	stdout.write(str(len(set(l))) + '\n')


t = int(input())
for w in range(t):
	n = int(input())
	L = sorted(list(map(int, input().split())))
	c = n
	if n == 1:
		print(1)
	else:
		k = L[0]
		for i in L[1:]:
			if i == k:
				c = c - 1
			k = i
		print(c)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	y = [i % x == 0 for i in l]
	if s % x != 0:
		print(n)
	elif False not in y:
		print(-1)
	else:
		y = []
		for i in range(n):
			if l[i] % x != 0:
				y.append(i)
		print(n - min(y[0] + 1, n - y[-1]))


for _ in range(int(input())):
	a = int(input())
	al = [int(x) for x in input().split()]
	print(len(set(al)))


import sys
import bisect as b
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def pref(a, n):
	pre = [0] * n
	pre[0] = a[0]
	for i in range(1, n):
		pre[i] = a[i] + pre[i - 1]
	return pre
for _ in range(inin()):
	(n, x) = cin()
	l = ain()
	s = sum(l)
	l1 = l[::-1]
	f = f1 = 0
	if s % x != 0:
		print(n)
	else:
		ans = n
		ans1 = n
		pre1 = pref(l, n)
		pre2 = pref(l1, n)
		for i in range(n):
			if (s - pre1[i]) % x != 0 and f == 0:
				ans = i
				f = 1
			if (s - pre2[i]) % x != 0 and f1 == 0:
				ans1 = i
				f1 = 1
		if ans == n and ans1 == n:
			print(-1)
		else:
			print(max(n - ans - 1, ans + 1, ans1 + 1, n - ans1 - 1))


try:
	for i in range(int(input())):
		n = int(input())
		w = list(map(int, input().split()))
		print(len(set(w)))
except:
	pass


cn = int(input())
for d in range(cn):
	mm = int(input())
	ar = list(map(int, input().split()))
	arn = ar + ar
	sr = set(arn)
	print(len(sr))


def main(n, xs):
	r = len(set(xs))
	return r
t = int(input())
for _ in range(t):
	n = int(input())
	xs = [int(x) for x in input().split()]
	r = main(n, xs)
	print(r)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	l = [int(x) for x in input().split()]
	flag = 0
	if sum(l) % x != 0:
		print(n)
		continue
	index1 = -1
	for i in range(n):
		if l[i] % x != 0:
			flag = 1
			index1 = i
			break
	if flag == 0:
		print(-1)
		continue
	l.reverse()
	index2 = -1
	for i in range(n):
		if l[i] % x != 0:
			flag = 1
			index2 = i
			break
	print(max(n - index1 - 1, n - index2 - 1))


t = int(input())
lists = []
for k in range(t):
	n = int(input())
	lists = input().split(' ')
	lists = [int(j) for j in lists]
	lists = list(set(lists))
	min1 = min(lists)
	max1 = max(lists)
	num = 1
	if min1 != max1 and n >= 2:
		num = 2
	for j in lists:
		n -= 1
		if j > min1 and j < max1 and (n >= 0):
			num += 1
	print(num)


ncases = int(input())
for i in range(ncases):
	line1 = input().split(' ')
	line2 = input().split(' ')
	hate = int(line1[1])
	arr = []
	count = 0
	for ele in line2:
		ele = int(ele)
		if ele % hate == 0:
			count += 1
		arr.append(ele)
	if count == len(arr):
		print(-1)
	elif sum(arr) % hate != 0:
		print(len(arr))
	else:
		s = []
		for j in range(len(arr)):
			find = arr[j]
			if find % hate != 0:
				s.append(j)
				break
		for k in range(-1, -(len(arr) + 1), -1):
			find = arr[k]
			if find % hate != 0:
				s.append(k)
				break
		arr1 = arr[s[0] + 1:]
		arr2 = arr[0:s[1]]
		print(max(len(arr1), len(arr2)))


t = int(input())
while t != 0:
	n = int(input())
	l = list([int(x) for x in input().split()])
	unique_list = set(l)
	ans = len(unique_list)
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	s = [0 for _ in range(n)]
	s[0] = a[0]
	count = -1 if a[0] % x == 0 else 1
	prev = None if a[0] % x == 0 else 0
	for i in range(1, n):
		s[i] = a[i] + s[i - 1]
		if s[i] % x == 0:
			if prev is not None:
				count = max(count, i - prev)
		else:
			count = max(count, i + 1)
			if prev is None:
				prev = i
	print(count)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	z = list(map(int, input().split()))
	y = z[::-1]
	a = sum(z)
	b = 0
	if a % x != 0:
		print(n)
	else:
		for i in range(n):
			if z[i] % x != 0 or y[i] % x != 0:
				b = i + 1
				print(n - b)
				break
		else:
			print(-1)


def main(a):
	new = {}
	for item in a:
		new[item] = True
	return len(new)
t = int(input())
cases = []
for i in range(t):
	n = int(input())
	cases.append(list(map(int, input().replace(',', ' ').split())))
for case in cases:
	print(main(case))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for v in a:
		if v not in d:
			d[v] = 1
	print(len(d.keys()))


test_cases = int(input())
test = test_cases
data = []
test_data = []
while test_cases > 0:
	test_data.append(input())
	data.append(input().split())
	test_cases -= 1
dummy = []
for i in range(0, test):
	print(len(set(data[i])))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	f = -1
	l = -1
	for i in range(n):
		if A[i] % x != 0 and f == -1:
			f = i
		if A[i] % x != 0:
			l = i
	if f == -1 and l == -1:
		print(-1)
	elif sum(A) % x != 0:
		print(n)
	else:
		print(max(n - f - 1, l))


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	(n, x) = read_ints()
	a = list(read_ints())
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		l = 0
		while l < n and a[l] % x == 0:
			l += 1
		if l == n:
			print(-1)
		else:
			r = n - 1
			while r >= 0 and a[r] % x == 0:
				r -= 1
			print(max(n - l - 1, r))


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x:
		print(n)
	else:
		lower = n + 1
		for i in range(n):
			if a[i] % x:
				lower = i
				break
		upper = 0
		for i in range(n - 1, -1, -1):
			if a[i] % x:
				upper = i
				break
		if upper == 0 and lower == n + 1:
			print(-1)
		else:
			ans = max(lower, n - lower - 1)
			ans = max(ans, upper, n - upper - 1)
			print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	arr = list(set(arr))
	arr.sort()
	print(len(arr))


n = int(input())
a = []
for i in range(n):
	l = int(input())
	array = list(map(int, input().split()))
	array = list(set(array))
	a.append(len(array))
for i in a:
	print(i)


T = int(input())
for t in range(T):
	(n, x) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	r = len(a) - 1
	l = 0
	curr_sum = sum(a)
	r_flag = 0
	l_flag = 0
	if curr_sum % x != 0:
		print(len(a))
	else:
		while l <= r:
			if a[l] % x != 0:
				l_flag = 1
			if a[r] % x != 0:
				r_flag = 1
			if l_flag or r_flag:
				break
			l += 1
			r -= 1
		if l_flag:
			ans = len(a) - l - 1
		elif r_flag:
			ans = r
		else:
			ans = -1
		print(ans)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

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

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] <= val:
			ans = mid
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	l = set(map(int, stdin.readline().split(' ')))
	print(len(l))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 0
	r = 0
	s = 0
	for i in range(n):
		a[i] = a[i] % x
		s = s + a[i]
	if s % x != 0:
		print(n)
	else:
		c = 1
		for i in range(n):
			if a[i] == 0:
				c = c + 1
			else:
				break
		m = 1
		a.reverse()
		for i in range(n):
			if a[i] == 0:
				m = m + 1
			else:
				break
		k = min(c, m)
		ans = n - k
		print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 0
	total = 0
	max_len = -1
	while i < n:
		total += a[i]
		if total % x != 0:
			max_len = max(max_len, i + 1)
		i += 1
	total = 0
	j = n - 1
	while j >= 0:
		total += a[j]
		if total % x != 0:
			max_len = max(max_len, n - j)
		j -= 1
	print(max_len)


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	t = sum(arr)
	i = 0
	j = n - 1
	mx = 0
	ok = 0
	t1 = t
	for i in range(n):
		if t1 % x != 0:
			ok = 1
			mx = max(mx, n - i)
			break
		t1 -= arr[i]
	t1 = t
	for i in range(n - 1, -1, -1):
		if t1 % x != 0:
			ok = 1
			mx = max(mx, i + 1)
		t1 -= arr[i]
	if ok == 1:
		print(mx)
	else:
		print(-1)


def solve():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	summ = sum(arr)
	prefixsum = [0 for i in range(n)]
	backsum = [0 for i in range(n)]
	prefixsum[0] = arr[0]
	backsum[0] = arr[n - 1]
	for i in range(1, n):
		prefixsum[i] = prefixsum[i - 1] + arr[i]
		backsum[i] = backsum[i - 1] + arr[n - i - 1]
	if summ % x:
		print(n)
		return
	i = 0
	while i < n:
		if (summ - prefixsum[i]) % x:
			print(n - (i + 1))
			return
		if (summ - backsum[i]) % x:
			print(n - (i + 1))
			return
		i += 1
	print(-1)
t = int(input())
for _ in range(t):
	solve()


from collections import Counter
T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	print(len(Counter(A).keys()))


import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % m:
		print(n)
	else:
		l = -1
		r = 0
		for i in range(0, n):
			if a[i] % m:
				if l == -1:
					l = i
				r = i
		if l == -1:
			print(-1)
		else:
			print(n - min(l + 1, n - r))


t = int(input())
for i in range(t):
	r = set()
	n = int(input())
	s = list(map(int, input().split()))
	pen = 0
	for j in s:
		if j in r:
			pen += 1
		else:
			r.add(j)
	print(n - pen)


t = int(input())
for i in range(t):
	n = int(input())
	li = [int(num) for num in input().split(' ', n - 1)]
	k = list(set(li) | set(li))
	print(len(k))


n = int(input())
for _ in range(n):
	m = int(input())
	a = [int(v) for v in input().split()]
	b = set([])
	for v in a:
		b.add(v)
	print(len(b))


test = int(input())
for t in range(test):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	sum = 0
	for i in arr:
		sum += i
	if sum % x != 0:
		print(n)
		continue
	first = None
	for i in range(n):
		if arr[i] % x != 0:
			first = i
			break
	last = None
	for i in range(n - 1, -1, -1):
		if arr[i] % x != 0:
			last = i
			break
	if last == None or first == None:
		print(-1)
		continue
	print(max(n - 1 - (first + 1) + 1, last - 1 - 0 + 1))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lol = [int(n) for n in input().split()]
	for i in range(n):
		lol[i] = lol[i] % k
	x = list(set(lol))
	if len(set(lol)) == 1 and x[0] == 0:
		print(-1)
	elif sum(lol) % k != 0:
		print(n)
	else:
		for i in range(len(lol)):
			if lol[i] != 0:
				x = i + 1
				break
		lol.reverse()
		for i in range(len(lol)):
			if lol[i] != 0:
				y = n - i
				break
		print(max(n - x, y - 1))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	p = []
	a = tuple(map(int, input().split()))
	s = 0
	c = 0
	for i in range(n):
		if a[i] % x == 0:
			c += 1
	if c == n:
		print(-1)
		continue
	a = a[::-1]
	sf = []
	sf.append(a[0])
	for i in range(1, n):
		sf.append(a[i] + sf[i - 1])
	a = a[::-1]
	sf = sf[::-1]
	p.append(a[0])
	for i in range(1, n):
		p.append(a[i] + p[i - 1])
	ans = 0
	l = 0
	r = n - 1
	for i in range(n):
		if sf[i] % x != 0 and ans < n - 1:
			l = i
			r = n - 1
			ans = max(ans, n - i)
		if p[i] % x != 0 and ans < i + 1:
			l = 0
			r = i
			ans = max(ans, i + 1)
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = [int(x) for x in input().split()]
	a = list(set(l))
	print(len(a))


for ttt in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x:
		print(n)
	else:
		li = n
		ri = -1
		for i in range(n):
			if a[i] % x != 0:
				li = min(li, i)
				ri = max(ri, i)
		if ri == -1:
			print(-1)
		else:
			l1 = max(n - li - 1, li)
			r1 = max(ri, n - ri - 1)
			print(max(l1, r1))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	mx = -1
	if sum(l) % x != 0:
		print(n)
	else:
		i = 0
		while i < n:
			if l[i] % x != 0:
				break
			i += 1
		j = n - 1
		while j >= 0:
			if l[j] % x != 0:
				break
			j -= 1
		j = n - 1 - j
		mn = min(i, j)
		print(n - mn - 1)


R = lambda : map(int, input().split())
(t,) = R()
exec(t * 'n,x=R();a=*R(),;b=[y%x>0for y in a];print(n-(sum(a)%x<1)*(min(b.index(1),b[::-1].index(1))+1)if any(b)else-1);')


for tt in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	ans = 0
	s2 = s
	if s % k != 0:
		print(n)
	else:
		for i in range(n):
			s = s - l[i]
			if s % k != 0:
				ans = max(ans, n - (i + 1))
				break
		l.reverse()
		for i in range(n):
			s2 = s2 - l[i]
			if s2 % k != 0:
				ans = max(ans, n - (i + 1))
				break
		if ans == 0:
			print(-1)
			continue
		print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict
for _ in range(int(input())):
	(N, K) = map(int, input().split())
	L = list(map(int, input().split()))
	prefix = list()
	prefix.append(L[0])
	for i in range(1, N):
		prefix.append(prefix[i - 1] + L[i])
	for i in range(N):
		prefix[i] = prefix[i] % K
	suffix = [0] * N
	suffix[N - 1] = L[N - 1]
	for i in range(N - 2, -1, -1):
		suffix[i] = L[i] + suffix[i + 1]
	suffix = suffix[::-1]
	max1 = -1
	max2 = -1
	for i in range(N):
		if prefix[i] % K != 0:
			max1 = i + 1
	for i in range(N):
		if suffix[i] % K != 0:
			max2 = i + 1
	print(max(max1, max2))


import sys
I = sys.stdin.readline
for _ in range(int(I())):
	I()
	print(len(set(I().split())))


ncase = int(input())
for i in range(0, ncase):
	arrsize = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	arr.append(-1)
	answer = 0
	for z in range(0, len(arr) - 1):
		if arr[z] != arr[z + 1]:
			answer = answer + 1
	print(answer)


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	m = sum(arr) % x
	if m != 0:
		print(n)
		continue
	ls = 0
	li = -1
	for i in range(n):
		ls += arr[i]
		li = i + 1
		if ls % x != 0:
			break
	rs = 0
	ri = -1
	for i in range(n - 1, -1, -1):
		rs += arr[i]
		ri = i
		if rs % x != 0:
			break
	if n - min(n - ri, li) == 0:
		print(-1)
	else:
		print(n - min(n - ri, li))


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

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

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	(n, x) = num_input()
	arr = list_input()
	summ = sum(arr)
	if summ % x != 0:
		print(n)
	else:
		first = -1
		for i in range(n):
			if arr[i] % x != 0:
				first = i
				break
		if first == -1:
			print(-1)
			return
		first += 1
		second = -1
		for i in range(-1, -(n + 1), -1):
			if arr[i] % x != 0:
				second = i
				break
		print(max(n - first, n + second))
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	u = 0
	for t in a:
		if t % x == 0:
			u += 1
	if u == n:
		print(-1)
	elif sum(a) % x != 0:
		print(n)
	else:
		(v, w) = (0, 0)
		for i in range(n):
			if a[i] % x != 0:
				v = i + 1
				break
		for j in range(n - 1, -1, -1):
			if a[j] % x != 0:
				w = n - j
				break
		length = min(v, w)
		print(n - length)


def linput(a):
	return [int(i) for i in a.split()]
q = int(input())
for u in range(q):
	n = int(input())
	s = linput(input())
	print(len(set(s)))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	j = 1
	while j < len(l):
		if l[j] == l[j - 1]:
			l.pop(j)
		else:
			j += 1
	print(len(l))


def longSubarrWthSumDivByK(arr, n, k):
	um = {i: 0 for i in range(8)}
	mod_arr = [0 for i in range(n)]
	max = 0
	curr_sum = 0
	for i in range(n):
		curr_sum += arr[i]
		mod_arr[i] = (curr_sum % k + k) % k
	for i in range(n):
		if mod_arr[i] != 0:
			max = i + 1
		elif mod_arr[i] in um:
			um[mod_arr[i]] = i
		elif max < i - um[mod_arr[i]]:
			max = i - um[mod_arr[i]]
	return max
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	x = longSubarrWthSumDivByK(li, len(li), k)
	y = longSubarrWthSumDivByK(li[::-1], len(li), k)
	if x == 0:
		print(-1)
	elif x >= y:
		print(x)
	elif y >= x:
		print(y)


def solve():
	n = int(input())
	inp = input().split(' ')
	vt = []
	for i in inp:
		vt.append(int(i))
	vt.sort()
	ans = 0
	last = -1
	for i in vt:
		if last == -1:
			last = i
			ans += 1
			continue
		if i == last:
			continue
		else:
			last = i
			ans += 1
	return ans
t = int(input())
while t > 0:
	t -= 1
	print(solve())


r = int(input())
for i in range(r):
	n = int(input())
	num = input()
	list = [int(x) for x in num.split()]
	list.sort()
	arr = []
	for x in list:

		def binarySearch(arr, l, r, x):
			if l <= r:
				mid = (l + r) // 2
				if arr[mid] == x:
					return mid
				elif arr[mid] > x:
					return binarySearch(arr, l, mid - 1, x)
				else:
					return binarySearch(arr, mid + 1, r, x)
			else:
				return -1
		result = binarySearch(arr, 0, len(arr) - 1, x)
		if result == -1:
			arr.append(x)
	print(len(arr))


t = int(input())
i = 0
while i < t:
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	summer = sum(a)
	if summer % x == 0:
		lc = 0
		rc = 0
		j = 0
		notFound = True
		notFound = True
		while j < len(a) and notFound:
			if a[j] % x == 0:
				lc += 1
			else:
				notFound = False
			if a[-(j + 1)] % x == 0:
				rc += 1
			else:
				notFound = False
			j += 1
		if notFound:
			print(-1)
		elif rc == 0:
			print(len(a) - lc)
		elif lc == 0:
			print(len(a) - rc)
		else:
			print(len(a) - max(lc, rc))
	else:
		print(len(a))
	i += 1


t = int(input())
while t != 0:
	left = -1
	(n, x) = [int(j) for j in input().split()]
	right = n
	elems = [int(j) for j in input().split()]
	if sum(elems) % x != 0:
		print(n)
		t -= 1
		continue
	for i in range(0, n):
		elem = elems[i]
		if elem % x != 0:
			if left == -1:
				left = i
			right = i
	if left == -1:
		print(-1)
	else:
		print(n - min(left + 1, n - right))
	t -= 1


import sys
input = sys.stdin.readline
ans = []
for kek in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x == 0:
		delta_min = n + n
		delta_max = 0
		for i in range(n):
			if a[i] % x != 0:
				delta_max = max(delta_max, i)
				delta_min = min(delta_min, i)
		delta_min += 1
		delta_max = n - delta_max
		DD = n - min(delta_max, delta_min)
		if DD == 0:
			ans.append(-1)
		else:
			ans.append(DD)
	else:
		ans.append(n)
print(*ans, sep='\n')


for _ in range(int(input())):
	(n, h) = map(int, input().split())
	l = [int(i) for i in input().split()]
	flag = 0
	i = 0
	j = n
	x = sum(l)
	x1 = x
	y1 = x
	if not x % h == 0:
		print(n)
		flag = 1
	while i < n and j >= 0 and (not flag):
		x1 = x1 - l[i]
		y1 = y1 - l[j - 1]
		if not x1 % h == 0:
			print(n - i - 1)
			flag = 1
			break
		if not y1 % h == 0 and (not flag):
			print(j - 1)
			flag = 1
			break
		i += 1
		j -= 1
	if not flag:
		print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	A = set(input().split())
	print(len(A))


for _ in '0' * int(input()):
	input()
	ls = list(set(map(int, input().split())))
	print(len(ls))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = {}
	for i in range(len(arr)):
		if arr[i] not in brr:
			brr[arr[i]] = arr[i]
	print(len(brr))


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) for x in input().split(' ')]
	t = set(l)
	l2 = list(t)
	print(len(l2))


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	a.sort()
	q = 1
	m = a[0]
	for i in range(n):
		if a[i] == m:
			continue
		else:
			q += 1
			m = a[i]
	print(q)


for i in ' ' * int(input()):
	n = int(input())
	L = set(map(int, input().split()))
	print(len(L))


t = int(input())
for i in range(t):
	a = list(map(int, input().split()))
	n = a[0]
	x = a[1]
	flag = 0
	total = 0
	temp1 = 0
	temp2 = 0
	arr = list(map(int, input().split()))
	for j in range(n):
		total += arr[j]
		if (flag == 0) & (arr[j] % x != 0):
			temp1 = j + 1
			flag = 1
		elif (flag == 1) & (arr[j] % x != 0):
			temp2 = n - j
	if total % x != 0:
		print(n)
	elif (temp1 == 0) & (temp2 == 0):
		print(-1)
	else:
		print(max(n - temp1, n - temp2))


import sys
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	a = set(a)
	print(len(a))


test = int(input())
while test:
	n = int(input())
	arr = list(map(int, input().split()))
	s = set(arr)
	print(len(s))
	test = test - 1


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for j in range(n):
		s += a[j]
	if s % x == 0:
		start = 0
		end = n - 1
		while a[start] % x == 0 and start < n - 1:
			start += 1
		if start == n - 1:
			if a[start] % x == 0:
				print(-1)
			else:
				print(1)
		else:
			while a[end] % x == 0 and end > 0:
				end -= 1
			if end == 0:
				if a[0] % x == 0:
					print(-1)
				else:
					print(1)
			else:
				m = max(n - start - 1, end)
				print(m)
	else:
		print(n)


test_case = int(input())
for i in range(test_case):
	n = input()
	s = set([int(i) for i in input().split()])
	print(len(s))


def main():
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	(s, a) = (0, True)
	for i in range(n):
		if arr[i] % x:
			a = False
		s += arr[i]
	if a:
		print(-1)
		return
	if s % x == 0:
		while l < n:
			if arr[l] % x:
				break
			l += 1
		while r > 0:
			if arr[r] % x:
				break
			r -= 1
		print(n - min(n - r, l + 1))
	else:
		print(n)
for _ in range(int(input())):
	main()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x != 0:
		print(n)
	else:
		check = 0
		c1 = s
		c2 = s
		for i in range(n - 1, -1, -1):
			c1 -= arr[i]
			if c1 % x != 0:
				a = len(arr[:i])
				break
		for i in range(n):
			c2 -= arr[i]
			if c2 % x != 0:
				check = 1
				b = len(arr[i + 1:])
				break
		if check != 0:
			print(max(a, b))
		else:
			print(-1)


for _ in range(int(input())):
	length = int(input())
	print(len(set(input().split())))


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	(n, x) = rl()
	a = rl()
	s = sum(a)
	a1 = 0
	a2 = 0
	if s % x != 0:
		print(n)
		continue
	for i in range(0, n):
		if a[i] % x != 0:
			a1 = a1 + 1
			break
		else:
			a1 = a1 + 1
	a.reverse()
	for i in range(0, n):
		if a[i] % x != 0:
			a2 = a2 + 1
			break
		else:
			a2 = a2 + 1
	if a1 == n and a2 == n:
		print(-1)
	else:
		print(n - min(a1, a2))


for ii in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = set(a)
	print(len(b))


for case in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	s = sum(a)
	i = 99999999
	j = -1
	for k in range(n):
		if a[k] % x != 0:
			i = min(i, k)
			j = max(i, k)
	if j == -1:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		l = i + 1
		r = n - j
		print(max(n - l, n - r))


t = int(input())
while t:
	t -= 1
	(n, x) = [i for i in map(int, input().strip().split())]
	A = [i for i in map(int, input().strip().split())]
	sum = 0
	for a in A:
		sum += a
	if sum % x == 0:
		l = n
		r = n
		for i in range(n):
			if A[i] % x != 0:
				l = i + 1
				break
		i = n - 1
		while i >= 0:
			if A[i] % x != 0:
				r = n - i
				break
			i -= 1
		res = n - min(l, r)
		if res == 0:
			print(-1)
		else:
			print(res)
	else:
		print(len(A))


import sys
from os import path
if path.exists('C:/Users/prana/Desktop/sublime/input.txt'):
	sys.stdin = open('C:/Users/prana/Desktop/sublime/input.txt', 'r')
	sys.stdout = open('C:/Users/prana/Desktop/sublime/output.txt', 'w')

def solve():
	(n, x) = input().split()
	a = list(map(int, input().split()))
	n = int(n)
	x = int(x)
	su = sum(a)
	count = 0
	if su % x != 0:
		print(n)
	else:
		ans1 = 0
		ans2 = 0
		for i in range(n):
			if a[i] % x != 0:
				break
		ans1 = n - (i + 1)
		print(ans1, file=sys.stderr)
		j = n - 1
		while j >= 0:
			if a[j] % x != 0:
				ans2 = j
				break
			j -= 1
		ans = max(ans2, ans1)
		if ans == 0:
			print(-1)
		else:
			print(ans)
T = 1
T = int(input())
for _ in range(1, T + 1):
	print('Case #', _, file=sys.stderr)
	solve()


t = int(input())
while t > 0:
	t -= 1
	a = int(input())
	lst = set(map(int, input().split()))
	print(len(lst))


def solve(arr, n, x):
	sm = sum(arr)
	if sm % x != 0:
		return n
	count = 0
	for i in arr:
		if i % x == 0:
			count += 1
	if count == x:
		return -1
	total = sm
	mx = 0
	for i in range(n):
		sm = sm - arr[i]
		if sm % x != 0:
			break
	mx = max(mx, n - i - 1)
	ln = 0
	for i in range(n - 1, -1, -1):
		ln += 1
		total = total - arr[i]
		if total % x != 0:
			break
	mx = max(mx, n - ln)
	if mx == 0:
		return -1
	return mx
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(arr, n, x))


n = int(input())
for i in range(n):
	s = int(input())
	k = list(map(int, input().split()))
	k = list(dict.fromkeys(k))
	print(len(k))


def solve(nums, x):
	if sum(nums) % x != 0:
		return len(nums)
	total = 0
	for i in range(len(nums)):
		total += nums[i]
		if total % x != 0:
			break
	total = 0
	for j in reversed(range(len(nums))):
		total += nums[j]
		if total % x != 0:
			break
	val = max(len(nums) - i - 1, j)
	return val if val else -1
t = int(input())
for _ in range(t):
	(l, x) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	print(solve(nums, x))


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

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]

def solve(n, x, aa):
	if sum(aa) % x:
		return n
	for i in range((n + 1) // 2):
		if aa[i] % x or aa[n - 1 - i] % x:
			return n - 1 - i
	return -1
for _ in range(II()):
	(n, x) = MI()
	aa = LI()
	print(solve(n, x, aa))


import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

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

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

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

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

def longSubarrWthSumDivByK(arr, n, k):
	um = {i: 0 for i in range(k)}
	mod_arr = [0 for i in range(n)]
	max = 0
	curr_sum = 0
	for i in range(n):
		curr_sum += arr[i]
		mod_arr[i] = (curr_sum % k + k) % k
	for i in range(n):
		if mod_arr[i] != 0:
			max = i + 1
		elif mod_arr[i] in um:
			um[mod_arr[i]] = i
		elif max < i - um[mod_arr[i]]:
			max = i - um[mod_arr[i]]
	return max
t = inp()
for _ in range(t):
	(n, k) = invr()
	a = inlist()
	b = a[::-1]
	res = max(longSubarrWthSumDivByK(a, n, k), longSubarrWthSumDivByK(b, n, k))
	if res == 0:
		print(-1)
	else:
		print(res)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = []
	ma = 0
	l.append(a[0])
	if a[0] % x != 0:
		ma = 1
	for i in range(1, n):
		l.append(a[i] + l[i - 1])
		if l[i] % x != 0:
			ma = max(ma, i + 1)
	(li, ri) = (-1, -1)
	for i in range(n):
		if a[i] % x != 0:
			li = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x != 0:
			ri = i
			break
	for i in range(1, n):
		if li != -1:
			ma = max(ma, i - li)
		if ri != -1:
			ma = max(ma, ri - i)
		ma = max(0, ma)
	if ma:
		print(ma)
	else:
		print('-1')


q = int(input())
for i in range(q):
	n = int(input())
	l = list(map(int, input().split(' ')))
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
	print(len(d))


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	for l in range(n):
		if arr[l] % x != 0:
			break
	for r in range(n - 1, -1, -1):
		if arr[r] % x != 0:
			break
	if arr[l] % x == 0:
		print(-1)
	else:
		print(n - min(n - r - 1, l) - 1)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
import threading
import bisect
import heapq
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	(n, x) = map(int, input().split())
	arr = [0] + list(map(int, input().split()))
	l = 0
	r = 0
	sumE = 0
	for i in range(1, len(arr)):
		sumE += arr[i]
		if arr[i] % x != 0:
			if l == 0:
				l = i
			r = i
	if sumE % x != 0:
		print(n)
	elif r == 0:
		print(-1)
	else:
		print(max(n - l, n - (n - r) - 1))


from sys import stdin
r = stdin.readline

def main():
	cases = int(r())
	for case in range(cases):
		n = int(r())
		A = list(map(int, r().strip().split()))
		print(len(set(A)))
main()


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	vis = {k: False for k in range(n)}
	S = set()
	res = 0
	for i in range(n):
		if arr[i] not in S:
			S.add(arr[i])
			res += 1
	print(res)


def code(n, l):
	count = n
	(ind1, ind2, f, m) = (0, 0, 0, 0)
	for i in range(n):
		if l[i] != 0 and f == 0:
			ind1 = i
			f = 1
		if l[n - i - 1] != 0 and m == 0:
			ind2 = i
			m = 1
	dif = min(ind1 + 1, ind2 + 1)
	return count - dif
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] %= x
	count = l.count(0)
	if count == n:
		print(-1)
	elif sum(l) % x != 0:
		print(n)
	else:
		ans = code(n, l)
		print(ans)


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

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))
from collections import defaultdict

def mus(d=0):
	return defaultdict(defaultdict(d))

def ms(x, y, d=0):
	return [[d] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppmsp(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for i in range(x or n))) for j in range(y or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def yn(x):
	return 'YES' if x else 'NO'
from itertools import groupby

def rnar():
	return (rri(), rrl())

def rn2ar():
	return (rri(), rrl(), rrl())

def r2nar():
	return (rri(), rri(), rrl())

def read():
	return rnar()

def solve(n, a):
	a.sort()
	answ = sum((1 for (i, g) in groupby(a)))
	return answ
test_count = rri()
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	print(result)


for i in [*open(0)][2::2]:
	print(len({*i.split()}))


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	res = sum(a)
	if res % k != 0:
		print(n)
	else:
		sm = res
		i = n - 1
		ans1 = 0
		while i >= 0:
			sm = sm - a[i]
			if sm % k != 0:
				ans1 = i
				break
			i -= 1
		ans2 = 0
		i = 0
		while i < n:
			res -= a[i]
			i += 1
			if res % k != 0:
				ans2 = n - i
				break
		if ans1 == 0 and ans2 == 0:
			print(-1)
		else:
			print(max(ans1, ans2))


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def CeilIndex(A, l, r, key):
	while r - l > 1:
		m = l + (r - l) // 2
		if A[m] >= key:
			r = m
		else:
			l = m
	return r

def lis(A, size):
	tailTable = [0 for i in range(size + 1)]
	len = 0
	tailTable[0] = A[0]
	len = 1
	for i in range(1, size):
		if A[i] < tailTable[0]:
			tailTable[0] = A[i]
		elif A[i] > tailTable[len - 1]:
			tailTable[len] = A[i]
			len += 1
		else:
			tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]
	return len

def countDistinct(arr, n):
	s = set()
	res = 0
	for i in range(n):
		if arr[i] not in s:
			s.add(arr[i])
			res += 1
	return res
t = read_int()
for i in range(t):
	n = read_int()
	a = read_int_line()
	l1 = lis(a, n)
	lm = countDistinct(a, n)
	print(max(lm, l1))


from sys import stdin
try:
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().rstrip().split()))
		s = set(arr)
		print(len(s))
except:
	pass


from math import *
inf = 10 ** 10
zzz = int(input())
for zz in range(zzz):
	n = int(input())
	a = [int(i) for i in input().split()]
	el = list(sorted(set(a)))
	print(len(el))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	(sum_frnt, sum_back) = (0, 0)
	maxim = -1
	for i in range(n):
		sum_frnt += l[i]
		sum_back += l[n - 1 - i]
		if sum_frnt % k != 0 or sum_back % k != 0:
			maxim = i + 1
	print(maxim)


t = int(input())
while t:
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	(left, right) = (-1, -1)
	s = 0
	for i in range(n):
		if a[i] % x != 0:
			if left == -1:
				left = i
			right = i
		s += a[i]
	if s % x != 0:
		print(n)
	elif left == -1:
		print(-1)
	else:
		print(n - min(left + 1, n - right))
	t -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % k != 0:
		print(len(arr))
	else:
		c = 0
		for i in range(n):
			c += 1
			if arr[i] % k:
				break
		cc = 0
		for j in range(n - 1, -1, -1):
			cc += 1
			if arr[j] % k:
				break
		ans = n - min(c, cc)
		if ans:
			print(ans)
		else:
			print(-1)


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	acc = 0
	ans = -1
	p = -1
	for i in range(n):
		acc += a[i]
		if acc % x != 0:
			ans = max(ans, i + 1)
			if p == -1:
				p = i
		elif p != -1:
			ans = max(ans, i - p)
	print(ans)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def solve():
	for _ in range(int(input())):
		(n, x) = read()
		arr = [i % x for i in read()]
		if not any(arr):
			print(-1)
		else:
			m = -1
			s = 0
			for i in range(n):
				s += arr[i]
				if s % x:
					m = i + 1
			s = 0
			for i in range(n):
				s += arr[n - 1 - i]
				if s % x:
					m = max(i + 1, m)
			print(m)
solve()


n = int(input())
for _ in range(n):
	l = input()
	nums = list([int(x) for x in input().split()])
	nums = set(nums)
	print(len(nums))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	s = sum(l)
	if s % m != 0:
		print(n)
	else:
		ok = 0
		best = 0
		for j in range(len(l)):
			if l[j] % m != 0:
				ok = 1
				best = j + 1
				break
		ok = 0
		best2 = 0
		for j in range(len(l) - 1, -1, -1):
			if l[j] % m != 0:
				ok = 1
				best2 = len(l) - j
				break
		if ok == 1:
			print(len(l) - min(best, best2))
		if ok == 0:
			print(-1)


import sys
import math

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

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

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

def SI():
	return sys.stdin.readline().strip()
t = int(input())
for q in range(t):
	(n, x) = MI()
	a = LI()
	if x == 1:
		print(-1)
	else:
		s = sum(a)
		if s % x != 0:
			print(n)
		else:
			ind = -1
			ind2 = -1
			for i in range(n):
				if a[i] % x != 0:
					ind = i
					break
			for i in range(n - 1, -1, -1):
				if a[i] % x != 0:
					ind2 = i
					break
			if ind == -1:
				print(-1)
			else:
				print(max(n - ind - 1, ind2))


queries = int(input())
for _ in range(queries):
	_ = input()
	print(len(set(input().split())))


n = int(input())
for i in range(n):
	l = int(input())
	j = 0
	y = input().split()
	dic = {}
	for k in y:
		if k in dic:
			dic[k] += 1
		else:
			dic[k] = 1
	u = len(dic)
	print(u)


import math
t = int(input())
for w in range(t):
	(n, x) = (int(i) for i in input().split())
	l = [int(i) for i in input().split()]
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		c = 0
		s1 = 0
		s2 = s
		for i in range(n - 1, -1, -1):
			if l[i] % x != 0:
				c = 1
				k = i
				break
		if c == 0:
			print(-1)
		else:
			for i in range(n):
				if l[i] % x != 0:
					k1 = i
					break
			print(max(k, n - k1 - 1))


t = int(input())
for q in range(t):
	(n, x) = map(int, input().split())
	mass = [int(x) for x in input().split()]
	if sum(mass) % x != 0:
		print(n)
		continue
	a = n
	b = n
	for i in range(n):
		if mass[i] % x != 0:
			a = i + 1
			break
	for i in range(n):
		if mass[n - i - 1] % x != 0:
			b = i + 1
			break
	a = min(a, b)
	if a == n:
		print(-1)
	else:
		print(n - a)


def hate(n, x, a):
	if sum(a) % x != 0:
		return n
	Ind = []
	for i in range(n):
		if a[i] % x != 0:
			Ind.append(i)
	l = len(Ind)
	if l == 0:
		return -1
	q = n - 1 - Ind[0]
	w = Ind[l - 1]
	return max(q, w)
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	print(hate(n, x, a))


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

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

def iin():
	return int(sin())
p = print
MAX = float('inf')
MIN = float('-inf')

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = ain()
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def main():
	for _ in range(iin()):
		(n, x) = ain()
		l = ain()
		s = sum(l)
		ss = s
		maxi = -1
		if s % x != 0:
			print(n)
		else:
			for i in range(n):
				if (s - l[i]) % x != 0:
					maxi = max(maxi, n - i - 1)
				s -= l[i]
			for i in range(n - 1, -1, -1):
				if (ss - l[i]) % x != 0:
					maxi = max(maxi, i)
				ss -= l[i]
			print(maxi)
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()


def lsa(x, arr):
	if sum(arr) % x != 0:
		return len(arr)
	else:
		f = fnde(x, arr)
		if f == -1:
			return -1
		l = len(arr) - 1 - lnde(x, arr)
		return len(arr) - min(f, l) - 1

def fnde(x, arr):
	index = 0
	n = len(arr)
	while arr[index] % x == 0:
		index += 1
		if index >= n:
			return -1
	return index

def lnde(x, arr):
	n = len(arr)
	index = n - 1
	while arr[index] % x == 0:
		index -= 1
		if index < 0:
			return -1
	return index
t = int(input())
for _ in range(t):
	x = int(input().split(' ')[1])
	arr = list(map(int, input().split(' ')))
	print(lsa(x, arr))


from collections import defaultdict
R = lambda : map(int, input().split())
t = int(input())

def solve(a):
	d = defaultdict(int)
	for x in a:
		d[x] = 1
	return sum(d.values())
for _ in range(t):
	n = int(input())
	a = list(R())
	print(solve(a))


for k in range(0, int(input())):
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	p = []
	s = 0
	j = 0
	z = 0
	while j <= len(l) - 1:
		if (l[j] + s) % x == 0:
			s = s + l[j]
			z = z + 1
			j = j + 1
		else:
			s = s + l[j]
			z = z + 1
			p.append(z)
			j = j + 1
	w = l[:]
	w = w[::-1]
	s = 0
	j = 0
	z = 0
	while j <= len(w) - 1:
		if (w[j] + s) % x == 0:
			s = s + w[j]
			z = z + 1
			j = j + 1
		else:
			s = s + w[j]
			z = z + 1
			p.append(z)
			j = j + 1
	p.append(0)
	if max(p) != 0:
		print(max(p))
	else:
		print('-1')


from sys import stdin
from queue import deque
from collections import defaultdict

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

def read_int():
	return int(input())

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

def read_str_list():
	return list(input().split())
for _ in range(read_int()):
	n = read_int()
	arr = read_list()
	visited = defaultdict(int)
	for a in arr:
		visited[a] = 1
	print(len(visited))


from math import *

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
t = int(input())
while t:
	t = t - 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	f = []
	l = []
	cnt = 0
	for i in a:
		cnt += i
		f.append(cnt)
	l.append(cnt)
	for i in range(n - 1):
		cnt -= a[i]
		l.append(cnt)
	mm = 0
	for i in range(n):
		if f[i] % x != 0:
			mm = max(mm, i + 1)
		if l[i] % x != 0:
			mm = max(mm, n - i)
	if mm == 0:
		print(-1)
	else:
		print(mm)


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if sum(a) % x == 0:
		left = 0
		right = n - 1
		result = -1
		while left < right:
			if a[left] % x != 0:
				result = n - left - 1
				break
			if a[right] % x != 0:
				result = right
				break
			left += 1
			right -= 1
		print(result)
	else:
		print(len(a))


for test_i in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) % x != 0:
		print(n)
	else:
		il = 1
		while il < n + 1:
			if arr[il - 1] % x > 0:
				break
			il += 1
		ir = 1
		while ir < n + 1:
			if arr[-ir] % x > 0:
				break
			ir += 1
		print(n - min(il, ir))


n = int(input())
for i2 in range(n):
	t = int(input())
	l = list(map(int, input().split()))
	l.sort()
	r = 1
	for i in range(1, t):
		if l[i] != l[i - 1]:
			r += 1
	print(r)


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().strip().split())
	list1 = list(map(int, stdin.readline().strip().split()))
	list2 = list1.copy()
	for i in range(1, n):
		list1[i] += list1[i - 1]
	for i in range(n - 2, -1, -1):
		list2[i] += list2[i + 1]
	f = 0
	for i in range(n - 1, -1, -1):
		if list1[i] % k != 0:
			f = 1
			break
	if f:
		c1 = i + 1
	else:
		c1 = 0
	f = 0
	for i in range(0, n):
		if list1[i] % k != 0:
			f = 1
			break
	if f:
		c2 = n - (i + 1)
	else:
		c2 = 0
	c = max(c1, c2)
	if c:
		print(c)
	else:
		print(-1)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	(s, e) = (-1, -1)
	val = sum(a)
	if val % x != 0:
		print(n)
		continue
	for i in range(n):
		if a[i] % x != 0:
			s = i
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x != 0:
			e = i
			break
	if s == -1:
		print(-1)
	else:
		print(max(n - s - 1, e))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	numb = list(map(int, input().split()))
	s = sum(numb)
	if s % x != 0:
		print(n)
		continue
	else:
		k = n
		for i in range(n):
			if numb[i] % x == 0:
				k = k - 1
				continue
			else:
				k = k - 1
				break
		m = n
		for i in range(n - 1, -1, -1):
			if numb[i] % x == 0:
				m = m - 1
				continue
			else:
				m = m - 1
				break
		if k == 0:
			print(-1)
		else:
			print(max(m, k))


for t in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	total = sum(arr)
	res1 = 0
	res2 = 0
	if total % x != 0:
		print(n)
		continue
	c = 0
	for i in range(0, n):
		total -= arr[i]
		c += 1
		if total % x != 0:
			res1 = n - c
			break
	arr.reverse()
	c = 0
	total = sum(arr)
	for i in range(0, n):
		total -= arr[i]
		c += 1
		if total % x != 0:
			res2 = n - i - 1
			break
	if res1 == 0 and res2 == 0:
		print(-1)
	else:
		print(max(res1, res2))


casos = int(input())
for c in range(casos):
	x = input()
	y = set(map(int, input().split()))
	print(len(y))


tc = int(input())
for ctr in range(tc):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	k = 0
	for i in a:
		if i % x != 0:
			k += 1
	if k == 0:
		print('-1')
	elif sum(a) % x != 0:
		print(n)
	else:
		l = 0
		r = n - 1
		for i in a:
			if i % x == 0:
				l += 1
			else:
				break
		for i in a[::-1]:
			if i % x == 0:
				r -= 1
			else:
				break
		print(n - min(l + 1, n - r))


tests = int(input())
for i in range(tests):
	bla = input()
	nums = set(map(int, input().split()))
	print(len(nums))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	am = [0]
	mod = [[] for i in range(x)]
	mod[0].append(0)
	for i in range(n):
		j = (am[-1] + a[i]) % x
		am.append(j)
		mod[j].append(i + 1)
	ans = 0
	for i in range(1, x):
		if len(mod[i]) == 0:
			continue
		if len(mod[i]) == 1:
			ans = max(ans, mod[i][0], n - mod[i][0])
		else:
			(a, b) = (mod[i][0], mod[i][-1])
			ans = max(b - a + 1, ans)
			if a != 0:
				ans = max(ans, b)
			if b != n:
				ans = max(ans, n - a)
	if ans == 0:
		print(-1)
	else:
		print(ans)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = 0
	lo = -1
	for j in range(n):
		s += l[j]
		if l[j] % x != 0:
			if lo == -1:
				lo = j
			up = j
	if s % x != 0:
		print(n)
	elif lo == -1:
		print(-1)
	else:
		print(n - min(lo + 1, n - up))


def solve(test):
	n = int(input())
	a = list(map(int, input().split()))
	st = set()
	for x in a:
		st.add(x)
	print(len(st))
t = int(input())
for _ in range(t):
	solve(_ + 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x != 0:
		print(n)
	else:
		f = 0
		b = 0
		while b < n and arr[n - b - 1] % x == 0:
			b += 1
		while f < n and arr[f] % x == 0:
			f += 1
		print(n - min(f, b) - 1)


t = int(input())
from collections import defaultdict
from sys import stdin, stdout
for i in range(t):
	n = int(input())
	l = list(map(int, stdin.readline().split()))
	d = defaultdict(int)
	c = 0
	for j in l:
		if d[j] == 0:
			d[j] = 1
			c += 1
	stdout.write(str(c) + '\n')


for I in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	left = 10000005
	right = -1
	count = 0
	for (i, num) in enumerate(a):
		if num % k == 0:
			count += 1
		else:
			left = min(left, i)
			right = max(right, i)
	if sum(a) % k != 0:
		print(n)
	elif count == n:
		print(-1)
	else:
		fromLeft = abs(0 - left) + 1
		fromRight = n - right
		if fromLeft <= fromRight:
			print(n - fromLeft)
		else:
			print(n - fromRight)


import sys

def main():
	t = int(sys.stdin.readline())
	count = {}
	for i in range(t):
		sys.stdin.readline()
		ans = set(map(int, sys.stdin.readline().split()))
		sys.stdout.write(f'{len(ans)}\n')
main()


T = int(input())
for _ in range(0, T):
	(n, x) = list(map(int, input().split()))
	s = [int(x1) for x1 in input().split()]
	tot = 0
	for i in range(0, len(s)):
		tot += s[i]
	if tot % x != 0:
		print(n)
	else:
		ptr1 = 0
		ptr2 = 0
		c1 = 0
		c2 = 0
		for i in range(0, len(s)):
			if s[i] % x == 0:
				c1 += 1
			else:
				break
		for i in range(len(s) - 1, -1, -1):
			if s[i] % x == 0:
				c2 += 1
			else:
				break
		ans = n - min(c1, c2) - 1
		if ans == 0:
			print(-1)
		else:
			print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % k != 0:
		print(n)
	else:
		id1 = -1
		id2 = -1
		for i in range(n):
			if l[i] % k != 0:
				id1 = i
				break
		for i in range(n - 1, -1, -1):
			if l[i] % k != 0:
				id2 = i
				break
		if id1 == -1 and id2 == -1:
			print(-1)
		else:
			print(max(n - id1 - 1, id2))


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


import sys

def swap(x, y, a):
	temp = a[x]
	a[x] = a[y]
	a[y] = temp
	return a

def solve():
	return None

def main():
	q = []
	for line in sys.stdin.readlines():
		q.append(line)
	for i in range(len(q)):
		q[i] = q[i].rstrip().split(' ')
		q[i] = [int(x) for x in q[i]]
	for i in range(1, len(q), 2):
		x = q[i][1]
		a = q[i + 1]
		current = 0
		res = -1
		save_pointer = -1
		flag = 0
		m = -1
		for j in range(2):
			res = -1
			for i in range(len(a)):
				current += a[i]
				if current % x != 0:
					res = i
					flag = 0
				else:
					save_pointer = res
					flag = 1
			m = max(m, max(res + 1, len(a) - save_pointer - 1))
			current = 0
			save_pointer = -1
			flag = 0
			a.reverse()
		if res == -1:
			print(-1)
		else:
			print(m)
main()


for i in range(int(input())):
	(n, x) = map(int, input().split())
	n = [int(i) for i in input().split()]
	MAX = 0
	if sum(n) % x != 0:
		print(len(n))
	else:
		for j in range((len(n) + 1) // 2):
			if n[j] % x != 0:
				MAX = max(len(n[j:-1]), MAX)
				break
		for j in range(len(n) - 1, len(n) // 2, -1):
			if n[j] % x != 0:
				MAX = max(len(n[0:j]), MAX)
				break
		if MAX == 0:
			print(-1)
		else:
			print(MAX)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(map(int, input().split()))
	if sum(s) % x != 0:
		print(n)
	else:
		(subf, subl) = (-1, -1)
		for (i, c) in enumerate(s):
			if c % x != 0:
				if subf == -1:
					subf = i
				subl = i
		if subf == -1:
			print(-1)
		else:
			print(max(n - subf - 1, subl))


import sys
for _ in range(int(input())):
	(n, x1) = map(int, input().split())
	l = list(map(int, input().split()))
	pa = []
	x = 0
	for i in l:
		x += i
		pa.append(x)
	for i in range(len(l)):
		pa[i] = pa[i] % x1
	sa = []
	x = 0
	for i in range(n - 1, -1, -1):
		x += l[i]
		sa.append(x)
	mx1 = -1
	mx2 = -1
	for i in range(n):
		if pa[i] % x1 != 0:
			mx1 = i + 1
	for i in range(n):
		if sa[i] % x1 != 0:
			mx2 = i + 1
	print(max(mx1, mx2))


from math import *
from collections import *
from operator import itemgetter
import bisect
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()
for i in range(t):
	n = ii()
	a = iia()
	s = list(set(a))
	print(len(s))


for _ in range(int(input())):
	[n, x] = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = [1 if i % x == 0 else 0 for i in A]
	if all(B):
		print(-1)
	elif sum(A) % x != 0:
		print(n)
	else:
		front = 0
		back = len(A) - 1
		while front < len(A) and A[front] % x == 0:
			front += 1
		while back >= 0 and A[back] % x == 0:
			back -= 1
		print(max(n - front - 1, back))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	r = n
	m = 0
	if s % x != 0:
		print(n)
		n = 0
		r = -199
	for i in range(n):
		if a[i] % x == 0:
			m += 1
		if (s - a[i]) % x != 0:
			r -= 1
			break
		elif (s - a[-i - 1]) % x != 0:
			r -= 1
			break
		else:
			s -= a[i]
			r -= 1
	if r == 0:
		print(-1)
	elif r != -199:
		print(r)


import array
import math
import os
import random
import re
import sys
k = input()
t = int(k)
for i in range(0, t, 1):
	arr1 = array.array('l', [])
	arr2 = array.array('l', [])
	arr2 = [int(w) for w in input().split()]
	n = int(arr2[0])
	x = int(arr2[1])
	arr1 = [int(w) for w in input().split()]
	s = 0
	z = -5
	oo = 0
	xx = -5
	yy = -5
	for j in range(n - 1, -1, -1):
		if arr1[j] % x != 0:
			yy = n - j
			break
	vv = 0
	for j in range(0, n, 1):
		s = s + arr1[j]
		if (arr1[j] % x != 0) & (vv == 0):
			xx = j + 1
			oo = 1
			vv = 1
	ll = -8
	if (xx > -5) & (yy > -5):
		ll = min(xx, yy)
	elif (xx == -5) & (yy > -5):
		ll = yy
	elif (xx > -5) & (yy == -5):
		ll = xx
	if s % x != 0:
		print(n)
	elif oo == 1:
		print(n - ll)
	else:
		print('-1')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	seti = set(a)
	print(min(len(seti), n))


import math

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

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

def li():
	return list(mi())
for _ in range(ii()):
	n = int(input())
	a = li()
	b = set(a)
	print(len(b))


for i in range(int(input())):
	(n, x) = [int(k) for k in input().split()]
	arr = [int(k) for k in input().split()]
	sum = 0
	sum1 = 0
	sum2 = 0
	nn = n
	for ele in arr:
		sum += ele
	if sum % x != 0:
		print(n)
	else:
		while nn:
			sum1 += arr[n - nn]
			if sum1 % x != 0:
				print(nn - 1)
				break
			sum2 += arr[nn - 1]
			if sum2 % x != 0:
				print(nn - 1)
				break
			nn -= 1
			if nn == 0:
				print(-1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	(ans, front, back) = (-1, 0, 0)
	for i in range(n):
		front += a[i]
		back += a[n - i - 1]
		if front % x != 0 or back % x != 0:
			ans = i + 1
	print(ans)


n = int(input())
count = []
for i in range(0, n):
	n1 = int(input())
	l = []
	l = list(map(int, input().split(' ')[:n1]))
	s = set(l)
	count.append(len(s))
	n1 = 0
for i in range(0, len(count)):
	print(count[i])


from sys import *
t = int(stdin.readline())
while t > 0:
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	s = set()
	count = 0
	for i in range(n):
		if arr[i] not in s:
			s.add(arr[i])
			count += 1
		else:
			continue
	print(count)
	t -= 1


n = int(input())
for i in range(n):
	a = int(input())
	lst = list(map(int, input().split()))
	new_lst = set(lst)
	print(len(new_lst))


t = int(input())
for i in range(t):
	x = int(input())
	ch = input()
	L = [int(i) for i in ch.split()]
	s = set()
	for i in L:
		s.add(i)
	print(len(s))


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	moduloArr = []
	totMod = 0
	for ele in arr:
		totMod = (totMod + ele % x) % x
		moduloArr.append(totMod)
	if moduloArr[-1] != 0:
		print(len(arr))
		continue
	maxLength = 0
	firstIndex = None
	for i in range(len(moduloArr)):
		if moduloArr[i] == 0:
			continue
		if firstIndex == None:
			firstIndex = i
		maxLength = i + 1
	if firstIndex == None:
		print(-1)
		continue
	if maxLength < len(arr) - firstIndex - 1:
		maxLength = len(arr) - firstIndex - 1
	print(maxLength)


t = int(input())
while t > 0:
	inp = list(map(int, input().split()))
	n = inp[0]
	x = inp[1]
	a = list(map(int, input().split()))
	sum = 0
	count = 0
	for i in range(n):
		sum += a[i]
		if a[i] % x == 0:
			count += 1
	if sum % x != 0:
		print(n)
	elif count != n:
		count1 = n
		count2 = n
		sum1 = sum
		sum2 = sum
		for i in range(n):
			sum1 -= a[i]
			if sum1 % x != 0:
				count1 = count1 - i - 1
				break
		for i in range(n):
			sum2 -= a[n - 1 - i]
			if sum2 % x != 0:
				count2 = count2 - i - 1
				break
		if count1 > count2:
			print(count1)
		else:
			print(count2)
	else:
		print(-1)
	t -= 1


t = int(input())
for i in range(t):
	(n, x) = (int(x) for x in input().split())
	a = list(map(int, input().split()))
	b = [y % x for y in a]
	m = sum(b) % x
	if m > 0:
		print(n)
	elif sum(b) == 0:
		print(-1)
	else:
		br = list(reversed(b))
		for i in range(n):
			if b[i] > 0:
				t1 = i + 1
				break
		for i in range(n):
			if br[i] > 0:
				t2 = i + 1
				break
		print(n - min(t1, t2))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	(n, x) = mi()
	a = li()
	if x == 1:
		print(-1)
	else:
		suml = sumr = sum(a)
		lpos = 0
		while lpos < n and suml % x == 0:
			suml -= a[lpos]
			lpos += 1
		rpos = n - 1
		while rpos > -1 and sumr % x == 0:
			sumr -= a[rpos]
			rpos -= 1
		if rpos == -1 or lpos == n:
			print(-1)
		else:
			print(max(n - lpos, rpos + 1))


import math
from bisect import bisect_left, bisect_right
from sys import stdin, stdout, setrecursionlimit
from collections import Counter
input = lambda : stdin.readline().strip()
print = stdout.write
t = int(input())
for i in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	print(str(len(set(ls))) + '\n')


from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

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

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

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

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

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

def fsi():
	return str(stdin.readline())

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

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

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

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def dfs(d, v):
	q = []
	q.insert(0, v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.insert(0, i)
		print(x)

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum
t = ii()
for i in range(t):
	n = ii()
	l = li()
	l = set(l)
	print(len(l))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	s = sum(a)
	ans = 0
	i = 0
	j = n - 1
	m = 1000000
	g = 1000000
	if s % x != 0:
		ans = n
		print(ans)
	else:
		for i in range(n):
			if (s - a[i]) % x != 0:
				m = i + 1
				break
			else:
				s = s - a[i]
		s = sum(a)
		for j in range(n - 1, -1, -1):
			if (s - a[j]) % x != 0:
				g = abs(j - n)
				break
			else:
				s = s - a[j]
		if m < n or g < n:
			print(n - min(m, g))
		else:
			print(-1)


t = int(input())
for T in range(t):
	(n, x) = map(int, input().split())
	b = list(map(int, input().split()))
	s = sum(b)
	i = 0
	j = n - 1
	ans = n
	ansNotFound = True
	while i <= j:
		if s % x != 0:
			ansNotFound = False
			break
		else:
			ans -= 1
			s = s - b[i]
			i += 1
	i = 0
	j = n - 1
	s = sum(b)
	ans2 = n
	while i <= j:
		if s % x != 0:
			ansNotFound = False
			break
		else:
			ans2 -= 1
			s = s - b[j]
			j -= 1
	if ansNotFound:
		print(-1)
	else:
		print(max(ans, ans2))


for _ in range(int(input())):
	dict = {}
	n = int(input())
	a = [int(o) for o in input().split()]
	s = set(a)
	c = len(s)
	print(c)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	(ans, i, j) = (0, 0, 1)
	while j < n:
		if a[i] < a[j]:
			ans += 1
			i += 1
			j += 1
		else:
			while j < n and a[i] == a[j]:
				i += 1
				j += 1
	print(ans + 1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
while t > 0:
	n = int(input())
	a = map(int, input().split())
	b = set(a)
	print(len(b))
	t -= 1


from sys import stdin, stdout
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()
cout = lambda s: stdout.write(s)
swrite = lambda s: cout(str(s))
nwrite = lambda s: cout(''.join([str(s), '\n']))

def nwrite2(s):
	cout(str(s))
	cout('\n')

def main():
	T = int(rl())
	for _ in range(T):
		n = int(rl())
		(seen, ans) = (set(), 0)
		for char in rll():
			x = int(char)
			if x not in seen:
				ans += 1
				seen.add(x)
		nwrite(ans)
	stdout.close()
main()


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	lst = list(dict.fromkeys(lst))
	print(len(lst))


t = int(input())
for op in range(t):
	e = list(map(int, input().split()))
	w = list(map(int, input().split()))
	s = sum(w)
	l = -1
	r = -1
	for i in range(len(w)):
		if w[i] % e[1] != 0:
			if l == -1:
				l = i
			r = i
	if l == -1:
		print(-1)
	elif s % e[1] != 0:
		print(len(w))
	else:
		print(e[0] - min(l + 1, e[0] - r))


import math
t = int(input())
while t > 0:
	a = int(input())
	l = list(map(int, input().split()))
	m = list(dict.fromkeys(l))
	print(len(m))
	t -= 1


from sys import *
input = stdin.readline
for u in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	s = 0
	for i in range(n):
		s = s + l[i]
		if s % x:
			c = i + 1
	ka = 0
	for i in range(n):
		s -= l[i]
		if s % x:
			ka = n - i - 1
			break
	if c != 0 or ka != 0:
		print(max(c, ka))
	else:
		print(-1)


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

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

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
for _ in range(I()):
	n = I()
	a = set(L())
	print(len(a))


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = set(a)
	ans = len(b)
	print(ans)


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if x == 1:
		print(-1)
	else:
		s = 0
		ls = []
		for i in a:
			s += i
			ls.append(s % x)
		zero = ls.count(0)
		if zero == n:
			print(-1)
		elif ls[-1]:
			print(n)
		else:
			for i in range(n):
				if ls[i]:
					l = i
					break
			for i in range(n - 1, -1, -1):
				if a[i] % x:
					r = i
					break
			m = max(n - l - 1, r)
			if m:
				print(m)
			else:
				print(-1)


import sys
from collections import Counter

def main():
	for _ in range(int(sys.stdin.readline())):
		n = int(sys.stdin.readline())
		l = [int(y) for y in sys.stdin.readline().split()]
		d = Counter(l)
		print(len(d))
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	l = -1
	for i in range(n):
		if a[i] % x != 0:
			if l == -1:
				l = i
			r = i
		sum += a[i]
	if sum % x != 0:
		print(n, sep='')
	elif l == -1:
		print('-1', sep='')
	else:
		print(n - min(l + 1, n - r), sep='')


def fun(n, x, arr):
	sum = 0
	k = 0
	for i in arr:
		sum += i
		if i % x == 0:
			k += 1
	if k == n:
		return -1
	if sum % x != 0:
		return n
	(l, r) = (0, n - 1)
	for i in range(n):
		if arr[i] % x != 0:
			l = i
			break
	while r >= 0:
		if arr[r] % x != 0:
			break
		else:
			r -= 1
	return max(n - l - 1, r)
t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(fun(n, x, arr))


def eval(a, na, x):
	i = 0
	all_divisible = True
	sum = 0
	while i < len(a):
		sum += a[i]
		if a[i] % x != 0:
			all_divisible = False
		i += 1
	if sum % x != 0:
		return len(a)
	if all_divisible:
		return -1
	start = 0
	end = len(a) - 1
	while a[start] % x == 0 or a[end] % x == 0:
		if a[start] % x == 0:
			start += 1
		if a[end] % x == 0:
			end -= 1
	return max(len(a) - start - 1, end)
for _ in range(int(input())):
	(na, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	print(eval(a, na, x))


from collections import defaultdict
for _ in range(int(input())):
	d = defaultdict(int)
	check = defaultdict(int)
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x:
		print(n)
		continue
	else:
		s = 0
		ans = -1
		for (i, a) in enumerate(l):
			s += a
			s %= x
			if s:
				ans = max(ans, i + 1, n - (i + 1))
		print(ans)


y = int(input())
ans = []
for i in range(y):
	al = input().split()
	m = list(map(int, al))
	n = m[0]
	k = m[1]
	al = input().split()
	m = list(map(int, al))
	s = sum(m)
	s1 = s
	l = n
	z = 0
	x = n - 1
	while s % k == 0:
		s = s - m[z]
		z += 1
		if z > n - 2:
			z = -1
			break
	while s1 % k == 0:
		s1 = s1 - m[x]
		x -= 1
		if x < 1:
			x = -1
			break
	if x == -1 and z == -1:
		ans.append(-1)
	elif x == -1:
		ans.append(n - z)
	elif z == -1:
		ans.append(x + 1)
	else:
		ans.append(max(n - z, x + 1))
for i in ans:
	print(i)


test = int(input())
while test > 0:
	test -= 1
	(x, y) = map(int, input().split())
	l = [int(x) for x in input().split()]
	cnt = 0
	for i in range(len(l)):
		if l[i] % y == 0:
			cnt += 1
	if cnt == x:
		print('-1')
		continue
	sum1 = sum(l)
	if sum1 % y != 0:
		print(x)
		continue
	(i, j) = (0, x - 1)
	(cnt1, cnt2) = (0, 0)
	while i < x and l[i] % y == 0:
		i += 1
		cnt1 += 1
	while j >= 0 and l[j] % y == 0:
		j -= 1
		cnt2 += 1
	if cnt2 > cnt1:
		print(x - cnt1 - 1)
	else:
		print(x - cnt2 - 1)


import sys
input = sys.stdin.readline
import math

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

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

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

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

def from_file(f):
	return f.readline

def solve(n, x, A):
	resid = [-1] * 10000
	resid[0] = 0
	first_seen = [0]
	P = [0] * (n + 1)
	for i in range(1, n + 1):
		P[i] = P[i - 1] + A[i - 1]
		r = P[i] % x
		if resid[r] == -1:
			resid[r] = i
			first_seen.append(i)
	L = 0
	for i in range(1, n + 1):
		r = P[i] % x
		for ind in first_seen:
			o = P[ind] % x
			if r != o:
				break
		else:
			continue
		L = max(L, i - ind)
	if L == 0:
		return -1
	return L
t = inp()
for _ in range(t):
	(n, x) = invr()
	A = inlt()
	print(solve(n, x, A))


import sys
import re
input = sys.stdin.readline

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

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

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

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

def main():
	t = inp()
	for l in range(t):
		(n, x) = invr()
		a = inlist()
		(l, r) = (0, 0)
		(tot, i) = (sum(a), 0)
		while tot % x == 0 and i != n:
			tot -= a[i]
			i += 1
			l += 1
		(tot, i) = (sum(a), n - 1)
		while tot % x == 0 and i != -1:
			tot -= a[i]
			i -= 1
			r += 1
		if l > r:
			(l, r) = (r, l)
		if n - l == 0:
			print('-1')
		else:
			print(n - l)
main()


def longestIncrSub(A):
	n = len(A)
	M = [0 for i in range(n)]
	M[0] = 1
	for i in range(1, n):
		_max = -1
		_1max = 0
		for j in range(i):
			if A[i] > A[j]:
				_1max = M[j] + 1
				if _1max > _max:
					_max = _1max
		M[i] = _max
	return max(M)
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().strip().split()))
	print(len(set(A)))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	max = 0
	count = 0
	for i in l:
		if i == max:
			continue
		else:
			max = i
			count += 1
	print(count)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	k = -1
	t = n + 1
	if s % m != 0:
		print(n)
	else:
		for i in range(n):
			if (s - l[i]) % m != 0:
				k = i
				break
		for i in reversed(range(n)):
			if (s - l[i]) % m != 0:
				t = i
				break
		if k == -1:
			print(-1)
		else:
			print(max(n - k - 1, t))


import sys
input = sys.stdin.readline

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

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

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

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

def solve(dim, t):
	(n, x) = (dim[0], dim[1])
	total = sum(t)
	if total % x != 0:
		print(n)
	else:
		left = 0
		right = n - 1
		found = False
		remove = 0
		while left <= right:
			remove += 1
			if t[left] % x != 0 or t[right] % x != 0:
				found = True
				break
			left += 1
			right -= 1
		if found:
			print(n - remove)
		else:
			print(-1)
T = inp()
tests = []
dims = []
for _ in range(T):
	dims.append(inlt())
	tests.append(inlt())
for i in range(T):
	solve(dims[i], tests[i])


from sys import *
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	s = 0
	d = []
	for i in range(n):
		if l[i] % m != 0:
			c += 1
			d.append(i)
		s += l[i]
	if c == 0:
		print(-1)
	elif s % m != 0:
		print(n)
	else:
		left = n - (d[0] + 1)
		right = d[-1]
		print(max(left, right))


T = int(input())
for i in range(T):
	input()
	a = input().split()
	print(len(set(a)))


import queue
import math
t = int(input())
while t:
	line = input().split()
	(n, x) = (int(line[0]), int(line[1]))
	a = list(map(int, input().split()))
	s = 0
	m = -1
	for i in range(n):
		s = (s + a[i]) % x
		if s:
			m = i + 1
	s = 0
	for i in range(n - 1, -1, -1):
		s = (s + a[i]) % x
		if s:
			m = max(n - i, m)
	print(m)
	t -= 1


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	count = n
	a.sort()
	for i in range(1, n):
		if a[i] == a[i - 1]:
			count -= 1
	print(count)


def run_arr(arr, num):
	s = set(arr)
	print(min(len(s), num))

def run():
	n = int(input())
	arrs = []
	nums = []
	for _ in range(n):
		nums.append(int(input()))
		arr = list(map(int, input().split()))
		arrs.append(arr)
	for i in range(n):
		run_arr(arrs[i], nums[i])
run()


n1 = int(input())
for i in range(n1):
	k = int(input())
	li = map(int, input().split())
	print(len(set(li)))


counter = input()
for i in range(0, int(counter)):
	x = input()
	array = input()
	array = array.split(' ')
	array2 = set(array)
	arrayLength = len(array2)
	print(arrayLength)


def ans(l, k, nums):
	sum = 0
	ans = -1
	total = 0
	count = 0
	for i in nums:
		total += i
		if i % k == 0:
			count += 1
	if count == l:
		return -1
	elif total % k != 0:
		return l
	else:
		for i in range(l):
			if nums[i] % k != 0:
				left = i
				break
		for i in range(l - 1, -1, -1):
			if nums[i] % k != 0:
				right = i
				break
		return l - min(left + 1, l - right)
t = int(input())
for i in range(t):
	(l, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	print(ans(l, k, nums))


import math, sys
import heapq
from fractions import Fraction
from collections import Counter, defaultdict

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

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

def la():
	return list(input())

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

def dic(x):
	return defaultdict(lambda : x)
t = ii()
for _ in range(t):
	(n, x) = li()
	a = li()
	total = sum(a)
	if total % x != 0:
		print(n)
	else:
		flag = 0
		temp = 0
		tempb = 0
		for i in range(n):
			temp += a[i]
			tempb += a[n - i - 1]
			if temp % x != 0 or tempb % x != 0:
				flag = i + 1
				break
		if flag == 0:
			print(-1)
		else:
			print(n - flag)


p = int(input())
for q in range(p):
	n = int(input())
	entrada = list(map(int, input().split(' ')))
	entrada.sort()
	cont = n
	for k in range(1, n):
		if entrada[k] == entrada[k - 1]:
			cont -= 1
	print(cont)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
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
mx = 10 ** 7 + 1
for _ in range(I()):
	(n, x) = R()
	a = list(R())
	f1 = f2 = -1
	if sum(a) % x:
		print(n)
		continue
	for i in range(n):
		if a[i] % x:
			f1 = n - (i + 1)
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x:
			f2 = i
			break
	print(max(f1, f2))


t = int(input())
for i in range(t):
	a = int(input())
	b = [int(s) for s in input().split()]
	b.sort()
	s = 1
	for k in range(1, len(b)):
		if b[k] > b[k - 1]:
			s += 1
	print(s)


def help():
	(n, x) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	if sum(arr) % x != 0:
		print(n)
		return
	notd = []
	for i in range(n):
		if arr[i] % x != 0:
			notd.append(i)
	if len(notd) == 0:
		print(-1)
		return
	s1 = notd[0]
	s2 = notd[-1]
	s2 = n - 1 - s2
	print(max(s1, n - 1 - s1, s2, n - 1 - s2))
for _ in range(int(input())):
	help()


t = int(input())
for test in range(t):
	(n, x) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	l = n
	r = n
	for el in range(n):
		if a[el] % x != 0:
			if el + 1 < l:
				l = el + 1
			if n - el < r:
				r = n - el
	lem = min(l, r)
	if sum(a) % x != 0:
		print(n)
	elif lem < n:
		print(n - lem)
	else:
		print(-1)


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(itg()):
	n = itg()
	a = mpint()
	print(len(set(a)))


for i in range(int(input())):
	(n, x) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	if sum(arr) % x != 0:
		print(n)
	else:
		(l, r) = (0, 0)
		for i in range(0, n // 2 + 1):
			if arr[i] % x == 0:
				l += 1
			if arr[-1 - i] % x == 0:
				r += 1
			if arr[i] % x != 0 or arr[-1 - i] % x != 0:
				break
		if r == n // 2 + 1 and l == n // 2 + 1:
			print(-1)
		else:
			print(n - min(l + 1, r + 1))


from collections import Counter, deque, defaultdict
from math import *
from bisect import bisect_right
MOD = 1000000007

def solve():
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	y = sum(l)
	if y % x:
		print(n)
		return
	for i in l:
		if i % x:
			break
	else:
		print(-1)
		return
	for i in range(n):
		if l[i] % x:
			left = i
			break
	cur = 0
	for i in range(n - 1, -1, -1):
		cur += 1
		if l[i] % x:
			right = cur
			break
	print(n - min(left + 1, right))
t = int(input())
for num in range(t):
	solve()


for _ in range(int(input())):
	(n, x) = [int(x) for x in input().split()]
	l = list(map(int, input().split()))
	for i in range(len(l)):
		l[i] = l[i] % x
	f = sum(l) % x
	if f != 0:
		print(len(l))
	elif l.count(0) == len(l):
		print('-1')
	else:
		for x in range(len(l)):
			if l[x] != 0:
				m = max(x + 1, n - x - 1)
				break
		for x in range(len(l)):
			if l[len(l) - x - 1] != 0:
				j = max(x + 1, n - x - 1)
				break
		print(max(m, j))


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi, log
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from functools import cmp_to_key, reduce
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')

def solve():
	T = int(sys.stdin.readline())
	for _ in range(T):
		(n, k) = map(int, sys.stdin.readline().split())
		a = list(map(int, sys.stdin.readline().split()))
		c = 0
		for i in a:
			if i % k == 0:
				c += 1
		if c == n:
			print(-1)
		elif sum(a) % k != 0:
			print(n)
		else:
			(l, r) = (None, None)
			for i in range(n):
				if a[i] % k != 0:
					l = i
					break
			for i in range(n - 1, -1, -1):
				if a[i] % k != 0:
					r = i
					break
			print(n - min(l + 1, n - r))
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
solve()


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	c = sum(a)
	d = []
	if c % x != 0:
		print(n)
	else:
		for i in range(n):
			if a[i] % x != 0:
				d.append(i)
		if len(d) == 0:
			print('-1')
		else:
			print(max(n - d[0] - 1, d[-1]))


t = int(input())
for i in range(t):
	n = int(input())
	cnt = {}
	ar = [int(x) for x in input().split()]
	for c in ar:
		if c in cnt:
			cnt[c] += 1
		else:
			cnt[c] = 1
	print(len(cnt.keys()))


from collections import Counter, defaultdict, deque
from heapq import heapify, heappush, heappop, heappushpop
from sys import stdin
int_inp = lambda : int(stdin.readline().strip())
lst_inp = lambda : [int(i) for i in stdin.readline().strip().split(' ')]
str_inp = lambda : stdin.readline().strip()

def lis_length(A):
	n = len(A)
	lis = [1] * n
	for i in range(n):
		for j in range(i):
			if A[j] <= A[i] and lis[j] + 1 >= lis[i]:
				lis[i] = lis[j] + 1
	return max(lis)
for _ in range(int_inp()):
	n = int_inp()
	a = lst_inp()
	print(len(set(a)))


for test in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	su = sum(arr)
	for i in range(n):
		if arr[i] % x != 0:
			break
	for j in range(n - 1, -1, -1):
		if arr[j] % x != 0:
			break
	if su % x != 0:
		print(n)
	elif i == n - 1 and j == 0:
		print(-1)
	else:
		print(max(n - i - 1, i + 1, j, n - j))


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
for _ in range(int(input())):
	n = int(input())
	l = set(input().split())
	print(str(len(l)) + '\n')


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	(l, r) = (-1, -1)
	temp_sum = 0
	for (i, j) in enumerate(a):
		if j % x != 0:
			if l == -1:
				(l, r) = (i, i)
			else:
				r = i
		temp_sum += j
	if l == -1:
		print('-1')
	elif temp_sum % x != 0:
		print(n)
	else:
		print(max(n - l - 1, n - (n - r)))


t = int(input())
while t:
	(n, x) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	d = 0
	s = 0
	for i in range(n):
		if l[i] % x == 0:
			d += 1
	if d == n:
		print(-1)
	elif sum(l) % x != 0:
		print(n)
	else:
		i = 0
		j = n - 1
		while l[i] % x == 0:
			i += 1
		while l[j] % x == 0:
			j -= 1
		print(n - min(i + 1, n - j))
	t -= 1


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = set(map(int, input().strip().split()))
		print(len(a))
main()


for i in range(int(input())):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		flag = False
		y = s
		for j in range(n):
			if (s - l[j]) % x != 0:
				flag = True
				print(n - j - 1)
				break
			else:
				s = s - l[j]
			if (y - l[n - 1 - j]) % x != 0:
				flag = True
				print(n - 1 - j)
				break
			else:
				y = y - l[n - 1 - j]
		if flag == False:
			print(-1)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr2 = reversed(arr)
	one = 0
	two = 0
	if sum(arr) % x != 0:
		print(n)
	else:
		for k in arr:
			if k % x == 0:
				one += 1
			else:
				one += 1
				break
		for k in arr2:
			if k % x == 0:
				two += 1
			else:
				two += 1
				break
		if one == n:
			print(-1)
		else:
			print(n - min(one, two))


for _ in range(int(input())):
	(n, x) = [int(num) for num in input().split()]
	a = [int(x) for x in input().split()]
	shit = sum(a)
	if shit % x != 0:
		print(len(a))
	else:
		i = 0
		k = 0
		while i != n // 2:
			if a[i] % x != 0 or a[-i - 1] % x != 0:
				print(n - i - 1)
				k = 1
				break
			i += 1
		if k == 0:
			print(-1)


for i in range(int(input())):
	d = int(input())
	g = list(map(int, input().split()))
	f = set(g)
	print(len(f))


def countDistinct(arr, n):
	s = set()
	res = 0
	for i in range(n):
		if arr[i] not in s:
			s.add(arr[i])
			res += 1
	return res
test = int(input())
while test > 0:
	n = int(input())
	a = []
	test = test - 1
	a = list(map(str, input().split()))
	print(countDistinct(a, n))


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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = len(set(a))
	print(ans)
t = int(input())
for i in range(t):
	solve()


import math
import fractions

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors

def ValueToBits(x, digit):
	res = [0 for i in range(digit)]
	now = x
	for i in range(digit):
		res[i] = now % 2
		now = now >> 1
	return res

def BitsToValue(arr):
	n = len(arr)
	ans = 0
	for i in range(n):
		ans += arr[i] * 2 ** i
	return ans

def ValueToArray10(x, digit):
	ans = [0 for i in range(digit)]
	now = x
	for i in range(digit):
		ans[digit - i - 1] = now % 10
		now = now // 10
	return ans
m = int(input())
for i in range(m):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	count = 1
	for j in range(n - 1):
		if a[j] != a[j + 1]:
			count += 1
	print(count)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	max = 0
	if sum(lst) % x != 0:
		print(n)
	else:
		(cnt, cnt1) = (-1, -1)
		for i in range(n):
			if lst[i] % x != 0:
				cnt = i
				break
		for i in range(n - 1, -1, -1):
			if lst[i] % x != 0:
				cnt1 = i
				break
		(cnt3, cnt4) = (n - cnt - 1, n - cnt1 - 1)
		if cnt == -1 and cnt1 == -1:
			print(-1)
		else:
			if cnt3 > cnt:
				cnt = cnt3
			if cnt4 > cnt1:
				cnt1 = cnt4
			if cnt > cnt1:
				print(cnt)
			else:
				print(cnt1)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	a.sort()
	cnt = 1
	for i in range(1, n):
		if a[i] > a[i - 1]:
			cnt += 1
	print(cnt)


import sys
from collections import defaultdict
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	s = set(arr)
	l = list(s)
	print(len(l))


from math import *
from copy import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def solve(l):
	n = len(l)
	L = defaultdict(int)
	for i in range(n):
		L[l[i]] += n
	x = sorted(L.keys())
	return len(x)
T = int(input())
for _ in range(T):
	N = int(stdin.readline())
	l = list(map(int, stdin.readline().rstrip().split()))
	print(solve(l))


q = int(input())
for _ in range(q):
	n = int(input())
	dat = list(map(int, input().split()))
	dat.sort()
	cnt = 0
	prev = -1
	for i in range(n):
		if prev < dat[i]:
			cnt += 1
		prev = dat[i]
	print(cnt)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline().split()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	n = int_input()
	arr = list_input()
	seti = set([])
	for i in arr:
		seti.add(i)
	print(len(seti))


def solve():
	(n, x) = map(int, input().split())
	lst = list(map(int, input().split()))
	fp = -1
	lp = -1
	sm = 0
	for i in range(n):
		sm += lst[i]
		sm %= x
		if lst[i] % x != 0:
			if fp == -1:
				fp = i
			lp = i
	if sm:
		print(n)
	elif fp == -1 and lp == -1:
		print(-1)
	elif fp == -1:
		print(lp)
	elif lp == -1:
		print(n - fp - 1)
	else:
		print(max(n - fp - 1, lp))
for t in range(int(input())):
	solve()


t = int(input())
for _ in range(t):
	repeat = int(input())
	l = list(map(int, input().split()))
	d = set(l)
	d = list(d)
	if repeat >= len(d):
		print(len(d))
	else:
		print(repeat)


from collections import Counter
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 Counter
import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	arr = list(map(int, input().split()))
	var = sum(arr)
	if sum(arr) % b != 0:
		print(a)
	else:
		be = 0
		en = 0
		m = a
		for i in range(a):
			var -= arr[i]
			be += 1
			if var % b != 0:
				m = min(m, be)
		arr = arr[::-1]
		var = sum(arr)
		for j in range(a):
			var -= arr[j]
			en += 1
			if var % b != 0:
				m = min(m, en)
		if m == a:
			print(-1)
		else:
			print(a - m)


k = int(input())
for i in range(k):
	a = int(input())
	v = map(int, input().strip().split())
	print(len(set(v)))


am = int(input())
res = list()
for i in range(am):
	lenk = int(input())
	lis = set(map(int, input().split()))
	res.append(len(lis))
print(*res, sep='\n')


a = int(input())
for _ in range(a):
	m = int(input())
	result = m
	ary = map(int, input().split())
	ary = sorted(ary)
	for i in range(m - 1):
		if ary[i] == ary[i + 1]:
			result -= 1
	print(result)


import sys
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	sum1 = 0
	sum2 = 0
	i = 0
	max1 = -1
	max2 = -1
	while i < n:
		sum1 += l[i]
		if sum1 % x != 0:
			max1 = max(max1, i + 1)
		i += 1
	j = n - 1
	counter = 0
	while j > -1:
		sum2 += l[j]
		if sum2 % x != 0:
			max2 = max(max2, counter + 1)
		counter += 1
		j -= 1
	print(max(max1, max2))


for _ in range(int(input())):
	b = int(input())
	print(len(set(map(int, input().split()))))


t = int(input())
for i in range(t):
	_ = int(input())
	a = list(map(int, input().split()))

	def copy(a):
		print(len(set(a)))
	copy(a)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(set(input().split()))
	a.sort()
	print(len(a))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	print(len(list(set(a))))


tc = int(input())
for _ in range(tc):
	(length, x) = map(int, input().split())
	array = list(map(int, input().split()))
	if sum(array) % x != 0:
		print(len(array))
	else:
		i = 0
		j = len(array) - 1
		while i <= j:
			if array[i] % x == 0:
				i += 1
			else:
				print(len(array) - i - 1)
				break
			if array[j] % x == 0:
				j -= 1
			else:
				print(j)
				break
		if i > j:
			print(-1)


import sys, os, io

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

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math as mt

def main():
	tc = ri()
	for _ in range(tc):
		(n, k) = ria()
		a = ria()
		s = sum(a)
		ans = -1
		z = 0
		for i in range(n):
			z += a[i]
			if z % k != 0:
				ans = max(i + 1, n - i - 1, ans)
		wi(ans)

class FastReader(io.IOBase):
	newlines = 0

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

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

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

class FastWriter(io.IOBase):

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

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

class FastStdin(io.IOBase):

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

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


numTestcases = int(input())
for i in range(numTestcases):
	n = int(input())
	nums = list(map(int, input().split(' ')))
	nums = list(dict.fromkeys(nums))
	print(len(nums))


for _ in range(int(input())):
	a = int(input())
	Li = list(map(int, input().split()))
	Ls = sorted(Li)
	ld = list(dict.fromkeys(Ls))
	print(len(ld))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = a
	x = 0
	y = 0
	s = sum(l)
	for i in range(a):
		if l[i] % b != 0 or l[a - i - 1] % b != 0:
			x += 1
			break
		else:
			x += 1
	if s % b != 0:
		print(a)
	elif x == a:
		print(-1)
	else:
		print(a - x)


for i in range(int(input())):
	n = int(input())
	arr = {}
	extraNum = 0
	for i in map(int, input().split()):
		if i in arr:
			extraNum += 1
		else:
			arr[i] = 1
	print(n - extraNum)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

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

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

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

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['Yes', 'No']
test_case = ii()
while test_case:
	test_case -= 1
	(n, m) = mi()
	a = li()
	b = [i for i in a[::-1]]
	a[0] %= m
	for i in range(1, n):
		a[i] += a[i - 1]
		a[i] %= m
	if a[-1]:
		ans = n
	else:
		x = -1
		for i in range(n):
			if a[i]:
				x = i + 1
				break
		if x == -1 or x >= n - x:
			ans = x
		else:
			ans = n - x
	b[0] %= m
	for i in range(1, n):
		b[i] += b[i - 1]
		b[i] %= m
	if b[-1]:
		ans1 = n
	else:
		x = -1
		for i in range(n):
			if b[i]:
				x = i + 1
				break
		if x == -1 or x >= n - x:
			ans1 = x
		else:
			ans1 = n - x
	print(max(ans, ans1))


t = int(input())
for i in range(t):
	n = int(input())
	numSet = {int(k) for k in input().split()}
	print(len(numSet))


import sys
input = sys.stdin.readline

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

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

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

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

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	for test in range(tests):
		n = inp()
		a = inlt()
		ans = 0
		hashm = {}
		for i in a:
			if i not in hashm:
				ans += 1
				hashm[i] = 1
		print(ans)
	return 0
main()


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	l = list(map(int, input().strip().split()))
	m = []
	m = list(dict.fromkeys(l))
	print(len(m))


for i in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	dict1 = {}
	count = 0
	for j in range(x):
		if l[j] not in dict1:
			dict1[l[j]] = 1
			count += 1
	print(count)


I = input
for _ in range(int(I())):
	I()
	print(len(set(I().split())))


import sys

def main():
	for i in range(int(sys.stdin.readline())):
		n = int(sys.stdin.readline())
		arr = [int(x) for x in sys.stdin.readline().split(' ')]
		print(len(set(arr)))
main()


import sys
for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		o1 = sys.maxsize
		o2 = sys.maxsize
		for i in range(0, n):
			if a[i] % x != 0:
				o1 = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				o2 = n - (i + 1)
				break
		m = min(o1, o2)
		if m == sys.maxsize:
			print(-1)
			continue
		print(n - (m + 1))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(len(l))
	else:
		a = 0
		b = len(l) - 1
		i = sum(l)
		j = sum(l)
		p = len(l)
		q = len(l)
		mx1 = 0
		mx2 = 0
		while a <= b:
			i -= l[a]
			j -= l[b]
			p -= 1
			q -= 1
			if i % x != 0:
				mx1 = p
				a += 1
				break
			else:
				a += 1
			if j % x != 0:
				mx2 = q
				b -= 1
				break
			else:
				b -= 1
		if mx1 == 0 and mx2 == 0:
			print(-1)
		else:
			print(max(mx1, mx2))


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	s = set(l)
	print(len(s))


from collections import deque

def solve(arr):
	new = list(set(arr))
	return str(len(new)) + '\n'
t = int(input())
output = ''
for i in range(t):
	length = int(input())
	arr = [int(x) for x in input().split(' ')]
	output += solve(arr)
print(output)


t = int(input())
while t:
	input()
	a = set(map(int, input().split()))
	print(len(a))
	t -= 1


for _ in range(int(input())):
	input()
	print(len({*input().split()}))


for i in range(int(input())):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if sum(b) % a[1] == 0:
		c = -1
		for i2 in b:
			if i2 % a[1] != 0:
				c = i2
				break
		if c != -1:
			d = -1
			for i2 in b[::-1]:
				if i2 % a[1] != 0:
					d = i2
					break
			print(max(a[0] - b.index(c) - 1, a[0] - b[::-1].index(d) - 1))
		else:
			print(-1)
	else:
		print(a[0])


t = int(input())
for _ in range(t):
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	s = list(map(int, input().split()))
	ln = len(s)
	s0 = 0
	l0 = 0
	min_ln = 0
	if sum(s) % x != 0:
		print(ln)
	else:
		for i in s:
			s0 += i
			l0 += 1
			if s0 % x != 0:
				min_ln = l0
				s0 = 0
				l0 = 0
				break
		else:
			print(-1)
		for i in s[::-1]:
			s0 += i
			l0 += 1
			if s0 % x != 0:
				min_ln = min((min_ln, l0))
				print(ln - min_ln)
				break


t = int(input())
for k in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))[:n]
	s = sum(a)
	f = 0
	ans = 0
	ans2 = 0
	s1 = sum(a)
	s2 = sum(a)
	if s % x != 0:
		print(n)
		continue
	for i in range(n):
		if f == 0:
			if (s1 - a[i]) % x != 0:
				f = 1
				ans = n - i - 1
			s1 = s1 - a[i]
		if f == 0:
			if (s2 - a[n - i - 1]) % x != 0:
				f = 1
				ans2 = n - i - 1
			s2 = s2 - a[n - i - 1]
	if f == 0:
		print(-1)
	else:
		print(max(ans, ans2))


cases = int(input())
for i in range(cases):
	n = int(input())
	l2 = input().split(' ')
	arr = []
	for a in l2:
		arr.append(int(a))
	d = {}
	for b in arr:
		if b in d:
			d[b] += 1
		else:
			d[b] = 1
	print(len(d))


T = int(input())
for t in range(T):
	(N, X) = [int(_) for _ in input().split()]
	A = [int(_) for _ in input().split()]
	s = 0
	(fmin, fmax) = (N + 1, -1)
	f = False
	for (i, el) in enumerate(A):
		s += el
		if el % X:
			f = True
			fmin = min(fmin, i)
			fmax = max(fmax, i)
	if s % X:
		print(N)
	elif not f:
		print(-1)
	else:
		print(max(N - fmin - 1, fmax))


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	s = set()
	for i in a:
		s.add(i)
	print(len(s))
	t -= 1


import sys
import heapq
from math import ceil, floor, gcd, fabs, factorial, fmod
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
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

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 [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	arr = l()
	out(str(len(set(arr))) + '\n')


def solve():
	n = int(input())
	u = set()
	for i in map(int, input().split()):
		u.add(i)
	print(len(u))
t = int(input())
for i in range(t):
	solve()


q = int(input())
for u in range(q):
	e = int(input())
	w = list(map(int, input().split()))
	print(len(set(w)))


try:
	for _ in range(int(input())):
		n = int(input())
		l = list(map(int, input().split()))
		print(len(set(l)))
except:
	pass


t = int(input())
for x in range(0, t, 1):
	n = int(input())
	arr = list(map(int, input().split()[:n]))
	ans = set(arr)
	print(len(ans))


def func(array):
	array_set = set(array)
	unique_list = list(array_set)
	print(len(unique_list))
t = int(input())
for _ in range(t):
	n = int(input())
	string_ = input().split(' ')
	array = [int(x) for x in string_]
	func(array)


from collections import Counter
n = int(input())
for _ in range(n):
	input()
	print(len(Counter(map(int, input().split()))))


def rez():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
	else:
		f = sum(a)
		s = sum(a)
		k = 0
		ans = []
		for i in range(n):
			if f % x == 0:
				f -= a[i]
			else:
				ans.append(i)
				break
		for i in range(n - 1, -1, -1):
			if s % x == 0:
				s -= a[i]
			else:
				ans.append(n - i - 1)
				break
		if not ans:
			print(-1)
		else:
			print(n - min(ans))
for t in range(int(input())):
	rez()


def main():
	from sys import stdin, stdout
	for _ in range(int(stdin.readline())):
		(n, x) = map(int, stdin.readline().split())
		arr = list(map(int, stdin.readline().split()))
		for (i, j) in enumerate(arr):
			arr[i] = j % x
		res = sum(arr) % x
		if res:
			stdout.write(str(n) + '\n')
		else:
			leftmost = 0
			rightmost = n - 1
			for i in arr:
				if i:
					break
				else:
					leftmost += 1
			for i in range(n - 1, -1, -1):
				if arr[i]:
					break
				else:
					rightmost -= 1
			res = max(n - (leftmost + 1), n - (n - 1 - rightmost + 1))
			stdout.write(str(res) + '\n')
main()


for _ in [0] * int(input()):
	input()
	print(len({*map(int, input().split())}))


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	l = list(map(int, input().split()))
	s = 0
	for j in l:
		s += j
	if s % c != 0:
		print(b)
	else:
		d = -1
		r = -1
		for j in range(b):
			if l[j] % c != 0:
				d = j
				break
		for i in range(b - 1, -1, -1):
			if l[i] % c != 0:
				r = i
				break
		if d == -1 and r == -1:
			print(-1)
		else:
			print(max(b - d - 1, r))


test = int(input())
for _ in range(test):
	(n, x) = map(int, input().split())
	arr = input().split()
	s = sum(map(int, arr))
	flag = 0
	m = n + 1
	if s % x != 0:
		print(n)
		flag = 1
	else:
		for i in range(n):
			if int(arr[i]) % x != 0:
				if n - i - 1 >= 0:
					temp = min(i, n - 1 - i)
				else:
					temp = i
				if temp < m:
					m = temp
				flag = 1
		if flag != 0:
			print(n - 1 - m)
	if flag == 0:
		print(-1)


t = int(input())
for i in range(t):
	an = int(input())
	a = list(map(int, input().split(' ')))
	s = set(a)
	sn = int(len(s))
	print(sn)


from sys import stdin, stdout

def input():
	return stdin.readline()
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	s1 = s
	(c1, c2) = (0, 0)
	if s % x != 0:
		print(n)
	else:
		i = 0
		while i < n:
			s1 -= a[i]
			if s1 % x != 0:
				c1 = n - i - 1
				break
			i += 1
		i = 0
		s2 = s
		while i < n:
			s2 -= a[n - i - 1]
			if s2 % x != 0:
				c2 = n - i - 1
				break
			i += 1
		maxi = max(c1, c2)
		if maxi == 0:
			print(-1)
		else:
			print(maxi)


t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().rstrip().split()))
	num = list(map(int, input().rstrip().split()))
	dsum = 0
	mlen = 0
	for i in range(len(num)):
		dsum += num[i]
		if dsum % x != 0:
			mlen = i
			dsum = 0
	dsum = 0
	nlen = 0
	for i in range(len(num) - 1, -1, -1):
		dsum += num[i]
		if dsum % x != 0:
			nlen = len(num) - i
	a = max(mlen, nlen)
	if a == 0:
		print(-1)
	else:
		print(a)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = len(set(l))
	print(min(n, s))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x == 0:
		l = 1
		for i in range(n):
			if not a[i] % x == 0:
				break
			else:
				l += 1
		if l == n:
			print(-1)
		else:
			r = 1
			for i in range(n - 1, -1, -1):
				if not a[i] % x == 0:
					break
				else:
					r += 1
			w = min(r, l)
			print(n - w)
	else:
		print(n)


sc = iter(open(0).read().split())
ni = lambda : int(next(sc))
ns = lambda : next(sc)
T = ni()
for _ in range(T):
	N = ni()
	A = {ni() for _ in range(N)}
	print(len(A))


from sys import stdin, stdout, stderr, maxsize
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
S = lambda : stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
for _ in range(I()):
	(n, x) = tup()
	ls = lint()
	s = sum(ls)
	a = n - 1
	ans = n
	while s % x == 0 and a > -1:
		s -= ls[a]
		a -= 1
		ans -= 1
	a = 0
	ans2 = n
	s = sum(ls)
	while s % x == 0 and a < n:
		s -= ls[a]
		a += 1
		ans2 -= 1
	print(-1) if max(ans2, ans) == 0 else print(max(ans2, ans))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	maxm = -1
	summ = sum(a)
	for i in range(n):
		if summ % x != 0:
			maxm = max(maxm, n - i)
			break
		summ -= a[i]
	summ = sum(a)
	for i in range(1, n + 1):
		if summ % x != 0:
			maxm = max(maxm, n - i + 1)
			break
		summ -= a[-i]
	print(maxm)


for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	print(len(set(L)))


a = int(input())
for x in range(a):
	b = int(input())
	k = list(map(int, input().split()))
	k = list(dict.fromkeys(k))
	print(len(k))


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	nums = set([int(i) for i in input().strip().split()])
	print(len(nums))


tests = int(input())
for i in range(tests):
	numbers = input().split(' ')
	n = int(numbers[0])
	x = int(numbers[1])
	line = [int(j) for j in input().split(' ')]
	left = -1
	right = -1
	add = 0
	for j in range(n):
		add += line[j]
		if line[j] % x != 0:
			if left == -1:
				left = j
			right = j
	if add % x != 0:
		print(n)
	elif left >= 0 or right >= 0:
		print(max(n - left - 1, right))
	else:
		print(-1)


t = int(input())
for i in range(0, t):
	x = 1
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	for j in range(0, n - 1):
		if a[j] != a[j + 1]:
			x = x + 1
		else:
			continue
	print(x)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	l = -1
	s = 0
	for i in range(n):
		if arr[i] % k != 0:
			if l == -1:
				l = i
			r = i
			s += arr[i]
	if s % k != 0:
		print(n)
	elif l == -1:
		print(-1)
	else:
		pr = l + 1
		su = n - r
		print(n - min(pr, su))


data = input().rstrip().split()
t = int(data[0])
for _ in range(t):
	n = int(input().rstrip().split()[0])
	arr = input().rstrip().split()
	arr = [int(a) for a in arr]
	print(len(set(arr)))


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	a = sorted(a)
	print(len(list(set(a))))
	t = t - 1


tc = int(input())
for m in range(tc):
	n = int(input())
	a = list(map(int, input().split(' ')))
	a = set(a)
	print(len(a))


def main(a):
	return len(set(a))
t = int(input())
cases = []
for i in range(t):
	n = int(input())
	cases.append(list(map(int, input().replace(',', ' ').split())))
for case in cases:
	print(main(case))


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits

def read_line():
	return stdin.readline().strip()

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def solve():
	(n, x) = read_int_arr()
	a = read_int_arr()
	if sum(a) % x != 0:
		print(n)
		return
	res = -1
	pre_sum = 0
	for (i, v) in enumerate(a, 1):
		pre_sum += v
		if pre_sum % x != 0:
			res = max(res, n - i)
	suf_sum = 0
	for (i, v) in enumerate(reversed(a), 1):
		suf_sum += v
		if suf_sum % x != 0:
			res = max(res, n - i)
	print(res)

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		solve()
main()


testCase = int(input())
arr = {}
for i in range(testCase):
	_ = int(input())
	a = [int(i) for i in input().split()]
	arr = set(a)
	print(len(arr))


from collections import Counter
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n, x) = gil()
	a = gil()
	ans = -1
	pre = a[:]
	for i in range(1, n):
		pre[i] += pre[i - 1]
	for i in range(n):
		if pre[i] % x:
			ans = max(ans, i + 1)
	pre = a[:]
	for i in reversed(range(n - 1)):
		pre[i] += pre[i + 1]
	for i in range(n):
		if pre[i] % x:
			ans = max(ans, n - i)
	print(ans)


import sys

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, x) = get_ints()
	arr = get_array()
	s = 0
	l = -1
	r = 0
	for (idx, val) in enumerate(arr):
		s += val
		if val % x != 0:
			if l == -1:
				l = idx
			r = idx
	if s % x != 0:
		print(n)
	elif l == -1:
		print(-1)
	else:
		print(n - min(l + 1, n - r))


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


def main():
	for _ in range(int(input())):
		input()
		print(len(set(input().split())))
main()


for i in range(0, int(input())):
	n = int(input())
	mylist = list(map(int, input().split()))
	mylist.sort()
	temp = 0
	minus = 0
	for item in mylist:
		if temp == item:
			minus = minus + 1
		temp = item
	print(n - minus)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	ans = -1
	if s % x != 0:
		print(n)
	else:
		(k1, k2) = (-1, -1)
		for i in range(n):
			if a[i] % x != 0:
				k1 = i + 1
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				k2 = n - i
				break
		if k1 == k2 == -1:
			print(-1)
		else:
			print(max(n - k1, n - k2))


def inp():
	ls = list(map(int, input().split()))
	return ls
t = int(input())
for ii in range(t):
	(n, x) = map(int, input().split())
	ls = inp()
	flag = False
	r = sum(ls)
	if r % x != 0:
		print(n)
		continue
	ans = n
	for i in range(n):
		if ls[i] % x != 0:
			k = i
			flag = True
			break
	for i in range(n - 1, -1, -1):
		if ls[i] % x != 0:
			l = i
			flag = True
			break
	if flag:
		print(ans - min(k + 1, n - l))
	if not flag:
		print(-1)


q = int(input())
for i in range(q):
	n = int(input())
	A = list(map(int, input().split()))
	print(len(set(A)))


import math
import sys
from itertools import permutations
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	for j in range(n):
		arr[j] = arr[j] % x
	pre = [arr[0]]
	for j in range(1, n):
		pre.append(pre[-1] + arr[j])
		pre[j] = pre[j] % x
	if pre[-1] != 0:
		print(n)
	else:
		x1 = -1
		for j in range(n):
			if pre[j] != 0:
				x1 = j
				break
		arr = arr[::-1]
		pre = [arr[0]]
		for j in range(1, n):
			pre.append(pre[-1] + arr[j])
			pre[j] = pre[j] % x
		x2 = -1
		for j in range(n):
			if pre[j] != 0:
				x2 = j
				break
		if x1 == -1:
			print(-1)
		else:
			y = min(x1, x2)
			print(n - y - 1)


from sys import stdin, gettrace
if not gettrace():

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

def main():

	def solve():
		n = int(input())
		aa = {int(a) for a in input().split()}
		print(len(aa))
	q = int(input())
	for _ in range(q):
		solve()
main()


from collections import Counter
for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().strip().split()))[:n]
	print(len(Counter(lst).keys()))


from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
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 N():
	return int(input())

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

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def c(nums):
	from bisect import bisect_left
	rec = []
	for i in nums:
		p = bisect_left(rec, i)
		if p >= len(rec):
			rec.append(i)
		else:
			rec[p] = min(rec[p], i)
	return len(rec)

def main():
	for _ in range(N()):
		n = N()
		arr = list(RL())
		ll = c(arr)
		le = len(set(arr))
		print(max(min(le, n), ll))
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	s = list(map(int, input().split()))
	sum = 0
	t = -1
	for i in range(a):
		sum = sum + s[i]
		s[i] = sum
	if not sum % b == 0:
		print(a)
	else:
		for i in range(a):
			if (sum - s[i]) % b:
				t = max(t, a - i - 1)
				break
		for i in range(a - 1, -1, -1):
			if s[i] % b:
				t = max(t, i + 1)
				break
		print(t)


for _ in range(int(input())):
	n = int(input())
	ar = {int(x) for x in input().split()}
	ans = len(ar)
	print(ans)


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	(n, x) = ilele()
	A = alele()
	s = sum(A)
	if s % x != 0:
		print(n)
	else:
		maxi = -1
		for i in range(n):
			if A[i] % x != 0:
				maxi = max(maxi, n - i - 1)
				break
		for i in range(n - 1, -1, -1):
			if A[i] % x != 0:
				maxi = max(maxi, i)
				break
		print(maxi)


import sys
t = int(sys.stdin.readline())
while t:
	(n, x) = map(int, sys.stdin.readline().strip().split())
	arr = list(map(int, sys.stdin.readline().strip().split()))
	l = -1
	for i in range(n):
		if arr[i] % x:
			if l == -1:
				l = i
			r = i
	if sum(arr) % x:
		print(n)
	elif l == -1:
		print(-1)
	else:
		print(n - min(l + 1, n - r))
	t -= 1


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

def solve():
	(n, x) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	l_total = sum(arr)
	r_total = sum(arr)
	if l_total % x != 0:
		print(n)
		return
	l_index = n - 1
	highest = -1
	while l_index >= 0:
		if l_total % x != 0:
			highest = l_index + 1
			break
		l_total -= arr[l_index]
		l_index -= 1
	r_index = 0
	r_total = sum(arr)
	while r_index < n:
		if r_total % x != 0:
			highest = max(highest, n - r_index)
			break
		r_total -= arr[r_index]
		r_index += 1
	print(highest)
main()


def I():
	return list(map(int, input().split()))
for __ in range(int(input())):
	n = int(input())
	print(len(set(I())))


def solve(arr):
	return len(set(arr))
testcases = int(input())
for i in range(testcases):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(arr))


def solve(elems):
	return len(set(elems))
t = int(input())
for i in range(t):
	l = int(input())
	elems = map(int, input().split(' '))
	print(solve(elems))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	if sum(a) % x != 0:
		print(n)
	else:
		c = 0
		for i in range(n):
			if a[i] % x != 0:
				c += 1
				if c == 1:
					imin = i
				imax = i
		if c == 0:
			print(-1)
		elif imax == imin:
			print(1)
		elif imin <= n - 1 - imax:
			print(n - imin - 1)
		else:
			print(n - (n - 1 - imax) - 1)


t = int(input())
for aq in range(t):
	x = int(input())
	k = list(map(int, input().split()))
	l = set()
	for ab in k:
		l.add(ab)
	print(len(l))


import os
os_input = os.read(0, int(10000000.0)).split()
os_input_pos = -1
answer_list = []

def read_s():
	global os_input_pos
	os_input_pos += 1
	return os_input[os_input_pos].decode()

def read_i():
	return int(read_s())

def write_s(v):
	answer_list.append(v)

def write_i(v):
	write_s(str(v))

def print_ans():
	os.write(1, '\n'.join(answer_list).encode())
T = read_i()
while T:
	T -= 1
	n = read_i()
	x = read_i()
	a = [read_i() for i in range(n)]
	cur = sum(a)
	if cur % x:
		write_i(n)
		continue
	left = 0
	for v in a:
		left += 1
		if v % x:
			break
	right = 0
	for v in reversed(a):
		right += 1
		if v % x:
			break
	n -= min(left, right)
	write_i(n if n else -1)
print_ans()


t = int(input())
for i in range(t):
	(n, s, m) = (int(input()), input().split(), set())
	for i in s:
		m.add(i)
	print(len(m))


from array import *
t = int(input())
while t > 0:
	t = t - 1
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	a = array('i', (int(i) for i in input().split()))
	l = -1
	s = 0
	for i in range(0, n):
		if a[i] % x != 0:
			if l == -1:
				l = i
			r = i
		s = s + a[i]
	if s % x != 0:
		print(n)
	elif l == -1:
		print(-1)
	else:
		print(n - min(l + 1, n - r))


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(n, x, a):
	if sum(a) % x != 0:
		return n
	not_div = [0 for _ in range(n)]
	for i in range(n):
		if a[i] % x != 0:
			not_div[i] = 1
	if 1 in not_div:
		return n - min(not_div.index(1), not_div[::-1].index(1)) - 1
	return -1
t = read_int()
for case in range(t):
	(n, x) = read_ints()
	a = read_ints()
	sol = solve(n, x, a)
	print(sol)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 1
	l1 = list(set(l))
	val = min(l)
	for i in range(len(l1)):
		if val < l1[i]:
			c += 1
	print(c)


import sys
from math import *
from collections import defaultdict
from queue import deque
from heapq import heappush, heappop
lines = [line.strip() for line in sys.stdin.readlines()]
t = int(lines[0])
for tt in range(t):
	n = int(lines[1 + tt * 2])
	xs = list(map(int, lines[2 + tt * 2].split()))
	print(len(set(xs)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = []
	if sum(a) % k != 0:
		print(n)
	else:
		m = n + 1
		for i in range(n):
			if a[i] % k != 0:
				m = min(m, i + 1)
		for i in range(n):
			if a[-i - 1] % k != 0:
				m = min(m, i + 1)
		print(n - m)


def calc(a):
	return len(set(a))
N = int(input())
cases = []
for _ in range(N):
	_ = input()
	cases.append(list(map(int, input().split())))
for c in cases:
	print(calc(c))


from itertools import accumulate

def solve(n, x, a):
	b = list(map(lambda v: v % x, accumulate(a)))
	c = list(map(lambda v: v % x, accumulate(reversed(list(a)))))
	for i in reversed(range(n)):
		if b[i] != 0 or c[i] != 0:
			return i + 1
	return -1
tc = int(input())
while tc > 0:
	(n, x) = map(int, input().split())
	print(solve(n, x, list(map(int, input().split()))))
	tc -= 1


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(s) for s in input().split()]
	summ = 0
	first_index = -1
	last_index = -1
	for j in range(len(a)):
		summ += a[j]
		if a[j] % x != 0:
			last_index = j
			if first_index == -1:
				first_index = j
	if summ % x == 0:
		if first_index == -1:
			print(-1)
		else:
			print(max(n - first_index - 1, last_index))
	else:
		print(n)


import sys
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	(n, x) = map(int, I().split())
	arr = list(map(int, I().split()))
	total = sum(arr)
	f_total = total
	f = n
	for i in arr:
		if f_total % x == 0:
			f_total -= i
			f -= 1
		else:
			break
	b_total = total
	b = n
	for i in arr[::-1]:
		if b_total % x == 0:
			b_total -= i
			b -= 1
		else:
			break
	x = max(f, b)
	if x == 0:
		ans += '-1\n'
	else:
		ans += str(x) + '\n'
print(ans)


def b(numbers):
	unique = set(numbers)
	print(len(unique))

def main():
	tests = int(input())
	while tests:
		n = int(input())
		numbers = list(map(int, input().split(' ')))
		b(numbers)
		tests -= 1
main()


for t in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	sum1 = 0
	b = []
	for i in range(n):
		sum1 += a[i]
		if a[i] % x != 0:
			b.append(i)
	if sum1 % x != 0:
		print(n)
	elif len(b) == 0:
		print(-1)
	else:
		print(max(n - b[0] - 1, b[-1]))


for _ in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if sum(arr) % x != 0:
		print(len(arr))
	else:
		ans = -1
		for i in range(len(arr)):
			if arr[i] % x != 0 or arr[len(arr) - i - 1] % x != 0:
				ans = len(arr) - i - 1
				break
		print(ans)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
from bisect import bisect_left as bl
from bisect import bisect_right as br

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def modpow(b, p, m):
	res = 1
	b = b % m
	while p:
		if p & 1:
			res = res * b % m
		b = b * b % m
		p >>= 1
	return res

def mod_inv(a, m):
	return modpow(a, m - 2, m)

def ncr(n, r, m):
	res = 1
	if r == 0:
		return 1
	if n - r < r:
		r = n - r
	(p, k) = (1, 1)
	while r:
		res = res % m * (n % m * mod_inv(r, m) % m) % m
		n -= 1
		r -= 1
	return res

def ncrlis(n, r, m, fact):
	return fact[n] * (mod_inv(fact[r], m) * mod_inv(fact[n - r], m)) % m % m

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
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')
for _ in range(ii()):
	n = ii()
	a = li()
	s = set(a)
	print(len(s))


def solution():
	from sys import stdout, stdin
	(_input, _print) = (stdin.readline, stdout.write)
	(_list, _range, _str, _len, _int) = (list, range, str, len, int)
	for _ in _range(_int(_input())):
		n = _int(_input())
		arr = set([_int(i) for i in _input().split()])
		print(len(arr))
solution()


n = int(input())
for _ in range(n):
	a = int(input())
	res = list(map(int, input().split()))
	res = set(res)
	ans = len(res)
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, x) = input().split()
	(n, x) = (int(n), int(x))
	a = [int(x) for x in input().split()]
	sm = sum(a)
	i = 0
	(sm1, sm2) = (sm, sm)
	ok = 1
	while i < len(a) / 2:
		if sm1 % x != 0:
			print(len(a) - i)
			ok = 0
			break
		elif sm2 % x != 0:
			print(len(a) - i)
			ok = 0
			break
		sm1 -= a[i]
		sm2 -= a[-i - 1]
		i += 1
	if ok:
		print(-1)


for _ in range(int(input())):
	(n, x) = [int(i) for i in input().split()]
	a = [int(i) % x for i in input().split()]
	if sum(a) % x:
		print(n)
		continue
	if sum(a) == 0:
		print(-1)
		continue
	f = 0
	while a[f] == 0:
		f += 1
	l = n - 1
	while a[l] == 0:
		l -= 1
	bad = min(f + 1, n - l)
	print(n - bad)


list = []
x = int(input())
for a in range(0, x):
	y = int(input())
	list = map(int, input().split())
	b = set(list)
	print(len(b))


t = int(input())
for case in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	print(len(s))


t = int(input())
while t:
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	sm = sum(arr)
	mx = -1
	if sm % m:
		print(n)
	else:
		for i in range(n):
			if arr[i] % m:
				mx = max(mx, n - i - 1, i)
		print(mx)
	t -= 1


import sys
I = sys.stdin.readline
for _ in range(int(I())):
	n = int(I())
	arr = list(map(int, I().split()))
	arr.sort()
	a = set()
	for i in arr:
		a.add(i)
	print(len(a))


for q in range(int(input())):
	n = input() * 2
	a = list(map(int, input().split()))
	print(len(set(a)))


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

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

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

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

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

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

def bo(i):
	return ord(i) - ord('a')
from copy import *
from bisect import *
from itertools import permutations
t = fi()
while t > 0:
	t -= 1
	(n, k) = mi()
	a = li()
	maxi = -1
	for i in range(n):
		a[i] %= k
	d = [[-2, -2] for i in range(k + 1)]
	c = 0
	d[0][0] = -1
	for i in range(n):
		c += a[i]
		c %= k
		if d[c][0] == -2:
			d[c][0] = i
		d[c][1] = i
	high = []
	for i in range(k + 1):
		if d[i][1] != -1:
			high.append(d[i][1])
	high.sort()
	for i in range(k + 1):
		if d[i][0] != -2:
			if len(high) > 0 and high[-1] == d[i][1]:
				if len(high) >= 2:
					maxi = max(maxi, max(0, high[-2] - d[i][0]))
			elif len(high) > 0 and high[-1] != d[i][1]:
				maxi = max(maxi, max(0, high[-1] - d[i][0]))
	print(maxi if maxi > 0 else -1)


T = int(input())
while T > 0:
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	temp = 0
	res = 0
	for i in range(n):
		temp += arr[i]
		if temp % x != 0:
			res = max(res, i + 1)
	for i in range(n):
		temp -= arr[i]
		if temp % x != 0:
			res = max(res, n - i - 1)
	if res == 0:
		res = -1
	print(res)
	T -= 1


T = int(input())
for T in range(T):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	total = sum(arr)
	if total % x != 0:
		print(len(arr))
		continue
	left = 0
	right = 0
	for i in range(n):
		if arr[i] % x == 0:
			left += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if arr[i] % x == 0:
			right += 1
		else:
			break
	if left + right >= n - 1:
		print(-1)
		continue
	print(len(arr) - min(left, right) - 1)


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


for q in range(int(input())):
	s = int(input())
	a = list(map(int, input().split()))
	a = set(list(a))
	print(len(a))


t = int(input())
for i in range(t):
	n = int(input())
	n1 = [int(i) for i in input().split()]
	n1 = set(n1)
	print(len(n1))


def possible(l):
	return len(list(set(l)))
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(possible(l))


import sys
import math
from collections import defaultdict as dd
mod = 1000000007
T = 1
T = int(sys.stdin.readline())
for _ in range(T):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	flg = 1
	for i in l:
		if i % x:
			flg = 0
			break
	if flg:
		print(-1)
	else:
		if sum(l) % x:
			print(n)
			continue
		(p1, p2) = (-1, n)
		for i in range(n):
			if l[i] % x:
				p1 = i
				break
		for i in range(n - 1, -1, -1):
			if l[i] % x:
				p2 = i
				break
		print(max(p2, n - p1 - 1))


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


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

def iin():
	return int(input())

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

def main():
	import heapq as hq
	t = iin()
	while t:
		t -= 1
		(n, x) = lin()
		a = lin()
		ans = -1
		for i in a:
			if i % x != 0:
				ans = 1
				break
		else:
			print(ans)
			continue
		sm = 0
		a1 = [[] for i in range(x)]
		for i in range(n):
			sm += a[i]
			if sm % x != 0:
				ans = i + 1
			a1[sm % x].append(i)
		for arr in a1:
			l = len(arr)
			ch = n - 1
			for i in range(l - 1, -1, -1):
				if ch == arr[i]:
					ch -= 1
				else:
					break
			for i in arr:
				ans = max(ans, ch - i)
		print(ans)
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')
if pypy:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
if profile:
	import cProfile
	cProfile.run('main()')
else:
	main()


from sys import stdin
from bisect import bisect_left, bisect_right, insort
from math import sqrt, ceil, floor, factorial, gcd
t = int(stdin.readline())
while t:
	t -= 1
	n = int(stdin.readline())
	a = [int(e) for e in input().split()]
	a.sort()
	i = 1
	while i < n:
		if a[i] == a[i - 1]:
			i += 1
		else:
			break
	print(1 + len(set(a[i:])))


for i in range(int(input())):
	n = int(input())
	ar = sorted(list(map(int, input().split(' '))))
	count = 1
	for j in range(1, n):
		if ar[j] == ar[j - 1]:
			continue
		else:
			count += 1
	print(count)


T = int(input())
for cs in range(T):
	n = int(input())
	st = set()
	for x in input().split():
		st.add(x)
	print(len(st))


for _ in range(int(input())):
	a = int(input())
	m = set(list(map(int, input().split())))
	print(len(m))


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	s = set()
	for i in range(n):
		s.add(arr[i])
	print(len(s))
	t -= 1


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(d) for d in input().split()]
	c = 0
	s = 0
	for el in a:
		if el % x != 0:
			c += 1
		s += el
	if c == 0:
		print(-1)
	elif 0 < c <= n:
		if s % x == 0:
			for i in range(n):
				if a[i] % x != 0 or a[-(i + 1)] % x != 0:
					print(n - (i + 1))
					break
		elif s % x != 0:
			print(n)


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

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

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 graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

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

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def solve():
	(n, x) = sep()
	a = lis()
	pre = []
	for i in range(0, n):
		if i == 0:
			pre.append(a[i])
		else:
			pre.append(a[i] + pre[i - 1])
	modarr = []
	for i in range(0, n):
		modarr.append(pre[i] % x)
	ans = 0
	help = -1
	for i in range(0, n):
		if modarr[i] != 0:
			help = i
			break
	if help == -1:
		print(-1)
		return
	for i in range(0, n):
		if modarr[i] != 0:
			ans = max(ans, i + 1)
		elif i > help:
			ans = max(ans, i - help)
	print(ans)
testcase(int(inp()))


from collections import *
from math import *
t = int(input())
for y in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = sum(a)
	if s % x != 0:
		print(n)
		continue
	s = -1
	for i in range(n):
		if a[i] % x != 0:
			s = i + 1
			break
	if s == -1:
		print(-1)
		continue
	e = -1
	for i in range(n - 1, -1, -1):
		if a[i] % x != 0:
			e = n - i
			break
	print(n - min(s, e))


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	a = list(map(int, stdin.readline().strip().split()))
	if n == 1:
		stdout.write('1' + '\n')
	else:
		stdout.write(str(len(set(a))) + '\n')


t = int(input())
for ti in range(t):
	n = int(input())
	li = [int(i) for i in input().split(' ')]
	li.sort()
	d = set()
	for i in li:
		if i not in d:
			d.add(i)
	print(len(d))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	s = list(map(int, input().split()))
	total_sum = sum(s)
	total_div = 0
	for i in s:
		if i % x == 0:
			total_div += 1
	if total_div == n:
		print(-1)
	elif total_sum % x != 0:
		print(n)
	else:
		ans = 0
		temp = total_sum
		for i in range(n):
			temp -= s[i]
			if temp % x:
				ans = n - i - 1
				break
		temp = total_sum
		for i in range(n - 1, -1, -1):
			temp -= s[i]
			if temp % x:
				ans = max(ans, i)
				break
		print(ans)


def inp():
	return map(int, input().split())
for _ in range(int(input())):
	(n, x) = inp()
	a = list(inp())
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		i1 = -1
		i2 = -1
		for i in range(n):
			if a[i] % x != 0:
				if i1 == -1:
					i1 = i
				i2 = i
		if i1 == -1:
			print(-1)
		elif i2 == -1:
			print(max(i1 + 1, n - i1))
		else:
			print(max(i1 + 1, n - i1 - 1, i2, n - i2))


import sys
import math
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = [int(_) for _ in input().split()]
	total = 0
	ans = -1
	for i in range(n):
		total += a[i]
		if total % x != 0:
			ans = max(ans, i + 1)
	total = 0
	for i in range(n - 1, -1, -1):
		total += a[i]
		if total % x != 0:
			ans = max(ans, n - i)
	print(ans)


import sys
from collections import defaultdict
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().strip().split()))
	d = defaultdict(int)
	for i in a:
		d[i] += 1
	op = 0
	for x in d:
		op += 1
	print(op)


import math

def mergeSort(lst):
	if len(lst) <= 1:
		return lst
	mid = math.floor(len(lst) / 2)
	left = mergeSort(lst[0:mid])
	right = mergeSort(lst[mid:])
	return merge(left, right)

def merge(arr1, arr2):
	i = 0
	j = 0
	lst = []
	while i < len(arr1) and j < len(arr2):
		if arr1[i] < arr2[j]:
			lst.append(arr1[i])
			i += 1
		else:
			lst.append(arr2[j])
			j += 1
	while i < len(arr1):
		lst.append(arr1[i])
		i += 1
	while j < len(arr2):
		lst.append(arr2[j])
		j += 1
	return lst
testCase = int(input())
test = 0
while test < testCase:
	num1 = int(input())
	lst = list(map(int, input().split()))
	count = 0
	lst = mergeSort(lst)
	i = 0
	lst = set(lst)
	print(len(lst))
	test += 1


t = int(input())
for case in range(t):
	(n, x) = map(int, input().split())
	a = [int(w) for w in input().split()]
	k = sum(a)
	s = 0
	if k % x == 0:
		for i in range(n):
			if a[i] % x != 0:
				s = n - 1 - i
				break
		else:
			print(-1)
			continue
		for i in reversed(range(n)):
			if a[i] % x != 0:
				s = max(s, i)
		print(s)
	else:
		print(n)


import sys
input = sys.stdin.buffer.readline

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

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
for __ in range(int(input())):
	(n, x) = I()
	arr = I()
	f = 0
	for i in range(n):
		if arr[i] % x != 0:
			f = 1
			break
	if not f:
		print(-1)
	else:
		s = sum(arr)
		if s % x:
			print(n)
		else:
			c1 = 0
			for i in reversed(range(n)):
				c1 += 1
				if arr[i] % x:
					break
			c2 = 0
			for i in range(n):
				c2 += 1
				if arr[i] % x:
					break
			print(n - min(c1, c2))


x = int(input())
for i in range(x):
	(a, b) = map(int, input().split(' '))
	l1 = list(map(int, input().split(' ')))
	s = sum(l1)
	if s % b == 0:
		i = 0
		j = -1
		ans = -1
		while i < a and -j <= a:
			if l1[i] % b != 0:
				ans = max(ans, a - i - 1)
				break
			if l1[j] % b != 0:
				ans = max(ans, a + j)
				break
			i += 1
			j -= 1
		print(ans)
	else:
		print(a)


from math import inf as inf
from math import *
from collections import *
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	pre = [0]
	suf = [0]
	for i in range(n):
		pre.append(pre[-1] + a[i])
	for i in range(n):
		suf.append(suf[-1] + a[n - i - 1])
	suf = suf[::-1]
	flag = 0
	(x1, x2) = (0, 0)
	for i in range(len(pre)):
		if pre[len(pre) - i - 1] % x:
			flag = 1
			x1 = len(pre) - i
			break
	for i in range(len(suf)):
		if suf[i] % x:
			flag = 1
			x2 = len(suf) - i
			break
	if flag == 0:
		print(-1)
	else:
		print(max(x1 - 1, x2 - 1))


a = int(input())
for _ in range(a):
	kk = int(input())
	ll = list(map(int, input().split()))
	mm = set(ll)
	print(len(mm))


tc = int(input())
while tc != 0:
	n = int(input())
	a = list(map(int, input().strip().split()))[:n]
	a = list(set(a))
	print(len(a))
	tc -= 1


production = True
import sys, math

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print(*args)

def solve():
	(n, x) = input(1)
	a = input(1)
	f = sum(a)
	if f % x != 0:
		out(n)
	else:
		s = -1
		for i in range(0, n):
			if a[i] % x != 0:
				s = i
				break
		y = -1
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				y = i
				break
		if s == -1:
			out(-1)
		else:
			out(n - min(s + 1, n - y))
	return
for i in range(input(11)):
	solve()


from sys import stdin
import math
t = int(input())
for _ in range(t):
	(n, x) = list(map(int, stdin.readline().rstrip().split(' ')))
	arr = list(map(int, stdin.readline().rstrip().split(' ')))
	s = sum(arr)
	if s % x != 0:
		print(n)
	else:
		idxF = None
		idxB = None
		for i in range(n):
			if arr[i] % x != 0:
				idxF = i
				break
		for i in range(n - 1, -1, -1):
			if arr[i] % x != 0:
				idxB = i
				break
		if idxF is None:
			print(-1)
		else:
			print(max(n - idxF - 1, idxB))


n = int(input())
for i in range(n):
	a = int(input())
	b = set(list(map(int, input().split())))
	if a > len(b):
		print(len(b))
	else:
		print(a)


import math
t = int(input())
for case in range(t):
	n = int(input())
	data = input().split()
	values = set()
	for i in data:
		values.add(int(i))
	print(len(values))


for i in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	nums = {}
	for j in range(n):
		nums[s[j]] = 1
	print(len(nums.keys()))


import sys
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input

def f(a):
	o = a[0]
	all = a[1]
	z = all - o
	return min(o, z)
for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(lambda t: int(t) % x, input().split()))
	if sum(a) % x == 0:
		if max(a) == 0:
			print(-1)
		else:
			ansl = n - 1
			i = 0
			while a[i] == 0:
				ansl -= 1
				i += 1
			ansr = n - 1
			i = 0
			a.reverse()
			while a[i] == 0:
				ansr -= 1
				i += 1
			print(max(ansl, ansr))
	else:
		print(n)


try:
	from sys import stdin, stdout
	import math
	import numbers
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		a = list(set(map(int, stdin.readline().split())))
		print(len(a))
except:
	pass


for i in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	s = sum(arr)
	if s % x == 0:
		ind = -1
		for i in range(n):
			if arr[i] % x != 0 or arr[-i - 1] % x != 0:
				ind = i
				break
		print(n - ind - 1 if ind != -1 else -1)
	else:
		print(n)


n = int(input())
final_res = []
for _ in range(n):
	(nums_count, x) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	total_sum = sum(nums)
	if total_sum % x != 0:
		print(nums_count)
		continue
	res = -1
	for k in range(nums_count):
		if nums[k] != 0 and nums[k] % x != 0 or (nums[nums_count - 1 - k] != 0 and nums[nums_count - 1 - k] % x != 0):
			res = nums_count - k - 1
			break
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(set(a))
	if len(a) < n:
		print(len(a))
	else:
		print(n)


T = int(input())
for _ in range(T):
	(n, x) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	remainders = list(map(lambda k: k % x, a))
	if sum(remainders) == 0:
		print(-1)
	elif sum(remainders) % x != 0:
		print(n)
	else:
		i = 0
		j = n - 1
		while remainders[i] == 0:
			i += 1
		while remainders[j] == 0:
			j -= 1
		print(max(j, n - (i + 1)))


import sys
import random
input = sys.stdin.read().split('\n')
for x in range(0, int(input[0]) * 2, 2):
	array = list(dict.fromkeys(input[x + 2].split(' ')))
	print(len(array))


import math
t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	data = list(map(int, input().split()))
	div = []
	l_found = -1
	r_found = -1
	sum_ren = 0
	for j in range(n):
		div.append(data[j] % x)
		sum_ren = sum_ren + data[j] % x
	if sum_ren % x != 0:
		print(n)
	else:
		for j in range(n):
			if div[j] != 0:
				l_found = j
				break
		for j in range(n - 1, -1, -1):
			if div[j] != 0:
				r_found = j
				break
		if l_found == -1 and r_found == -1:
			print(-1)
		else:
			print(max(n - l_found - 1, r_found))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	m = sum(a)
	if m % x == 0:
		z = []
		for i in range(len(a)):
			if a[i] % x != 0:
				z.append(i)
				break
		for i in range(len(a) - 1, -1, -1):
			if a[i] % x != 0:
				z.append(i)
				break
		if len(z) == 0:
			print(-1)
		else:
			print(max(len(a) - z[0] - 1, z[1]))
	else:
		print(n)


for _ in range(int(input())):
	n = int(input())
	lst = input().split()
	set1 = set(lst)
	nn = len(set1)
	if nn <= n:
		print(nn)
	else:
		print(n)


def solve():
	(n, x) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	cval = -1
	for i in range(n):
		arr[i] = arr[i] % x
	s = sum(arr)
	if s % x != 0:
		return n
	flag = 0
	length = 0
	for i in range(n):
		if arr[i] != 0:
			flag = 1
			break
	if flag:
		length = n - i - 1
	else:
		return -1
	j = 0
	for i in range(n - 1, -1, -1):
		if arr[i] != 0:
			flag = 1
			break
		j += 1
	if flag:
		length = max(length, n - j - 1)
	else:
		return -1
	return length
t = int(input())
while t:
	print(solve())
	t -= 1


from sys import stdin, exit, setrecursionlimit
from math import ceil, log2
setrecursionlimit(10000000)
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	n = int(input())
	arr = set(mi())
	print(len(arr))


class Solution:
	n = int(input())
	for _ in range(n):
		x = int(input())
		a = [int(x) for x in input().split()]
		a = list(set(a))
		print(len(a))


t = int(input())
while t != 0:
	t = t - 1
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	dic = {}
	for i in range(0, n):
		if dic.__contains__(arr[i]) == False:
			dic[arr[i]] = 1
	print(len(dic))


t = int(input())
for test in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	start = 0
	end = n - 1
	ans = 0
	if sum(a) % x != 0:
		print(n)
	else:
		while start < n and a[start] % x == 0:
			start += 1
		ans = max(ans, n - start - 1)
		while end >= 0 and a[end] % x == 0:
			end -= 1
		ans = max(ans, end)
		if ans == 0:
			print(-1)
		else:
			print(ans)


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
import string

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
input = sys.stdin.readline
for _ in range(ii()):
	n = ii()
	print(len(set(li())))


from typing import Tuple

def solve(arr) -> Tuple[int]:
	return

def main():
	t = int(input())
	while t > 0:
		n = int(input())
		arr = set(map(int, input().split()))
		print(len(arr))
		t -= 1
main()


t = int(input())
for j in range(t):
	(n, x) = map(int, input().split())
	nums = list(map(int, input().split()))
	total = 0
	flag = False
	for num in nums:
		total += num
		if num % x != 0:
			flag = True
	offset = 0
	(l, r) = (0, n - 1)
	while l + offset < r - offset:
		if nums[l + offset] % x != 0 or nums[r - offset] % x != 0:
			break
		else:
			offset += 1
	if total % x == 0:
		if not flag:
			print('{}'.format(-1))
		else:
			print('{}'.format(n - offset - 1))
	else:
		print('{}'.format(n))


t = int(input())
for ii in range(t):
	(n, x) = map(int, input().split())
	a = [int(i) for i in input().split()]
	(prefix, suffix) = ([a[0] % x], [a[-1] % x])
	for i in range(1, n):
		prefix.append((prefix[-1] + a[i]) % x)
	for i in range(n - 2, -1, -1):
		suffix.append((suffix[-1] + a[i]) % x)
	maxa = 0
	for i in range(len(prefix)):
		if prefix[i] != 0:
			maxa = i + 1
	for i in range(len(suffix)):
		if suffix[i] != 0:
			maxa = max(maxa, i + 1)
	print(maxa if maxa != 0 else -1)


import math as ma
t = int(input())
for i in range(t):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
	else:
		s = 0
		e = []
		for i in range(n):
			s += a[i]
			e.append(s)
		e = e[::-1]
		s = 0
		f = []
		for i in range(n - 1, -1, -1):
			s += a[i]
			f.append(s)
		f = f[::-1]
		g = []
		for i in range(n):
			if e[i] % x != 0:
				g.append(n - i)
				break
		for i in range(n):
			if f[i] % x != 0:
				g.append(n - i)
				break
		if len(g) == 0:
			print(-1)
		else:
			print(max(g))


import math
t = int(input())
for cnt in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	temp = 0
	ans = -1
	sum = 0
	for i in range(2 * n):
		if i == n:
			temp = n
			if sum % x != 0:
				ans = temp
				break
		if i < n:
			sum += a[i]
			temp += 1
			if temp > ans and temp != 0 and (sum % x != 0):
				ans = temp
		else:
			sum -= a[i - n]
			temp -= 1
			if temp > ans and sum % x != 0:
				ans = temp
	print(ans)


T = int(input())

def solve(arr, x):
	s = sum(arr)
	N = len(arr)
	(a, b) = (N, N)
	for i in range(0, N):
		if arr[i] % x != 0:
			a = i + 1
			break
	for i in range(N - 1, -1, -1):
		if arr[i] % x != 0:
			b = N - i
			break
	ret = min(a, b)
	return ret
while T > 0:
	(n, x) = [int(el) for el in input().split(' ')]
	arr = [int(el) for el in input().split(' ')]
	if sum(arr) % x == 0:
		ans = solve(arr, x)
		if ans == n:
			print(-1)
		else:
			print(n - ans)
	else:
		print(n)
	T -= 1


import sys
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	n = int(sys.stdin.readline())
	a = [int(j) for j in sys.stdin.readline().split()]
	d = {}
	ctr = 0
	for g in range(n):
		if a[g] not in d:
			d[a[g]] = 1
			ctr += 1
	ans_arr.append(str(ctr))
print('\n'.join(ans_arr))


tc = int(input())
for i in range(tc):
	n = int(input())
	arr = set(map(int, input().split()))
	print(len(arr))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(len(a))
	elif len([z for z in a if z % x == 0]) == len(a):
		print(-1)
	else:
		front = 0
		back = 0
		for i in range(len(a)):
			if a[i] % x != 0:
				front += 1
				break
			front += 1
		for i in range(len(a) - 1, 0, -1):
			if a[i] % x != 0:
				back += 1
				break
			back += 1
		print(len(a) - min(front, back))


t = int(input())
for _ in range(0, t):
	n = int(input())
	aa = set([int(i) for i in input().split()])
	print(min(len(aa), n))


t = int(input())
while t != 0:
	n = input()
	lop = list(map(int, input().split()))
	lop = set(lop)
	lop = list(lop)
	y = len(lop)
	print(y)
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	input()
	print(len(set(map(int, input().split()))))


n = int(input())
list_ = []
for i in range(n):
	k = int(input())
	x = list(map(int, input().split()))
	set_ = set(x)
	len_ = len(set_)
	list_.append(len_)
for j in list_:
	print(j)


n = int(input())
for j in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	b = set(l)
	print(len(b))


t = int(input())
for _ in range(t):
	(n, x) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	s = 0
	lenl = -1
	lenR = -1
	for (i, a) in enumerate(A):
		s += a
		if s % x != 0:
			lenl = i + 1
	A.reverse()
	for (i, a) in enumerate(A):
		s += a
		if s % x != 0:
			lenR = i + 1
	print(max(lenl, lenR))


from collections import Counter
for _ in range(int(input())):
	N = int(input())
	MyDict = Counter(list(map(int, input().split())))
	print(len(MyDict))


t = int(input())
v = []
for i in range(t):
	n = int(input())
	b = set(map(int, input().split()))
	print(len(b))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

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

def isPowerOfTwo(x):
	return x and (not x & x - 1)

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)))
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, x) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	d = {}
	val = 0
	p = []
	for i in range(n):
		d[a[i] % x] = True
		val += a[i]
		if a[i] % x != 0:
			p.append(i)
	if val % x != 0:
		print(n)
	elif len(d) == 1 and 0 in d:
		print(-1)
	else:
		if len(p) > 1:
			ans = max(n - 1 - p[0], p[-1])
		else:
			ans = 1
		print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(N, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x:
		print(N)
		continue
	l = N
	r = -1
	for i in range(N):
		if a[i] % x:
			l = min(l, i)
			r = max(r, i)
	if l == N and r == -1:
		print(-1)
		continue
	print(N - min(l + 1, N - r))


t = int(input())
while t != 0:
	t -= 1
	x = int(input())
	s = {'and'}
	k = input().split(' ')
	for i in range(x):
		s.add(k[i])
	a = len(s) - 1
	print('{}\n'.format(a))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	L = list(map(int, input().split()))
	val = sum(L)
	if val % m != 0:
		print(n)
		continue
	pos2 = -1
	pos1 = -1
	for i in range(n):
		if (val - L[i]) % m != 0:
			pos1 = n - i - 1
			break
	for i in range(n - 1, -1, -1):
		if (val - L[i]) % m != 0:
			pos2 = i
			break
	if pos1 == -1 or pos2 == -1:
		print(-1)
		continue
	print(max(pos1, pos2))


import sys
import os
input = sys.stdin.buffer.readline
t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = -1
	s = sum(arr)
	if s % x != 0:
		ans = n
	else:
		pos = -1
		for i in range(n):
			if arr[i] % x != 0:
				pos = i
				ans = n - (i + 1)
				break
			if arr[n - 1 - i] % x != 0:
				ans = n - (i + 1)
				pos = i
				break
	brr = list(filter(lambda y: y % x != 0, arr))
	if len(brr) == 0:
		print('-1')
	else:
		print(ans)


def find_max_subarr(arr, x, max_sum):
	if max_sum % x:
		return len(arr)
	for i in range(len(a) // 2):
		if (max_sum - arr[i]) % x or (max_sum - arr[len(arr) - 1 - i]) % x:
			return len(arr) - i - 1
	return -1
t = int(input())
for i in range(t):
	(n, x) = [int(e) for e in input().split()]
	a = [int(e) for e in input().split()]
	max_sum = sum(a)
	res = find_max_subarr(a, x, max_sum)
	print(res)


import sys
input = sys.stdin.readline
for T in range(int(input())):
	(n, x) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	s = sum(arr)
	res = False
	if s % x != 0:
		print(n)
		continue
	else:
		ans = 0
		l = r = 0
		for i in range(n // 2):
			l += arr[i]
			r += arr[n - 1 - i]
			if arr[i] % x != 0:
				ans = max(ans, 1)
			if arr[n - 1 - i] % x != 0:
				ans = max(ans, 1)
			if (s - l) % x != 0:
				ans = max(ans, n - 1 - i)
			if (s - r) % x != 0:
				ans = max(ans, n - 1 - i)
			if (s - l - r) % x != 0:
				ans = max(ans, n - i - 2)
		if ans == 0:
			print(-1)
		else:
			print(ans)


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
mod = 1000000007
for _ in range(vary(1)):
	n = vary(1)
	num = array_int()
	tt = min(num)
	s = set(num)
	s.remove(tt)
	print(len(s) + 1)


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ss = sum(a)
	se = sum(a)
	if ss % x != 0:
		print(n)
	else:
		ct = 0
		i = 0
		j = n - 1
		for i in range(n):
			ss = ss - a[i]
			se = se - a[j - i]
			if ss % x != 0 or se % x != 0:
				if n - i - 1 > ct:
					ct = n - i - 1
		if ct == 0:
			print('-1')
		else:
			print(ct)


T = int(input())
for i in range(T):
	count = 0
	final_list = []
	x = int(input())
	arr1 = list(map(int, input().split()))
	final_list = set(arr1)
	print(len(final_list))


T = int(input())
for _ in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	Dict = {}
	for i in arr:
		Dict[i] = 1
	print(len(Dict))


import sys
input = lambda : sys.stdin.readline().split('\n')[0]
t = int(input())
while t > 0:
	t -= 1
	(n, x) = list(map(int, input().split(' ')))
	l = list(map(int, input().split(' ')))
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		cnt = n + 1
		for (i, v) in enumerate(l):
			if v % x != 0:
				cnt = min(cnt, i)
		for (i, v) in enumerate(reversed(l)):
			if v % x != 0:
				cnt = min(cnt, i)
		if cnt == n + 1:
			print(-1)
		else:
			print(n - cnt - 1)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	p = 0
	a = -1
	b = -1
	c = -1
	for i in range(n):
		p += A[i]
		if p % x != 0:
			a = i + 1
	for i in range(n):
		if A[i] % x != 0:
			b = max(i + 1, n - i - 1)
			break
	for i in range(n - 1, -1, -1):
		if A[i] % x != 0:
			c = max(n - i, i)
			break
	print(max(a, max(b, c)))


import math

def solve():
	(n, x) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(len(l))
		return
	idx1 = -1
	idx2 = -1
	for i in range(len(l)):
		if l[i] % x != 0:
			idx1 = i
			break
	for i in range(len(l) - 1, -1, -1):
		if l[i] % x != 0:
			idx2 = i
			break
	if idx1 == -1:
		print(-1)
		return
	print(max(len(l) - idx1 - 1, idx2))
t = 1
t = int(input())
while t > 0:
	t -= 1
	solve()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
lst = []
for i in range(t):
	(n, x) = I()
	lst = I()
	if sum(lst) % x != 0:
		print(n)
	else:
		sum1 = 0
		pos = 0
		maxi = -1
		count = 0
		for i in range(n - 1, 0, -1):
			sum1 = sum1 + lst[i]
			count = count + 1
			if sum1 % x != 0:
				pos = count
				if pos > maxi:
					maxi = pos
		sum1 = 0
		for i in range(n):
			sum1 = sum1 + lst[i]
			if sum1 % x != 0:
				pos = i + 1
				if pos > maxi:
					maxi = pos
		if maxi == 0:
			print(-1)
		else:
			print(maxi)


def CeilIndex(A, l, r, key):
	while r - l > 1:
		m = l + (r - l) // 2
		if A[m] >= key:
			r = m
		else:
			l = m
	return r

def LongestIncreasingSubsequenceLength(A, size):
	tailTable = [0 for i in range(size + 1)]
	len = 0
	tailTable[0] = A[0]
	len = 1
	for i in range(1, size):
		if A[i] < tailTable[0]:
			tailTable[0] = A[i]
		elif A[i] > tailTable[len - 1]:
			tailTable[len] = A[i]
			len += 1
		else:
			tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]
	return len

def countDistinct(arr, n):
	arr.sort()
	res = 0
	i = 0
	while i < n:
		while i < n - 1 and arr[i] == arr[i + 1]:
			i += 1
		res += 1
		i += 1
	return res
for _ in range(int(input())):
	n = int(input())
	arr = [int(s) for s in input().split()]
	x = LongestIncreasingSubsequenceLength(arr, len(arr))
	c = countDistinct(arr, len(arr))
	print(max(x, c))


import sys
import os

def f(n, a):
	dic = {}
	total = 0
	for i in a:
		if i not in dic:
			total += 1
			dic[i] = 1
	return total
t = int(input())
fptr = sys.stdout
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	fptr.write(str(f(n, a)))
	fptr.write('\n')
fptr.close()


T = int(input())
for _ in range(0, T):
	(n, x) = map(int, input().split())
	A = list(map(int, input().split()))
	c1 = -1
	c2 = 0
	s = sum(A)
	for i in range(0, n):
		if A[i] % x != 0:
			if c1 == -1:
				c1 = i
			c2 = i
	if s % x != 0:
		print(n)
	elif c1 == -1:
		print(-1)
	else:
		k = min(c1 + 1, n - c2)
		print(n - k)


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ar1 = list(dict.fromkeys(arr))
	print(len(ar1))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().strip().split()))[:n]
	l.sort()
	c = 1
	for j in range(n - 1):
		if l[j] != l[j + 1]:
			c = c + 1
	print(c)


def ans(A, x):
	if sum(A) % x != 0:
		return len(A)
	for i in range(len(A)):
		if A[i] % x != 0:
			break
		if A[len(A) - i - 1] % x != 0:
			break
	if len(A) - i - 1 == 0:
		return -1
	return len(A) - i - 1
T = int(input())
for t in range(T):
	(n, x) = input().split(' ')
	x = int(x)
	A = input().split(' ')
	A = [int(x) for x in A]
	print(ans(A, x))


def first_x(ar, x):
	for (i, n) in enumerate(ar):
		if n % x != 0:
			return i
	return -1
t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	ar = list(map(int, input().split()))
	sum_all = sum(ar)
	if sum_all % x != 0:
		print(len(ar))
	else:
		lx = first_x(ar, x)
		rx = first_x(ar[::-1], x)
		if lx == -1 and rx == -1 or all((i % x == 0 for i in ar)):
			print(-1)
		else:
			min_del = min(lx, rx)
			rest = len(ar) - min_del - 1
			print(rest)


def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	arr = set(arr)
	print(len(arr))
t = int(input())
for _ in range(t):
	solve()


from sys import stdin, stdout
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()
import math
from collections import Counter

def solve():
	(n, x) = MAP()
	a = LI()
	s = sum(a)
	p = s
	m = 0
	if s % x != 0:
		m = n
	for i in range(n - 1):
		s -= a[i]
		if s % x != 0:
			m = max(m, n - i - 1)
	for i in range(n - 1, -1, -1):
		p -= a[i]
		if p % x != 0:
			m = max(m, i)
	if m == 0:
		print(-1)
	else:
		print(m)
for i in range(IN()):
	solve()


for t in range(int(input())):
	n = list(map(int, input().split()))
	q = n[0]
	x = n[1]
	boo = False
	a = list(map(int, input().split()))
	if sum(a) % x == 0:
		for i in range(q):
			if a[i] % x != 0:
				z = i
				boo = True
				break
		for j in range(q):
			if a[q - j - 1] % x != 0:
				h = q - j - 1
				boo = True
				break
		if not boo:
			print('-1')
		else:
			x = max(q - z - 1, h)
			print(x)
	else:
		print(q)


t = int(input())
while t > 0:
	n = int(input())
	s = set([int(i) for i in input().split()])
	print(len(s))
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	lower = upper = 0
	while lower < n and a[lower] % k == 0:
		lower += 1
	while upper < n and a[n - upper - 1] % k == 0:
		upper += 1
	if s % k != 0:
		print(n)
	else:
		print(n - 1 - min(lower, upper))


from collections import defaultdict, Counter
from itertools import permutations
from os import system
from sys import stdin, stdout
import queue
import math
from time import time
for _ in range(int(input())):
	n = input()
	arr = set(map(int, input().split()))
	print(len(arr))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = [int(i) % x for i in input().split()]
	s = sum(a)
	if s == 0:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		ans = 0
		for i in range(n):
			if a[i] != 0:
				ans = max(i, ans, n - i - 1)
		a = a[::-1]
		for j in range(n):
			if a[j] != 0:
				ans = max(j, ans, n - j - 1)
		print(ans)


for t in range(int(input())):
	(n, li) = (int(input()), set(sorted([int(x) for x in input().split()])))
	print(len(li))


t = int(input())
for i in range(0, t):
	n = int(input())
	lst = list((int(num) for num in input().split()))[:n]
	lst = set(lst)
	print(len(lst))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	ar = list(map(int, input().split()))
	s = sum(ar)
	if s % x != 0:
		print(n)
	else:
		ans1 = 0
		su = 0
		for i in range(n):
			su += ar[i]
			if (s - su) % x != 0:
				ans1 = n - i - 1
				break
		(ans2, su) = (0, 0)
		for i in range(n - 1, -1, -1):
			su += ar[i]
			if (s - su) % x != 0:
				ans2 = i
				break
		ans = max(ans1, ans2)
		if ans:
			print(ans)
		else:
			print(-1)


import sys, os, io
I = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for tc in range(1, 1 + int(I())):
	(n, x) = map(int, I().split())
	a = list(map(int, I().split()))
	if sum(a) % x > 0:
		print(n)
	else:
		ans = -1
		for i in range(n):
			if a[i] % x > 0:
				ans = max([ans, i, n - i - 1])
		print(ans)


t = int(input())
result = []
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = set(arr)
	result.append(len(arr))
for x in result:
	print(x)


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

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(II()):
		II()
		aa = LI()
		print(len(set(aa)))
main()


from collections import Counter
for _ in range(int(input())):
	x = input()
	line = list(map(int, input().split()))
	print(len(Counter(line).keys()))


t = int(input())
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	lis = set(nums)
	lis = list(lis)
	print(len(lis))


t = int(input())
for i in range(0, t):
	n = int(input())
	l = [int(x) for x in input().split()]
	s1 = set(l)
	print(len(list(s1)))


from collections import Counter
tc = int(input())
while tc > 0:
	n = int(input())
	a = list(map(int, input().strip().split()))
	lth = len(Counter(a).keys())
	if lth > n + 1:
		print(n + 1)
	else:
		print(lth)
	tc = tc - 1


for i in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	pre = [a[0]]
	f = 0
	for i in range(1, n):
		pre.append(pre[-1] + a[i])
	suff = [a[n - 1]] * n
	for i in range(n - 2, -1, -1):
		suff[i] = suff[i + 1] + a[i]
	s = sum(a)
	ans = [0]
	if s % x != 0:
		print(n)
	else:
		for i in range(n):
			if (s - pre[i]) % x != 0:
				ans.append(n - i - 1)
				f = 1
		for i in range(n):
			if (s - suff[i]) % x != 0:
				ans.append(i)
				f = 1
		m = max(ans)
		if m == 0 or f == 0:
			print(-1)
		else:
			print(m)


import sys
from sys import stdin

def solve():
	t = int(input())
	for test in range(0, t):
		n = int(input())
		a = set(map(int, input().split()))
		print(len(a))

def main():
	solve()
main()


t = int(input())
for t1 in range(t):
	(n, x) = [int(n1) for n1 in input().split()]
	n2 = [int(n1) for n1 in input().split()]
	if sum(n2) % x != 0:
		print(len(n2))
	else:
		n3 = []
		for i in range(len(n2)):
			if n2[i] % x != 0:
				n3.append(i)
		if len(n3) - 1 > 0:
			if len(n2[:n3[-1]]) > len(n2[n3[0] + 1:]):
				print(len(n2[:n3[-1]]))
			else:
				print(len(n2[n3[0] + 1:]))
		else:
			print(-1)


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

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

def solve():
	_ = read_int()
	return len(set(read_ints()))
T = read_int()
for _ in range(T):
	print(solve())


import sys
t = int(input())
while t:
	t -= 1
	(n, x) = map(int, input().split())
	lis = list(map(int, input().split()))
	check = 0
	for i in range(n):
		if lis[i] % x:
			check = 1
			break
	if check:
		s = 0
		for i in range(n):
			s += lis[i]
		if s % x:
			print(n)
		else:
			(f, l) = (-1, -1)
			for i in range(n):
				if lis[i] % x:
					f = i
					break
			for i in range(n - 1, -1, -1):
				if lis[i] % x:
					l = i
					break
			if f + 1 >= n - l:
				print(l)
			else:
				print(n - f - 1)
	else:
		print(-1)


def f(A):
	INF = 10 ** 10
	F = [INF] * (len(A) + 1)
	F[0] = -INF
	for i in range(len(A)):
		left = 0
		right = len(A)
		while right - left > 1:
			middle = (left + right) // 2
			if F[middle] >= A[i]:
				right = middle
			else:
				left = middle
		F[right] = A[i]
	return F.index(10 ** 10) - 1
t = int(input())
for i in range(t):
	n = int(input())
	lit = [int(i) for i in input().split()]
	if len(set(lit)) > n:
		print(f(lit) + n - 1)
	else:
		print(len(set(lit)))


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

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

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

def solve():
	(n, x) = get_tuple()
	ls = get_list()
	total = sum(ls)
	if total % x != 0:
		return n
	else:
		ans1 = n
		total1 = total
		i = 0
		while i < n:
			total1 -= ls[i]
			ans1 -= 1
			if total1 % x != 0:
				break
			i += 1
		ans2 = n
		total2 = total
		j = n - 1
		while j >= 0:
			total2 -= ls[j]
			ans2 -= 1
			if total2 % x != 0:
				break
			j -= 1
		if ans1 or ans2:
			return max(ans1, ans2)
		return -1

def main():
	print(solve())
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


import os
import sys

def get_int():
	return int(input())

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

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

def get_float():
	return float(input())

def get_floats():
	return map(float, input().split())

def list_strs():
	return list(input().split())

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

def list_floats():
	return list(map(float, input.split()))

def post(x):
	print(x, end=' ')
j = int(input())
for t in range(1, j + 1):
	(n, x) = get_ints()
	a = list_ints()
	res = -1 if all((i % x == 0 for i in a)) else 0
	res = n if sum(a) % x != 0 else 0
	(l, r) = (-1, 0)
	if res != 0:
		print(res)
	else:
		res = -1
		for i in range(n):
			if a[i] % x != 0 and l == -1:
				l = r = i
			elif a[i] % x != 0:
				r = i
		res = max(n - l - 1, r)
		print(res if l != -1 else l)


t = int(input())
ans = ''
while t:
	n = int(input())
	a = len(set(map(int, input().split())))
	ans = ans + str(a) + '\n'
	t = t - 1
print(ans)


t = int(input())
a = []
b = []
for i in range(t):
	(n, x) = map(int, input().split())
	a.append(x)
	v = list(map(int, input().split()))
	b.append(v)
ans = []
for i in range(t):
	cnt = 0
	w = 0
	xx = sum(b[i])
	if xx % a[i] != 0:
		ans.append(len(b[i]))
	else:
		for j in range(len(b[i])):
			if b[i][j] % a[i] != 0:
				cnt = max(len(b[i]) - j - 1, j)
				w = max(cnt, w)
		ans.append(w)
for i in ans:
	if i == 0:
		print(-1)
	else:
		print(i)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	cnt = 0
	maxi = 0
	suma = sum(l[:])
	(i, j) = (0, n - 1)
	if suma % x == 0:
		ch = 0
		dec1 = 1
		dec2 = 1
		(i1, j1) = (0, n - 1)
		for i in range(n):
			if l[i] % x != 0:
				break
			else:
				dec1 += 1
		for j in range(n - 1, -1, -1):
			if l[j] % x != 0:
				break
			else:
				dec2 += 1
		dec = min(dec1, dec2)
		if n - dec > 0:
			print(n - dec)
		else:
			print(-1)
	else:
		print(n)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
		continue
	else:
		nn = -1
		s = 0
		for i in range(n):
			s = (s + a[i]) % x
			if s != 0:
				nn = max(nn, i + 1, n - i - 1)
		print(nn)


test = int(input())
for _ in range(test):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(set(a))
	print(len(b))


import random

def bubble_sort(l):
	for t in range(len(l)):
		for i in range(len(l) - 1):
			if l[i] > l[i + 1]:
				(l[i + 1], l[i]) = l[i:i + 2]
	return l
num_cases = int(input())
for i in range(num_cases):
	n = int(input())
	case = list(map(lambda x: int(x), input().split(' ')))
	prev = case.pop(0)
	count = 1
	unfound = {prev}
	for num in case:
		if num > prev:
			count += 1
			prev = num
			unfound.add(num)
		elif n > 0:
			if num not in unfound:
				unfound.add(num)
				n -= 1
				count += 1
	print(count)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if x == 1:
		print(-1)
	else:
		s = sum(a)
		if s % x != 0:
			print(n)
		else:
			mx1 = n - 1
			mx2 = n - 1
			i = 0
			while i < n and a[i] % x == 0:
				i += 1
				mx1 -= 1
			i = n - 1
			while i >= 0 and a[i] % x == 0:
				i -= 1
				mx2 -= 1
			print(max(mx1, mx2))


t = int(input())
for t1 in range(0, t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(a)
	if s % m != 0:
		print(n)
	else:
		l = -1
		r = -1
		for i in range(0, n):
			if a[i] % m != 0:
				if l == -1:
					l = i
				r = i
		if l == -1:
			print(-1)
		else:
			print(n - min(l + 1, n - r))


t = int(input())
for q in range(0, t):
	(n, x) = map(int, input().split())
	b = [0] * n
	a = [int(i) for i in input().split()]
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		flag = -1
		for i in range(0, n):
			if a[i] % x != 0:
				b[i] = 1
		flag = -1
		for i in range(0, n):
			if b[i] == 1:
				c = max(i, n - i - 1)
				flag = max(flag, c)
		print(flag)


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

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

def ai():
	return list(map(int, input().split()))
for _ in range(ii()):
	n = ii()
	lst = list(set(ai()))
	print(len(lst))


import math, collections, sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(len(set(a)))


for i in range(int(input())):
	a = int(input())
	b = set()
	for i in input().split():
		b.add(i)
	print(len(b))


t = int(input())
for i in range(t):
	(n, x) = input().split()
	a = list(map(int, input().split()))
	n = int(n)
	x = int(x)
	s = sum(a)
	if s % x != 0:
		print(n)
	else:
		an1 = 0
		an2 = 0
		for i in range(n):
			if a[i] % x != 0:
				break
		an1 = n - (i + 1)
		j = n - 1
		while j >= 0:
			if a[j] % x != 0:
				an2 = j
				break
			j -= 1
		ans = max(an2, an1)
		if ans == 0:
			print(-1)
		else:
			print(ans)


t = int(input())
while t > 0:
	t -= 1
	[n, x] = list(map(int, input().split()))
	a_list = list(map(int, input().split()))
	s = 0
	s = sum(a_list)
	if s % x != 0:
		print(len(a_list))
	else:
		flag1 = flag2 = -1
		for i in range(n):
			if a_list[i] % x != 0:
				flag1 = i + 1
				break
		for j in range(n):
			if a_list[n - j - 1] % x != 0:
				flag2 = j + 1
				break
		if flag1 == -1 or flag2 == -1:
			print('-1')
		elif flag1 > flag2:
			print(n - flag2)
		else:
			print(n - flag1)


from math import *
T = int(input())
while T:
	T -= 1
	n = input()
	a = set(list(input().split()))
	print(len(a))


t = int(input())
ans = []
for i in range(t):
	mod = []
	(n, x) = input().split()
	n = int(n)
	x = int(x)
	a = list(map(int, input().split()))
	current = 0
	totalsum = sum(a)
	for j in range(n):
		if a[j] % x == 0:
			current += 1
	if current == n:
		ans.append(-1)
		continue
	elif totalsum % x != 0:
		ans.append(n)
		continue
	else:
		total = totalsum
		mini = 0
		for k in range(n):
			total -= a[k]
			if total % x != 0:
				mini = max(mini, n - k - 1)
				break
		total = totalsum
		for l in range(-1, -n, -1):
			total -= a[l]
			if total % x != 0:
				mini = max(mini, n + l)
				break
		ans.append(mini)
for kk in ans:
	print(kk)


t = int(input())
while t != 0:
	n = int(input())
	a = list(map(int, input().split()))
	j = 1
	a.sort()
	mi = a[0]
	for i in range(1, len(a)):
		if a[i] > mi:
			j += 1
			mi = a[i]
		else:
			continue
	print(j)
	t -= 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	s = ss = sum(a)
	cntf = cntb = cntbo = n
	i = 0
	while i < n and s % x == 0:
		s -= a[i]
		cntf -= 1
		i += 1
	i = n - 1
	s = ss
	while i >= 0 and s % x == 0:
		s -= a[i]
		cntb -= 1
		i -= 1
	l = 0
	r = n - 1
	s = ss
	oe = 1
	while l < r and s % x == 0:
		if oe % 2:
			s -= a[l]
			cntbo -= 1
			l += 1
		else:
			s -= a[r]
			cntbo -= 1
			r -= 1
		oe = 1 - oe
	if cntf == 0 or cntb == 0:
		print(-1)
	else:
		print(max(cntf, cntb, cntbo))


from sys import stdin
input = stdin.readline
import math
for i in range(int(input())):
	n = int(input())
	arr = sorted(list(map(int, input().split())))
	ans = n
	for j in range(n - 1):
		if arr[j + 1] == arr[j]:
			ans -= 1
	print(ans)


t = int(input())
import math
delay = []
for _ in range(t):
	(n, x) = map(int, input().split())
	arr = input().split()
	arr = [int(a) for a in arr]
	s = sum(arr)
	if s % x != 0:
		print(n)
		continue
	else:
		start = 0
		startsum = s
		while start < n:
			if (startsum - arr[start]) % x != 0:
				break
			else:
				startsum -= arr[start]
				start += 1
		end = n - 1
		endsum = s
		while end >= 0:
			if (endsum - arr[end]) % x != 0:
				break
			else:
				endsum -= arr[end]
				end -= 1
		ans = max(n - 1 - start, end)
		if ans < 1:
			ans = -1
		print(ans)


import sys

def read():
	return int(input())

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

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

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

def main():
	cas = read()
	while cas:
		cas -= 1
		(n, x) = get_ints()
		V = get_array()
		tot = 0
		fi = -1
		se = -1
		for i in range(n):
			tot += V[i]
			if V[i] % x != 0:
				se = i
				if fi == -1:
					fi = i
		if tot % x != 0:
			print(n)
		elif fi != -1:
			print(max(n - fi - 1, se))
		else:
			print(-1)
main()


import sys
input = sys.stdin.readline

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

def inlt():
	return list(map(int, input().split()))
k = inp()
for i in range(k):
	count = 0
	n = inp()
	l = inlt()
	print(len(list(set(l))))


for _ in range(int(input())):
	a = input().split(' ')
	n = int(a[0])
	x = int(a[1])
	a = input().split(' ')
	s = 0
	for i in range(n):
		a[i] = int(a[i])
		s = s + a[i]
	ans = -1
	if s % x != 0:
		ans = n
	else:
		front = -1
		back = -1
		for i in range(n):
			if a[i] % x != 0:
				front = i
				break
		for i in range(n):
			if a[n - i - 1] % x != 0:
				back = n - i - 1
				break
		if front != -1:
			ans = max(n - front - 1, back)
		else:
			ans = -1
	print(ans)


import sys
import sys
from math import *
from collections import defaultdict as dd
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip())
from collections import defaultdict as df
import heapq
infinite = float('inf')
t = int(input().strip())
for _ in range(t):
	x = int(input().strip())
	l = set(RI())
	print(len(l))


t = int(input())
for io in range(t):
	n = int(input())
	arr = len(set(map(int, input().split())))
	print(arr)


for _ in range(int(input())):
	size = input()
	print(len(set(input().split())))


t = int(input())
while t > 0:
	t = t - 1
	(n, x) = map(int, input().split())
	a = input()
	A = list(map(int, list(a.split())))
	d = []
	s = A[0]
	ans = [-1] * n
	if s % x != 0:
		d.append(0)
		ans[0] = 1
	for i in range(1, n):
		s = s + A[i]
		if s % x == 0:
			if d != []:
				ans[i] = i - d[0]
		else:
			ans[i] = i + 1
			if d == []:
				d.append(i)
	print(max(ans))


for i in range(int(input())):
	p = int(input())
	r = list(map(int, input().split()))
	m = list(dict.fromkeys(r))
	print(len(m))


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	c1 = 1
	c2 = 1
	for i in range(n):
		if a[i] % x == 0:
			c1 += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if a[i] % x == 0:
			c2 += 1
		else:
			break
	if c1 == c2:
		if c1 > n:
			print(-1)
		elif c1 == 1:
			print(n)
		else:
			print(n - c1)
	else:
		print(n - min(c1, c2))


def solve(arr):
	print(len(arr))

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		arr = list(set(arr))
		solve(arr)
main()


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	if sum(a) % x != 0:
		print(len(a))
	else:
		sum_a = sum(a)
		num_1 = 0
		for j in range(n):
			sum_a = sum_a - a[j]
			if sum_a % x != 0:
				num_1 = n - j - 1
				break
		sum_b = sum(a)
		num_2 = 0
		for j in range(n - 1, -1, -1):
			sum_b = sum_b - a[j]
			if sum_b % x != 0:
				num_2 = j
				break
		num_max = max(num_1, num_2)
		if num_max > 0:
			print(num_max)
		else:
			print(-1)


t = int(input())
for i in range(t):
	ans = 1
	n = int(input())
	a = sorted(list(map(int, input().split())))
	b = []
	for j in range(n - 1):
		b.append(a[j + 1] - a[j])
	for k in b:
		if k > 0:
			ans += 1
	print(ans)


for t in range(int(input())):
	(n, x) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	ans = n
	if sum(arr) % x == 0 and len(list(filter(lambda a: a % x != 0, arr))) == 0:
		ans = -1
	elif sum(arr) % x == 0:
		cnt1 = 0
		cnt2 = 0
		for i in range(n // 2):
			if arr[i] % x == 0:
				cnt1 += 1
			else:
				break
		for i in range(1, n // 2 + 1):
			if arr[-i] % x == 0:
				cnt2 += 1
			else:
				break
		ans -= min(cnt1, cnt2) + 1
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	sm = sum(arr)
	if sm % x:
		print(n)
	else:
		ok = True
		for i in range(1, n + 1):
			if arr[i - 1] % x:
				ans = n - i
				ok = False
				break
		for i in range(n, 0, -1):
			if arr[i - 1] % x:
				ans = max(ans, i - 1)
				break
		print(-1 if ok else ans)


t = int(input())
answer = []
for test in range(t):
	(n, x) = list(map(int, input().split(' ')))
	liste = list(map(int, input().split(' ')))
	first = n
	end = -1
	for i in range(n):
		if liste[i] % x != 0:
			first = i + 1
			break
	for i in range(n - 1, -1, -1):
		if liste[i] % x != 0:
			end = i - 1
			break
	sum_l = sum(liste)
	if sum_l % x != 0:
		answer.append(str(n))
	else:
		m = max(n - first, end + 1)
		if m > 0:
			answer.append(str(m))
		else:
			answer.append(str(-1))
print('\n'.join(answer))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	x = list(map(int, input().split()))
	if sum(x) % k != 0:
		print(len(x))
		continue
	tot_div = 0
	for i in range(n):
		if x[i] % k == 0:
			tot_div += 1
	if tot_div == n:
		print(-1)
		continue
	total = sum(x)
	mini = -1
	for i in range(n):
		total -= x[i]
		if total % k != 0:
			mini = max(mini, n - i - 1)
	total2 = sum(x)
	for i in range(n - 1, -1, -1):
		total2 -= x[i]
		if total2 % k != 0:
			mini = max(mini, i)
	print(mini)


for t in range(int(input())):
	(n, x) = [int(_) for _ in input().split()]
	a = [int(_) for _ in input().split()]
	s = sum(a)
	(ans, tmp) = (0, 0)
	for i in range(n):
		tmp += a[i]
		if tmp % x:
			ans = max(ans, i + 1)
		if (s - ans) % x:
			ans = max(ans, n - i - 1)
	print(ans if ans != 0 else -1)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

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

	def In():
		return map(int, input().split())
else:

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

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

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_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, x) = In()
		l = list(In())
		su = sum(l)
		ans = n
		if su % x != 0:
			print(ans)
			return
		else:
			for i in range(n):
				if (su - l[i]) % x != 0:
					ans -= i + 1
					su -= l[i]
					break
				elif (su - l[n - i - 1]) % x != 0:
					ans -= i + 1
					su -= l[n - i - 1]
					break
				else:
					su -= l[i]
			if su % x == 0:
				print(-1)
			else:
				print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
results = []
for case in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	a = [i % x for i in a]
	ans = -1
	if sum(a) % x != 0:
		ans = n
	elif set(a) == {0}:
		ans = -1
	else:
		for i in range(n):
			if a[i] or a[n - 1 - i]:
				ans = n - (i + 1)
				break
	results.append(ans)
for result in results:
	print(result)


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))

def solve():
	(n, x) = M()
	a = L()
	p = sum(a)
	q = p
	m = 0
	if p % x != 0:
		m = n
	for i in range(n - 1):
		p -= a[i]
		q -= a[n - i - 1]
		if p % x != 0:
			m = max(m, n - i - 1)
		if q % x != 0:
			m = max(m, n - i - 1)
	if m:
		print(m)
	else:
		print(-1)
for i in range(I()):
	solve()


def brute(arr, x):
	result = -1
	resultArr = []
	for left in range(len(arr)):
		for right in range(left, len(arr) + 1):
			if sum(arr[left:right]) % x != 0:
				if right - left > result:
					result = right - left
					resultArr = arr[left:right]
	print(resultArr)
	return result

def soln(arr, x):
	result = 0
	left = 0
	right = len(arr) - 1
	currSum = sum(arr)
	flag = False
	while left <= right:
		if currSum % x != 0:
			result = right - left + 1
			break
		if (currSum - arr[left]) % x != 0:
			currSum -= arr[left]
			left += 1
		elif (currSum - arr[right]) % x != 0:
			currSum -= arr[right]
			right -= 1
		else:
			flag = True
			currSum -= arr[left]
			left += 1
			currSum -= arr[right]
			right -= 1
	while flag and left <= right:
		if left - 1 >= 0 and (currSum + arr[left - 1]) % x != 0:
			left -= 1
			currSum += arr[left]
		elif right + 1 < len(arr) and (currSum + arr[right + 1]) % x != 0:
			right += 1
			currSum += arr[right]
		else:
			flag = False
	result = right - left + 1
	if result == 0:
		return -1
	return result

def randomTest():
	import random
	t = 50
	for i in range(1, t + 1):
		n = random.randint(1, 100)
		arr = [random.randint(1, 10) for _ in range(n)]
		x = random.randint(1, 10)
		print(i, arr, x)
		b = brute(arr, x)
		f = soln(arr, x)
		if b != f:
			print('Broken!')
			print(b, f)
			return

def test():
	arr = [9, 5, 4, 9]
	x = 3
	b = brute(arr, x)
	f = soln(arr, x)
	print(b, f)

def main():
	t = int(input())
	for _ in range(t):
		(n, x) = [int(x) for x in input().split()]
		arr = [int(x) for x in input().split()]
		result = soln(arr, x)
		print(result)
main()


for S in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	cnt = 0
	for i in range(n - 1):
		if a[i] == a[i + 1]:
			cnt += 1
	print(n - cnt)


import bisect, collections

def solution():
	n = int(input().strip())
	a = [int(x) for x in input().strip().split(' ')]
	print(len(set(a)))

def main():
	T = int(input().strip())
	for _ in range(T):
		solution()
main()


for case in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	s = set()
	for x in arr:
		s.add(x)
	print(len(s))


import math
for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	print(len(set(list1)))


t = int(input())
while t != 0:
	n = int(input())
	arr = [int(a) for a in input().split(' ')]
	s_arr = set(arr)
	print(len(s_arr))
	t = t - 1


def unique(a):
	a_set = set(a)
	uni_list = list(a_set)
	return sorted(uni_list)

def long(a, n):
	longest = unique(a)
	return len(longest)
t = int(input())
for i in range(t):
	n = int(input())
	list1 = list(map(int, input().split()))
	print(long(list1, n))


def solve():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if all(map(lambda i: a[i] % x == 0, range(n))):
		print(-1)
		return
	s = sum(a)
	(l, r) = (n + 1, n + 1)
	for i in range(n):
		if a[i] % x != 0:
			l = min(i, l)
			r = i
	if s % x != 0:
		print(n)
		return
	print(max(n - l - 1, r))
t = int(input())
for _ in range(t):
	solve()


a = int(input())
for _ in range(a):
	(b, c) = map(int, input().split())
	e = list(map(int, input().split()))
	d = [i % c for i in e]
	if sum(d) % c != 0:
		print(b)
	else:
		l = 0
		r = b - 1
		while l < b and d[l] == 0:
			l += 1
		while r >= 0 and d[r] == 0:
			r -= 1
		if l > r:
			print(-1)
		else:
			print(max(r, b - l - 1))


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = [int(x) for x in input().split()]
	s = 0
	div = []
	nd = []
	if sum(a) % x != 0:
		ans = n
	else:
		for i in range(n):
			if a[i] % x == 0:
				div.append(i)
			else:
				nd.append(i)
		if len(div) == n:
			ans = -1
		else:
			s1 = sum(a)
			ans1 = n - nd[0] - 1
			ans2 = nd[len(nd) - 1]
			ans = max(ans1, ans2)
	print(ans)


asd = int(input())
for item in range(0, asd):
	n = int(input())
	l = list(map(int, input().split()))
	sq = set(l)
	print(len(sq))


def main_function():
	t = int(input())
	for i in range(t):
		n = int(input())
		A = set(map(int, input().split(' ')))
		print(len(A))
main_function()


t = int(input())
for i in range(t):
	n = int(input())
	numbers = list(map(int, input().split()))
	numbers.sort()
	counter = 1
	for j in range(n - 1):
		if numbers[j] != numbers[j + 1]:
			counter += 1
	print(counter)


for i in range(int(input())):
	n = int(input())
	n1 = list(map(int, input().split()))
	c = list(set(n1))
	print(len(c))


for _ in range(int(input())):
	input()
	print(len(set([int(i) for i in input().split()])))


from collections import Counter
a = int(input())
for i in range(a):
	b = int(input())
	d = 0
	c = list(map(int, input().split()))
	k = Counter(c)
	print(len(k.values()))


t = int(input())
for i in range(0, t):
	nx = input().split()
	n = int(nx[0])
	x = int(nx[1])
	L = list(map(int, input().split()))
	if all((e % x == 0 for e in L)):
		print(-1)
	else:
		s = 0
		for i in range(0, len(L)):
			s += L[i]
		if s % x != 0:
			print(len(L))
		else:
			M = []
			N = []
			s = 0
			t = 0
			for i in range(0, len(L)):
				s += L[i]
				M.append(s)
				t += L[n - 1 - i]
				N.append(t)
			for i in range(len(L) - 1, -1, -1):
				if M[i] % x != 0:
					x1 = i + 1
					break
			for i in range(len(L) - 1, -1, -1):
				if N[i] % x != 0:
					x2 = i + 1
					break
			print(max(x1, x2))


z = int(input())
for q in range(z):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0 or (sum(a) < x and sum(a) != 0):
		ans = n
	else:
		flag = 0
		for i in range(n):
			if a[i] % x != 0 or (a[i] < x and a[i] != 0):
				ans = max(i + 1, n - i - 1)
				flag = 1
				break
			if a[n - i - 1] % x != 0 or (a[n - i - 1] < x and a[n - i - 1] != 0):
				ans = max(i + 1, n - i - 1)
				flag = 1
				break
		if flag == 0:
			ans = -1
	print(ans)


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	if sum(l) % x != 0:
		print(n)
	else:
		count = n
		st = 0
		for i in l:
			if i % x == 0 or i == 0:
				count -= 1
				st += 1
			else:
				break
		count1 = n
		en = n
		for i in l[::-1]:
			if i % x == 0 or i == 0:
				count1 -= 1
				en -= 1
			else:
				break
		s = sum(l[st:en])
		if s % x != 0:
			print(max(count, count1))
		else:
			ans = max(count, count1) - 1
			if ans > 0:
				print(ans)
			else:
				print(-1)
	t -= 1


import math
q = int(input())
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(set(l)))


cases = int(input())
for t in range(cases):
	(n, x) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = 0
	f = 0
	for i in a:
		s += i
		f += i % x == 0
	if f == n:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		l = n + 1
		r = -1
		for i in range(n // 2 + 1):
			low = i
			high = n - i - 1
			if low <= high:
				if a[low] % x != 0:
					l = min(l, low)
				if a[high] % x != 0:
					r = max(r, n - i - 1)
		print(max(n - l - 1, r))


t = int(input())
while t > 0:
	n = int(input())
	x = list(map(int, input().split()))
	dic = {}
	for i in x:
		dic[i] = 1
	print(len(dic.keys()))
	t -= 1


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, x) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	su = sum(arr)
	su2 = su
	if su % x != 0:
		print(n)
	else:
		ma = -1
		ma2 = -1
		for i in range(n):
			if arr[i] % x != 0:
				ma = max(ma, n - i - 1)
				break
			else:
				su -= arr[i]
		for i in range(n):
			if arr[n - i - 1] % x != 0:
				ma2 = max(ma2, n - i - 1)
				break
			else:
				su -= arr[n - i - 1]
		print(max(ma, ma2))


t = int(input())
while t > 0:
	(n, x) = map(int, input().split())
	arr = list(map(int, input().split()))
	count = 0
	s = 0
	l = True
	r = True
	lnotdiv_id = 0
	rnotdiv_id = 0
	for i in range(n):
		if arr[i] % x == 0:
			count += 1
		s = s + arr[i]
	if count == n:
		print(-1)
	elif s % x != 0:
		print(n)
	else:
		for i in range(n):
			if arr[i] % x != 0 and l == True:
				lnotdiv_id = i
				l = False
			elif arr[n - 1 - i] % x != 0 and r == True:
				rnotdiv_id = n - 1 - i
				r = False
		print(n - min(lnotdiv_id + 1, n - 1 - rnotdiv_id + 1))
	t -= 1


from collections import Counter, defaultdict, deque
import math
tt = int(input())
for i in range(tt):
	l = int(input())
	s = set((x for x in input().split()))
	print(len(s))


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	a = inputlist()
	suma = 0
	good = False
	for i in range(n):
		if a[i] % k != 0:
			good = True
		suma += a[i]
	if suma % k != 0:
		print(n)
		continue
	if not good:
		print(-1)
		continue
	cnt1 = 0
	cnt2 = 0
	while a[cnt1] % k == 0:
		cnt1 += 1
	while a[n - 1 - cnt2] % k == 0:
		cnt2 += 1
	print(n - min(cnt1 + 1, cnt2 + 1))


t = int(input())
for i in range(0, t):
	(n, x) = map(int, input().split())
	o = list(map(int, input().split()))
	s = 0
	b = 0
	e = 0
	m = 0
	if x == 1:
		print(-1)
	else:
		s = sum(o)
		dd = s
		if s % x == 0:
			f = -1
			for j in range(0, n):
				s = s - o[j]
				dd = dd - o[n - j - 1]
				if s % x != 0 or dd % x != 0:
					print(n - j - 1)
					f = 0
					break
			if f == -1:
				print(-1)
		else:
			print(n)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

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

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

def in_ints():
	return map(int, input().split())
q = in_int()
for qq in range(q):
	n = in_int()
	a = in_list()
	s = set(a)
	print(len(s))


from sys import stdin, stdout
import math
import heapq
t = 1

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

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

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

def main():
	n = aint()
	l = lint()
	print(len(set(l)))
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	ok = False
	for i in range(n):
		if a[i] % x:
			ok = True
			break
	if not ok:
		print(-1)
	elif sum(a) % x:
		print(n)
	else:
		dist = -1
		for i in range(n):
			if a[i] % x:
				dist = n - i - 1
				break
		for i in range(n - 1, -1, -1):
			if a[i] % x:
				dist = max(dist, i)
				break
		print(dist)


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 solve():
	for _ in range(int(input())):
		(n, x) = li()
		a = [int(t) % x for t in input().split()]
		s = sum(a)
		if s % x != 0:
			print(n)
		elif set(a) == {0}:
			print(-1)
		else:
			for i in range(n):
				if a[i] or a[-(i + 1)]:
					print(n - (i + 1))
					break
solve()


def check(n, x, lst):
	if sum(lst) % x != 0:
		return n
	else:
		s1 = sum(a)
		num_1 = 0
		for j in range(n):
			s1 -= lst[j]
			if s1 % x != 0:
				num_1 = n - j - 1
				break
		s2 = sum(a)
		num_2 = 0
		for j in range(n - 1, -1, -1):
			s2 -= a[j]
			if s2 % x != 0:
				num_2 = j
				break
		num_max = max(num_1, num_2)
		return num_max if num_max > 0 else -1
for _ in range(int(input())):
	(m, y) = [int(j) for j in input().split()]
	a = [int(j) for j in input().split()]
	print(check(m, y, a))


cases = int(input())
answers = []
for _ in range(cases):
	n = int(input())
	arr = list(map(int, input().split()))
	answers.append(len(set(arr)))
for i in answers:
	print(i)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 0
	j = 0
	s = 0
	mx = 0
	while i < n:
		s += a[j]
		if s % x != 0:
			mx = max(mx, j - i + 1)
		if j < n - 1:
			j += 1
		else:
			s -= a[i]
			i += 1
	if mx == 0:
		print(-1)
	else:
		print(mx)


import sys
import collections
input = sys.stdin.readline

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

def solve(n, a):
	print(len(set(a)))
T = int(input())
while T:
	n = int(input())
	a = list(map(int, input().split()))
	solve(n, a)
	T -= 1


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	l = -1
	r = -1
	k = 0
	s = 0
	for i in range(n):
		if a[i] % x != 0:
			k = 1
		s += a[i]
		if l == -1 and a[i] % x != 0:
			l = i + 1
		if a[i] % x != 0:
			r = i + 1
	if k == 0:
		print(-1)
	elif s % x != 0:
		print(n)
	elif l > n - r + 1:
		print(r - 1)
	else:
		print(n - l)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	suma = sum(a)
	if suma % x == 0:
		cnt = 0
		for i in range(n):
			if a[i] % x != 0:
				cnt += 1
				break
			cnt += 1
		cnt1 = 0
		for i in range(n - 1, -1, -1):
			if a[i] % x != 0:
				cnt1 += 1
				break
			cnt1 += 1
		if n - min(cnt, cnt1) == 0:
			print('-1')
		else:
			print(n - min(cnt, cnt1))
	else:
		print(n)


def main():
	t = int(input())
	for __ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		if sum(a) % k:
			print(n)
			continue
		(l, r) = (-1, -1)
		for i in range(n):
			if a[i] % k:
				l = i
				break
		for i in range(n - 1, -1, -1):
			if a[i] % k:
				r = i
				break
		if l == -1:
			print(-1)
		else:
			print(n - min(l + 1, n - r))
main()


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))

def solve():
	(n, x) = MP()
	arr = LS()
	(mx, sm, lsm, fsm) = (-1, 0, -1, 0)
	for i in range(n):
		sm += arr[i]
		if sm % x != 0:
			mx = i + 1
		else:
			lsm = i
			fsm = sm
	if mx == -1:
		print(-1)
	elif lsm == -1:
		print(mx)
	else:
		for i in range(lsm):
			fsm -= arr[i]
			if fsm % x != 0:
				print(max(lsm - i, mx))
				break
for _ in range(IP()):
	solve()


t = int(input())
s = []
for iddefefe in range(0, t):
	y = 1
	n = int(input())
	x = input()
	xx = x.split()
	for i in range(0, n):
		xx[i] = int(xx[i])
	xx.sort()
	for i in range(1, n):
		if xx[i] > xx[i - 1]:
			y += 1
	s.append(y)
for i in s:
	print(i)


from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
	(n, x) = map(int, stdin.readline().split())
	l = list(map(int, stdin.readline().split()))
	s = sum(l)
	if s % x != 0:
		print(n)
		continue
	idx = [i for (i, a) in enumerate(l) if a % x != 0]
	if len(idx) == 0:
		print(-1)
	else:
		ans = max(n - idx[0] - 1, n - (n - idx[-1]))
		print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	ls = list(map(int, input().split()))
	print(len(set(ls)))


import sys, math
from collections import deque

def solve():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	total = sum(a)
	if not total % x == 0:
		print(n)
		return
	t1 = total
	li = 0
	for i in range(n):
		t1 -= a[i]
		if not t1 % x == 0:
			li = n - 1 - i
			break
	t2 = total
	ri = 0
	for j in range(n - 1, -1, -1):
		t2 -= a[j]
		if not t2 % x == 0:
			ri = j
			break
	ans = max(li, ri)
	if ans == 0:
		print(-1)
	else:
		print(ans)
	return
for _ in range(int(input())):
	solve()


from sys import stdin, stdout
import atexit, io, sys
buffer = io.BytesIO()
sys.stdout = buffer

@atexit.register
def write():
	sys.__stdout__.write(buffer.getvalue())
in1 = int(stdin.readline())
for i in range(in1):
	in2 = stdin.readline()
	in3 = stdin.readline()
	in3 = in3.split()
	l = len(set(in3))
	stdout.write(str(l) + '\n')


t = int(input())
for i in range(0, t):
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	a = -1
	b = -1
	s = sum(l)
	if s % x != 0:
		print(n)
	else:
		for i in range(0, n):
			if l[i] % x != 0:
				a = i
				break
		for i in range(n - 1, -1, -1):
			if l[i] % x != 0:
				b = i
				break
		if a == -1 and b == -1:
			print(-1)
		else:
			print(max([len(l[a + 1:]), len(l[:b])]))


t = int(input())
for tt in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	n = len(a)
	sum = 0
	for i in range(n):
		sum += a[i]
	if sum % x:
		ans = n
	else:
		l = r = 0
		for i in range(n):
			l += 1
			if a[i] % x:
				break
		for i in range(n - 1, -1, -1):
			r += 1
			if a[i] % x:
				break
		ans = n - min(l, r)
		if ans == 0:
			ans = -1
	print(ans)


T = int(input())
while T > 0:
	N = int(input())
	arr = set(map(int, input().split()))
	print(len(arr))
	T = T - 1


import sys
input = sys.stdin.readline

def rez():
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) % x != 0:
		print(n)
	else:
		f = sum(a)
		s = sum(a)
		ans = []
		for i in range(n):
			if f % x == 0:
				f -= a[i]
			else:
				ans.append(i)
				break
		for i in range(n - 1, -1, -1):
			if s % x == 0:
				s -= a[i]
			else:
				ans.append(n - i - 1)
				break
		if not ans:
			print(-1)
		else:
			print(n - min(ans))
for t in range(int(input())):
	rez()


t = int(input())

def solve(arr, x):
	n = len(arr)
	s = sum(arr)
	if s % x != 0:
		return n
	first_idx = 0
	while first_idx < n and arr[first_idx] % x == 0:
		first_idx += 1
	second_idx = n - 1
	while second_idx >= 0 and arr[second_idx] % x == 0:
		second_idx -= 1
	if first_idx == n:
		return -1
	res = max(first_idx, n - first_idx - 1, n - second_idx, second_idx)
	if res == 0:
		return -1
	return res
for _ in range(t):
	(n, x) = map(int, input().split())
	(*arr,) = map(int, input().split())
	print(solve(arr, x))


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = dict()
	for i in a:
		if b.get(i):
			b[i] += 1
		else:
			b[i] = 1
	print(len(b))


q = int(input())
for i in range(1, q + 1):
	n = int(input())
	a = [int(c) for c in input().split()]
	print(len(set(a)))


for _ in range(int(input())):
	num = int(input())
	li = [int(i) for i in input().split()]
	print(len(set(li)))


t = int(input())
for i in range(t):
	(n, x) = map(int, input().split(' '))
	v = list(map(int, input().split(' ')))
	s = sum(v)
	(l, r) = (0, n - 1)
	ans = n
	while r >= l and s % x == 0:
		if v[l] % x > 0 or v[r] % x > 0:
			ans = n - (l + 1)
			break
		else:
			l += 1
			r -= 1
	if r >= l:
		print(ans)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
t = int(sys.stdin.readline())
for _ in range(t):
	(n, x) = map(int, sys.stdin.readline().split())
	l = list(map(int, sys.stdin.readline().split()))
	s = sum(l)
	length = len(l)
	if s % x != 0:
		print(length)
	else:
		flag = 0
		for i in range(length):
			if l[i] % x != 0:
				result1 = length - (i + 1)
				flag = 1
				break
		for i in range(length - 1, -1, -1):
			if l[i] % x != 0:
				result2 = i
				flag = 1
				break
		if flag == 0:
			print(-1)
		else:
			print(result1 if result1 > result2 else result2)


import sys
input = sys.stdin.buffer.readline
x = int(input())
for x in range(x):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	p = 0
	ma = 0
	for y in range(b):
		p += d[y]
	if p % c != 0:
		ma = b
	else:
		for y in range(b):
			if d[y] % c != 0:
				ma = b - y - 1
				break
		for y in range(b - 1, -1, -1):
			if d[y] % c != 0:
				if y > ma:
					ma = y
					break
	if ma == 0:
		print(-1)
	else:
		print(ma)


import sys
from itertools import accumulate

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, x) = MAP()
	A = LIST()
	acc = [0] + list(accumulate(A))
	acc = [a % x for a in acc]
	ans = -1
	done = set()
	for l in range(N):
		if acc[l] in done:
			continue
		done.add(acc[l])
		for r in range(N, l, -1):
			if acc[l] != acc[r]:
				ans = max(ans, r - l)
				break
	print(ans)


import sys
max_int = 1000000001
min_int = -max_int
t = int(input())
for _t in range(t):
	(n, x) = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	s = sum(a)
	lena = len(a)
	l = 0
	for elem in a:
		if elem % x:
			break
		l += 1
	r = 0
	for elem in a[::-1]:
		if elem % x:
			break
		r += 1
	if s % x:
		print(lena)
	else:
		print(lena - min(l, r) - 1)


n = int(input())
for i in range(n):
	s = int(input())
	a = set([int(x) for x in input().split()])
	if s > len(a):
		print(len(a))
	else:
		print(s)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	dic_t = {}
	for i in arr:
		dic_t[i] = dic_t.get(i, 0) + 1
	print(len(dic_t))


for _ in range(int(input())):
	t = int(input())
	l = list(map(int, input().strip().split()))
	print(len(set(l)))


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l_set = len(set(l))
	print(l_set)


t = int(input())
for i in range(t):
	a1 = int(input())
	a2 = list(map(int, input().split()))
	a = {}
	if len(a2) == a1:
		for x in a2:
			if x in a:
				continue
			else:
				a[x] = x
		print(len(a))