#include <bits/stdc++.h>
;
using namespace std;
void play() {
  long long n, x, a, first = -1, last = -1, sum = 0;
  cin >> n >> x;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    sum += a;
  }
  if (sum % x != 0) {
    cout << n << "\n";
    return;
  }
  for (long long i = 0; i < n; i++)
    if (v[i] % x != 0) {
      first = i;
      break;
    }
  for (long long i = n - 1; i >= 0; i--)
    if (v[i] % x != 0) {
      last = i;
      break;
    }
  if (first == -1 && last == -1)
    cout << -1;
  else {
    if (first == -1)
      cout << last;
    else if (last == -1) {
      cout << n - first - 1;
    } else
      cout << max(n - first - 1, last);
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) play();
  return 0;
}
