#include <bits/stdc++.h>
using namespace std;
void solve(int test_case) {
  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  bool possible = false;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % x != 0) {
      possible = true;
    }
    sum += a[i];
  }
  if (!possible) {
    cout << "-1\n";
    return;
  }
  if (sum % x != 0) {
    cout << n << "\n";
  } else {
    int i1, i2;
    for (int i = 0; i < n; i++) {
      if (a[i] % x != 0) {
        i1 = i;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] % x != 0) {
        i2 = i;
        break;
      }
    }
    long long ans = max((i2), n - 1 - i1);
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int T;
  cin >> T;
  for (int t = 1; t <= T; t++) {
    solve(t);
  }
}
