#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x, ai, st = 0;
  cin >> n >> x;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> ai;
    a[i] = ai % x;
    st += ai;
    st %= x;
  }
  if (st != 0) {
    cout << n;
    return;
  }
  int l = 0, r = 0;
  while (a[l] == 0 && l < n) {
    l++;
  }
  if (l == n) {
    cout << -1;
    return;
  }
  while (a[n - 1 - r] == 0 && r < n) {
    r++;
  }
  cout << max(n - l - 1, n - r - 1);
  return;
}
int main() {
  int testcases;
  cin >> testcases;
  for (int tc = 0; tc < testcases; tc++) {
    solve();
    cout << "\n";
  }
  return 0;
}
