from collections import defaultdict 
t=int(input())
while t>0:
    t-=1
    n=int(input())
    a=list(map(int,input().split()))
    minn=1000000
    if n==1:
        print(-1)
    else:
        d=dict()
        d=defaultdict(lambda:list(),d)
        for i in range(n):
            d[a[i]].append(i)

        for val in d.values():
            for i in range(len(val)-1):
                minn=min(minn,val[i+1]-val[i])
        print(minn+1)

            #print(val)
            #for i in key.values():


        #for key,values in d.items():
         #   print(key,values)



  