#include <bits/stdc++.h>
using namespace std;

template <typename T>
void read(T &x) {
    int s = 0, c = getchar();
    x = 0;
    while (isspace(c)) c = getchar();
    if (c == 45) s = 1, c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
    int b[40], l = 0;
    if (x < 0) putchar(45), x = -x;
    while (x > 0) b[l++] = x % 10, x /= 10;
    if (!l) putchar(48);
    while (l) putchar(b[--l] | 48);
    putchar(c);
}
int cnt[200050],shu[200050];
int n;
void Input(void) {
    read(n);
    for(int i=1;i<=n;++i)
        read(shu[i]);
    for(int i=1;i<=n;++i) cnt[i]=0;
    if (n==1) printf("-1\n");
    else{
        int ans=9999999;
        for(int i=1;i<=n;++i){
            if (cnt[shu[i]]){
                ans=min(ans,i-cnt[shu[i]]+1);
                for(int j=1;j<=n;++j) cnt[j]=0;
            }
            cnt[shu[i]]=i;
        }
        printf("%d\n",ans);
    }
}

void Solve(void) {}

void Output(void) {}

main(void) {
    int kase;
    read(kase);
    for (int i = 1; i <= kase; i++) {
        //printf("Case #%d: ", i);
        Input();
        Solve();
        Output();
    }
}
