#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long x;
    cin >> n >> x;
    long long a[n];
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    int ans = -1;
    bool ok = false;
    if (sum % x) {
      cout << n << "\n";
      continue;
    }
    for (int i = 0; i < n; i++) {
      if ((sum - a[i]) % x) {
        ok = true;
        ans = n - i - 1;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if ((sum - a[i]) % x) {
        ok = true;
        ans = max(ans, i);
      }
    }
    cout << ans << "\n";
  }
}
