for _ in range(int(input())):
    n = int(input())
    lis = list(map(int,input().split()))
    last=[-1]*(200000)
    ans=1000000000
    if n<=1:
        print(-1)
    else:
        for i in range(n):
#            print(last)
            if last[lis[i]]!=-1:
                ans=min(ans,i-last[lis[i]]+1)
            last[lis[i]]=i
        print(ans)
