#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const string ln = "\n";
const string alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
void printv(vector<pair<int, int> > &s) {
  for (int i = 0; i < s.size(); i++) {
    cout << s[i].first << " ";
  }
  cout << ln;
}
int main() {
  int tq;
  cin >> tq;
  for (int ti = 0; ti < tq; ti++) {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    int s = 0;
    bool f = 1;
    vector<int> nd;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s += a[i];
      if (a[i] % x) {
        f = 0;
        nd.push_back(i);
      }
    }
    if (f) {
      cout << -1 << ln;
      continue;
    }
    if (s % x != 0) {
      cout << n << ln;
      continue;
    }
    int ans = 1;
    for (int i = 0; i < nd.size(); i++) {
      int id = nd[i];
      ans = max(ans, max(id, n - id - 1));
    }
    cout << ans << ln;
  }
}
