#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int n;
    int number;
    int min_dist = INT_MAX;
    int dist;
    unordered_map<int, int> nums;
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> number;
      if (!(nums.find(number) == nums.end())) {
        dist = j - nums[number];
        if (dist < min_dist) {
          min_dist = dist;
        }
      }
      nums[number] = j;
    }
    if (min_dist == INT_MAX) {
      cout << -1 << endl;
    } else {
      cout << min_dist + 1 << endl;
    }
  }
  return 0;
}
