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