#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    vector<int> arr(n);
    long long sum = 0;
    for (auto &i : arr) {
      cin >> i;
      sum += i;
    }
    if (sum % x != 0) {
      cout << n << endl;
      continue;
    }
    long long ans = -1;
    for (long long i = 0; i < n; ++i) {
      if (arr[i] % x != 0) {
        ans = max(ans, n - i - 1);
      }
    }
    for (long long i = n - 1; i >= 0; --i) {
      if (arr[i] % x != 0) {
        ans = max(ans, i);
      }
    }
    cout << ans << endl;
  }
}
