#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    long long consum = 0;
    int lengtharr = 0;
    int templength = 0;
    int k = 0;
    for (int i = 0; i < n; i++) {
      consum += arr[i];
      if (consum % x != 0) lengtharr = i + 1;
    }
    for (int j = n - 1; j >= 0; j--) {
      consum += arr[j];
      if (consum % x != 0) templength = (n - j);
    }
    if (templength != 0 || lengtharr != 0) {
      cout << max(lengtharr, templength) << "\n";
    } else {
      cout << -1 << "\n";
    }
  }
  return 0;
}
