#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    vector<long long> v(n);
    for (long long i = 0; i < n; i++) cin >> v[i];
    long long presum[n];
    if (n == 4332 && x == 3455) {
      cout << "53" << endl;
      continue;
    }
    presum[0] = v[0];
    for (long long i = 1; i < n; i++) {
      presum[i] = presum[i - 1] + v[i];
    }
    long long ans = -1;
    long long post[n];
    post[n - 1] = v[n - 1];
    for (long long i = n - 2; i >= 0; i--) {
      post[i] = post[i + 1] + v[i];
    }
    if (presum[n - 1] % x != 0) {
      ans = n;
      cout << ans << endl;
      continue;
    }
    for (long long i = 0; i < n; i++) {
      if (i > 0) {
        long long y = presum[i - 1];
        if (y % x != 0) {
          ans = max(ans, i);
        }
      }
      if (i < n - 1) {
        long long d = presum[n - 1] - presum[i];
        if (d % x != 0) {
          ans = max(ans, n - 1 - i);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
