#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x, l = -1, r = 1, a, sum = 0;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
      cin >> a;
      if (a % x != 0) {
        if (l == -1) l = i;
        r = i;
      }
      sum += a;
    }
    if (sum % x) {
      cout << n << endl;
    } else if (l == -1) {
      cout << -1 << endl;
    } else {
      cout << n - min(l + 1, n - r) << endl;
    }
  }
  return 0;
}
