#include <bits/stdc++.h>
const int MAX_N = 200000;
int a[MAX_N + 1];
inline void solveCase() {
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; i++) std::cin >> a[i];
  std::unordered_map<int, int> h;
  int ans = std::numeric_limits<int>::max();
  for (int i = 1; i <= n; i++) {
    auto p = h.find(a[i]);
    if (p != h.end()) ans = std::min(ans, i - p->second + 1);
    h[a[i]] = i;
  }
  if (ans == std::numeric_limits<int>::max()) {
    std::cout << "-1\n";
  } else {
    std::cout << ans << '\n';
  }
}
inline void solve() {
  int t;
  std::cin >> t;
  while (t--) solveCase();
}
int main() {
  solve();
  return 0;
}
