from collections import Counter,defaultdict
from sys import stdin, stdout
input = stdin.readline
I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
for _ in range(I()):
    n=I()
    a=LI()
    d=Counter(a)
    e={}
    for i in d.keys():
        e[i]=[]
    mi=-1
    for i in range(n):
        e[a[i]]+=[i]
        if len(e[a[i]])>1:
            if mi==-1:
                mi=(e[a[i]][-1]-e[a[i]][-2])+1
            else:
                mi=min((e[a[i]][-1]-e[a[i]][-2])+1,mi)
    print(mi)