for tc in range(int(input())):
    n = int(input())
    line = input().split()
    arr = []
    lengths = []
    d = {}
    for i in range(n):
        element = int(line[i])
        if d.get(element, -1) >= 0:
            lengths.append(i - d.get(element))
        d[element] = i
    if len(lengths) == 0:
        print("-1")
    else:
        print(min(lengths)+1)