import sys
input=sys.stdin.readline

t=int(input())
for _ in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  ls=[0]*(n+1)
  ans=-1
  for i in range(n):
    if ls[a[i]]==0:
      ls[a[i]]=i+1
    else:
      ans=i-ls[a[i]]+2
      break
  print(ans)