#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tc = 1;
  cin >> tc;
  while (tc--) {
    long long n, x;
    cin >> n >> x;
    long long ar[n];
    long long ans = 0;
    long long p = 0, s = 0;
    for (long long i = 0; i < n; i++) {
      cin >> ar[i];
      s += ar[i];
    }
    while (p < n && ar[p] % x == 0) p++;
    long long q = 0;
    while (q < n && ar[n - 1 - q] % x == 0) q++;
    ans = max(ans, n - min(p, q) - 1);
    if (ans == 0) ans = -1;
    if (s % x) ans = n;
    cout << ans << endl;
  }
}
