#include <bits/stdc++.h>   using namespace std;   int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0);   const int N = 200010;   const int inf = ~0u >> 2;   const long long INF = ~0ull >> 2;   long long read() {     long long x;     if (scanf( %lld , &x) == -1) exit(0);     return x;   }   const double pi = acos(-1.0);   double readf() {     double x;     if (scanf( %lf , &x) == -1) exit(0);     return x;   }   template <typename T>   T sqr(const T &x) {     return x * x;   }   int mod = (1 ? 1000000007 : 998244353);   long long mul(long long a, long long b, long long m = mod) { return a * b % m; }   long long qpow(long long a, long long b, long long m = mod) {     long long ans = 1;     for (; b; a = mul(a, a, m), b >>= 1)       if (b & 1) ans = mul(ans, a, m);     return ans;   }   long long getinv(long long v, long long m = mod) { return qpow(v, m - 2, m); }   long long n, x, t, l, r, sum;   void solve() {     cin >> n >> x;     sum = 0;     l = inf, r = -inf;     for (long long i = (0), _ = (n); i < _; i++) {       cin >> t;       if (t % x != 0) l = min(l, i), r = max(r, i);       sum += t % x;     }     if (sum % x != 0) {       cout << n << endl;       return;     }     if (l != inf) {       cout << max(n - l - 1, r) << endl;       return;     }     cout << -1 << endl;   }   signed main() {     long long T;     cin >> T;     while (T--) {       solve();     }     return 0;   }   