#include <bits/stdc++.h>
using namespace std;
int solve() {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  vector<int> index;
  for (int(i) = 0; (i) < n; (i)++) {
    cin >> a[i];
    if (a[i] % x != 0) index.push_back(i);
  }
  if (index.size() == 0) {
    cout << "-1\n";
    return 0;
  }
  int s = 0;
  for (int(i) = 0; (i) < index.size(); (i)++) {
    s += a[index[i]];
  }
  if (s % x != 0) {
    cout << n << "\n";
    return 0;
  }
  int rez = n;
  int q = 0, w = index.size() - 1;
  int i = index[0], j = index[index.size() - 1];
  while (s % x == 0) {
    if (i + 1 < n - j) {
      s -= a[i];
      rez -= i + 1;
      q++;
      i = index[q];
    } else {
      s -= a[j];
      rez -= n - j;
      w--;
      j = index[w];
    }
  }
  cout << rez << "\n";
  return 0;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
