#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long logtwo(long long n) {
  if (n == 1) return 0;
  return logtwo(n / 2) + 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    long long arr[n];
    long long tot_sum = 0;
    for (long long i = 0; i < n; i++) {
      cin >> arr[i];
      tot_sum += arr[i];
    }
    if (tot_sum % x != 0) {
      cout << n << "\n";
      continue;
    }
    long long start = -1;
    long long end = -1;
    for (long long i = 0; i < n; i++) {
      if (arr[i] % x != 0) {
        start = i + 1;
        break;
      }
    }
    for (long long i = n - 1; i >= 0; i--) {
      if (arr[i] % x != 0) {
        end = i - 1;
        break;
      }
    }
    if (start != -1 && end != -1) {
      long long len_left = n - start;
      long long len_right = end + 1;
      cout << max(len_left, len_right) << "\n";
    }
    if (start != -1 && end == -1) {
      cout << n - start - 1 << "\n";
    }
    if (start == -1 && end != -1) {
      cout << end + 1 << "\n";
    }
    if (start == -1 && end == -1) {
      cout << -1 << "\n";
    }
  }
}
