from collections import defaultdict
t = int(input())
while(t>0):
    n= int(input())   
    arr = [int(i) for i in input().split()]
    d=  defaultdict(list)
    for i in range(n):
        d[arr[i]].append(i)
    mini =100000000
    for i in d.keys():
        if len(d[i])>1:
            k = d[i]
            for i in range(1,len(k)):
                mini = min(mini,k[i]-k[i-1]+1)
    if mini ==100000000:
        mini = -1
    print(mini)
    t-=1