def is_domin(a):
    my_dict = dict()
    for el in a:
        my_dict[el] = my_dict.get(el, 0) + 1
    sorted_dict = sorted(my_dict.items(), key=lambda kv: kv[1], reverse=True)
    if len(my_dict) == 1 or sorted_dict[0][1] > sorted_dict[1][1]:
        return True
    else:
        return False


n = int(input())
for nn in range(n):
    length = int(input())
    my_list = list(map(int, input().split()))
    if length == 1:
        print(-1)
    else:
        for i in range(2, length + 1):
            for j in range(0, length - i + 1):
                if is_domin(my_list[j:j + i]):
                    print(i)
                    break
            else:
                continue
            break