#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(T& a) {
  for (auto x : a) cout << x << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, h, i;
    cin >> n >> h;
    long long cnt = 0, c = -1, t2;
    long long a[n + 5];
    for (i = 0; i < n; i++) {
      cin >> a[i];
      cnt += a[i];
      if (a[i] % h != 0) {
        if (c == -1) c = i;
        t2 = i;
      }
    }
    if (cnt % h)
      cout << n << "\n";
    else if (c == -1)
      cout << -1 << "\n";
    else {
      long long re = n - min(c + 1, n - t2);
      cout << re << "\n";
    }
  }
  return 0;
}
