#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t, n, x, i, sum = 0;
  cin >> t;
  while (t--) {
    sum = 0;
    cin >> n >> x;
    int a[n + 1];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (i = 0; i < n; i++) {
      sum = sum + a[i];
    }
    if (sum % x != 0) {
      cout << n << endl;
      continue;
    }
    bool d = 0;
    int b = 0, c = 0;
    for (i = 0; i < n; i++) {
      if (a[i] % x != 0) {
        d = 1;
        b = n - i - 1;
        break;
      }
    }
    reverse(a, a + n);
    for (i = 0; i < n; i++) {
      if (a[i] % x != 0) {
        d = 1;
        c = n - i - 1;
        break;
      }
    }
    if (d) {
      cout << max(b, c) << endl;
    } else {
      cout << "-1" << endl;
    }
  }
}
