#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dx[] = {-1, 0, 1, 0};
long long dy[] = {0, -1, 0, 1};
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    vector<long long> v(n + 10);
    long long sum = 0;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
      v[i] %= x;
    }
    for (long long i = 0; i < n; i++) {
      sum = (sum + v[i]) % x;
      if (sum != 0) {
        ans = i + 1;
      }
    }
    for (long long i = 0; i < n; i++) {
      sum = (sum - v[i] + x) % x;
      if (sum != 0) {
        ans = max(ans, n - i - 1);
      }
    }
    if (ans == 0)
      cout << -1 << "\n";
    else
      cout << ans << "\n";
  }
}
