#include <bits/stdc++.h>
using namespace std;
long long int maxi(long long int a, long long int b) { return (a > b) ? a : b; }
long long int mini(long long int a, long long int b) { return (a < b) ? a : b; }
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x, sum = 0;
    cin >> n >> x;
    long long int a[n];
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      a[i] %= x;
      sum += a[i];
    }
    long long int mx = -1, mn = 100000000;
    for (long long int i = 0; i < n; i++) {
      if (a[i]) {
        mx = maxi(i, mx);
        mn = mini(i, mn);
      }
    }
    if (sum % x)
      cout << n << endl;
    else if (mx > -1 && mn < 10000000) {
      cout << n - mini(mn + 1, n - mx) << endl;
    } else
      cout << "-1\n";
  }
}
