def dominated(n,m):
    t=set(m)
    if len(t)==len(m):
        return -1
    t=list(t)
    points={}
    for i in t:
        points[i]=[]
    for i in range(len(m)):
        points[m[i]].append(i)
    result=[]
    for j in points.items():
        if len(j[1])==1:
            continue
        for i in range(len(j[1])-1):
            result.append(j[1][i+1]-j[1][i]+1)
    return min(result)

for i in range(int(input().strip())):
    n=int(input().strip())
    m=input().strip().split()
    m=[int(m[i]) for i in range(len(m))]
    print(dominated(n,m))