#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x;
  cin >> n >> x;
  vector<int> ys(n);
  vector<int> zs(x);
  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    ys[i] = y % x;
    zs[y % x]++;
  }
  if (zs[0] == n) {
    cout << -1 << endl;
    return;
  } else {
    int tmp = 0;
    for (int i = 0; i < zs.size(); i++) {
      tmp += i * zs[i];
    }
    if (tmp % x != 0) {
      cout << n << endl;
      return;
    } else {
      int i = 0;
      int j = n - 1;
      for (i = 0; i < n; i++) {
        if (ys[i]) {
          break;
        }
      }
      for (j = n - 1; j >= 0; j--) {
        if (ys[j]) {
          break;
        }
      }
      cout << n - (min(i + 1, n - j)) << endl;
      return;
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
