#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    long long s = 0;
    vector<long long> vec(n);
    for (int i = (int)0; i < (int)n; i++) {
      cin >> vec[i];
      s += vec[i];
    }
    long long l = 0, r = 0;
    while (n > l && (vec[l] % x == 0)) l++;
    while (r < n && (vec[n - r - 1] % x == 0)) r++;
    if (s % x != 0)
      cout << n << "\n";
    else {
      cout << n - min(l, r) - 1 << "\n";
    }
  }
  return 0;
}
