#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    vector<int> arr;
    unordered_map<int, vector<int> > mapping;
    for (int j = 0; j < n; j++) {
      int input;
      cin >> input;
      arr.push_back(input);
    }
    for (int p = 0; p < n; p++) {
      mapping[arr[p]].push_back(p + 1);
    }
    int ans = 2 * 10 ^ 5;
    int entering = -1;
    for (auto it = mapping.begin(); it != mapping.end(); it++) {
      int val = it->first;
      vector<int> index = it->second;
      for (int k = 0; k < index.size() - 1; k++) {
        int diff = index[k + 1] - index[k] + 1;
        if (diff < ans) {
          ans = diff;
        }
        entering = 0;
      }
    }
    if (entering == -1) {
      cout << entering << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
