#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11, M = 1e3 + 9;
long long int solve() {
  long long int n, x;
  cin >> n >> x;
  long long int ar[n], sum = 0;
  for (long long int i = 0; i < n; ++i) {
    cin >> ar[i];
    ar[i] %= x;
    sum += ar[i];
  }
  if (sum % x) return n;
  long long int left = n, right = -1;
  for (long long int i = 0; i < n; ++i) {
    if (ar[i] != 0) {
      left = min(left, i);
      right = max(right, i);
    }
  }
  if (left == n) return -1;
  long long int left_buffer = left + 1;
  long long int right_buffer = n - right;
  return (n - min(left_buffer, right_buffer));
}
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    cout << solve() << endl;
  }
  return 0;
}
