#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, x;
  cin >> n >> x;
  long long a[n];
  for (auto &i : a) cin >> i;
  long long pre[n + 1];
  pre[0] = 0;
  for (long long i = 1; i <= n; i++) pre[i] = (pre[i - 1] + a[i - 1]) % x;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (pre[i] != 0) ans = max(ans, i);
  }
  for (long long i = n; i >= 0; i--) {
    if (pre[i] != pre[n]) ans = max(ans, n - i);
  }
  if (ans == 0)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) solve();
}
