#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int qw;
  cin >> qw;
  vector<int> mas[200010];
  for (int we = 0; we < qw; we++) {
    int n;
    cin >> n;
    int cur;
    int res = -1;
    for (int i = 0; i < n; i++) {
      cin >> cur;
      if (mas[cur].size() == 0) {
        mas[cur].push_back(we);
        mas[cur].push_back(i);
      } else {
        if (mas[cur][1] == we) {
          if (res == -1) {
            res = i - mas[cur][0] + 1;
          }
          res = min(res, i - mas[cur][0] + 1);
          mas[cur][0] = i;
        } else {
          mas[cur][1] = we;
          mas[cur][0] = i;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
