#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    int answer = -1;
    map<int, int> mp;
    for (int j = 1; j <= t; j++) {
      int k;
      cin >> k;
      if (mp.count(k)) {
        int tmp = j - mp[k] + 1;
        if (answer == -1 || answer > tmp) {
          answer = tmp;
        }
      }
      mp[k] = j;
    }
    cout << answer << endl;
  }
}
