def solve(arr):
    dic={}
    f=0
    for i in range(len(arr)):
        try:
            dic[arr[i]].append(i)
            f=1
        except:
            dic[arr[i]]=[i]
    mini=999999999999
    # f=0
    for i in dic:
        curr=999999999999
        if len(dic[i])>1:
            # f2=1
            for j in range(1,len(dic[i])):
                curr=min(dic[i][j]-dic[i][j-1],curr)
        mini=min(curr,mini)

    if f==1:
        return mini+1
    else:
        return -1


for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    print(solve(arr))
