def main():
    print = out.append
    ''' Cook your dish here! '''
    n = get_int()
    li = get_list()
    indexs = defaultdict(list)
    for i, ele in enumerate(li):
        indexs[ele].append(i)
    res = -1
    for key in indexs:
        for j in range(1, len(indexs[key])):
            res = min(res, indexs[key][j]-indexs[key][j-1]+1) if res!=-1 else indexs[key][j]-indexs[key][j-1]+1
    print(res)




''' Coded with love at India by Satyam Kumar '''
import sys
from collections import defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
#main()
[main() for _ in range(int(input()))]
print(*out, sep='\n')
