#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int vis[N];
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    int n;
    scanf("%d", &n);
    int ans = -1;
    for (int i = 1; i <= n; i++) vis[i] = 0;
    int now = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (vis[a[i]]) {
        int dis = i - vis[a[i]] + 1;
        if (ans == -1)
          ans = dis;
        else
          ans = min(ans, dis);
      }
      vis[a[i]] = i;
    }
    printf("%d\n", ans);
  }
  return 0;
}
