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: interview

Starter code:

Solutions:

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)


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

for _ in range(int(input())):
    n, x = list(map(int, input().split()))
    # n = int(input())
    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)


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

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

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


"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""



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


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



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

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

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