vis = [-1 for i in range(200005)]
last = [-1 for i in range(200005)]
for tc in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    ret = n + 1
    for i in range(n):
        x = a[i]
        if (vis[x] == tc): ret = min(ret, 1 + i - last[x])
        else: vis[x] = tc
        last[x] = i
    if (ret > n): ret = -1
    print(ret)