#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void D() {
  ll n, x;
  cin >> n >> x;
  vector<int> v(n);
  for (auto &i : v) cin >> i;
  ll sum = accumulate(v.begin(), v.end(), 0);
  if (sum % x) {
    cout << n << "\n";
    ;
    return;
  }
  ll temp = sum;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    sum -= v[i];
    if (sum % x) {
      ans = max(ans, n - (i + 1));
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    temp -= v[i];
    if (temp % x) {
      ans = max(ans, (ll)i);
      break;
    }
  }
  cout << (ans == 0 ? -1 : ans) << "\n";
  ;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(0);
  cout << fixed;
  ll n, m, k, pt(0), ct(0), x, y;
  ll t = 1;
  cin >> t;
  while (t--) {
    D();
  }
}
