#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;
ll res;
ll a[N], n, x;
void solve() {
  cin >> n >> x;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ll i = 0;
  ll summ = sum;
  ll ans = 0;
  if (sum % x != 0) {
    cout << n << "\n";
    return;
  }
  while (i < n) {
    summ -= a[i];
    if (summ % x != 0) {
      ans = max(ans, n - i - 1);
      break;
    }
    i++;
  }
  ll j = n - 1;
  summ = sum;
  while (j >= 0) {
    summ -= a[j];
    if (summ % x != 0) {
      ans = max(ans, j);
      break;
    }
    j--;
  }
  if (!ans) ans = -1;
  cout << ans << "\n";
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
