from collections import defaultdict as dc
from collections import deque as dq
from bisect import bisect_left,bisect_right,insort_left
import sys
import math
#define of c++ as inl=input()
mod=10**9 +7
def bs(a,x):
    i=bisect_left(a,x)
    if i!=len(a):
        return i
    else:
        return len(a)
def inp():
    p=int(input())
    return p
def line():
    p=list(map(int,input().split()))
    return p
def bs(a,b):
    l=a
    r=b+1
    x=b
    ans=0
    while(l<r):
        mid=(l+r)//2
        if x|mid>ans:
            ans=x|mid
            l=mid+1
        else:
            r=mid
    return ans
def digit(n):
    a=[]
    while(n>0):
        a.append(n%10)
        n=n//10
    return a
def fibo(n,p):
    a=1
    b=1
    for i in range(2,n+1):
        c=a+b
        a=b
        b=c
        if p[i]==1:
            p[i]=c
    
for _ in range(inp()):
    n=inp()
    ans=0
    a=line()
    z=float('inf')
    p=dc(list)
    for i in range(n):
        p[a[i]].append(i+1)
    for i in list(p.keys()):
        l=p[i]
        #print(i,l)
        if len(l)>1:
            ans=1
            for j in range(1,len(l)):
                z=min(z,(l[j]-l[j-1]+1))
                
    if ans==0:
        print(-1)
    else:
        print(z)
        
    