#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x, s = 0, c = 0, m = -500, ss = 0, mx = -500;
    ;
    cin >> n >> x;
    int a[n];
    vector<int> v, w;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      s += a[i];
      v.push_back(s % x);
    }
    for (int i = n - 1; i >= 0; i--) {
      ss += a[i];
      w.push_back(ss % x);
    }
    if (s % x != 0)
      cout << n << endl;
    else {
      for (int i = 0; i < n; i++) {
        if (v[i] != 0) m = max(m, i + 1);
      }
      for (int i = 0; i < n; i++) {
        if (w[i] != 0) mx = max(mx, i + 1);
      }
      if (m == -500 && mx == -500)
        cout << -1 << endl;
      else
        cout << max(m, mx) << endl;
    }
  }
  return 0;
}
