def shortest_dominated(a: list) -> int:
    numbers_indices = {}
    minimal_length = -1
    for idx, el in enumerate(a):
        if el not in numbers_indices:
            numbers_indices[el] = idx
        else:
            prev_idx = numbers_indices[el]
            numbers_indices[el] = idx
            
            dominated_length = idx - prev_idx + 1
            if minimal_length == -1:
                minimal_length = dominated_length
            elif dominated_length < minimal_length: 
                minimal_length = dominated_length
    return minimal_length

def main():
    t = int(input())
    for i in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        print(shortest_dominated(a))
        
main()