#include <bits/stdc++.h>
using namespace std;
void mian();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int _t_;
  cin >> _t_;
  while (_t_--) mian();
}
void mian() {
  int n;
  cin >> n;
  long long x;
  cin >> x;
  vector<long long> a(n);
  for (auto &x : a) cin >> x;
  long long sum = 0, div = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % x == 0) div++;
    sum += a[i];
    sum %= x;
  }
  if (sum != 0) {
    cout << n << '\n';
    return;
  }
  if (div == n) {
    cout << -1 << '\n';
    return;
  }
  int minl, minr;
  for (int i = 0; i < n; i++) {
    if (a[i] % x) {
      minl = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] % x) {
      minr = i;
      break;
    }
  }
  cout << max(n - minl - 1, n - (n - minr)) << '\n';
}
