#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long int bpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int fact(long long int n) {
  if ((n == 0) || (n == 1))
    return 1;
  else
    return (n * fact(n - 1)) % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  std::cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, x, sum = 0;
    cin >> n >> x;
    vector<long long int> v(n);
    int l = -1, r;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      if (v[i] % x) {
        if (l == -1) {
          l = i;
        }
        r = i;
      }
      sum += v[i];
    }
    if (sum % x)
      cout << n << "\n";
    else if (l == -1)
      cout << "-1"
           << "\n";
    else {
      cout << n - min(l + 1, n - r) << "\n";
    }
  }
}
