#include <bits/stdc++.h>
using namespace std;
int T, N;
long long int A[200000];
long long int x;
int main() {
  cin >> T;
  for (int t = 0; t < T; t++) {
    cin >> N >> x;
    bool divx = true;
    for (int i = 0; i < N; i++) {
      cin >> A[i];
      if (A[i] % x != 0) divx = false;
    }
    if (divx)
      cout << -1 << endl;
    else {
      long long int sum = 0;
      for (int i = 0; i < N; i++) sum += A[i];
      if (sum % x != 0)
        cout << N << endl;
      else {
        int sx = 0, dx = N - 1;
        while (A[sx] % x == 0) sx++;
        while (A[dx] % x == 0) dx--;
        cout << max(N - sx - 1, dx) << endl;
      }
    }
  }
  return 0;
}
