#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i, j, k, a, xmin = 999999, c;
  cin >> t;
  set<int> x;
  while (t--) {
    cin >> n;
    k = 0, c = 0, xmin = 999999;
    for (i = 0; i < n; i++) {
      cin >> a;
      if (!x.count(a)) {
        c++;
        x.insert(a);
      } else {
        k = 1;
        c++;
        if (c < xmin) {
          xmin = c;
        }
        x.clear();
        x.insert(a);
        c = 1;
      }
    }
    if (k == 1)
      cout << xmin << endl;
    else
      cout << -1 << endl;
    x.clear();
  }
}
