def main():
    answer = ""
    for query in range(int(input())):
        ans = None
        n = int(input())
        array = list(map(int,input().split(' ')))
        ocurrences = dict()
        for index in range(len(array)):
            num = array[index]
            if ocurrences.get(num) == None:
                ocurrences[num] = [index]
            else:
                a = ocurrences[num]
                a.append(index)
                ocurrences[num] = a
        total_min_range = -1
        for key in ocurrences.keys():
            
            lst = ocurrences[key] 
            if len(lst) > 1:
                min_range = abs(lst[1] - lst[0])
                for index in range(len(lst)-1):
                    min_range = min(min_range,abs(lst[index+1] - lst[index]))
                if total_min_range == -1 or total_min_range >= min_range:
                    total_min_range = min_range
        if total_min_range != -1:
            total_min_range += 1
        answer += str(total_min_range) + "\n"
    print(answer)
main()
