#include <bits/stdc++.h>
using namespace std;
int i, j, n, t, s, x, a[100005];
int main() {
  for (cin >> t; t--;) {
    cin >> n >> x;
    for (i = s = 0; i++ < n;) {
      cin >> a[i];
      s += a[i];
    }
    if (s % x)
      cout << n << endl;
    else {
      for (i = 0; i <= n && a[i] % x < 1;) i++;
      for (j = n; j && a[j] % x < 1;) j--;
      if (i > n)
        cout << -1 << endl;
      else
        cout << max(n - i, j - 1) << endl;
    }
  }
}
