#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    int N, X;
    cin >> N >> X;
    vector<int> v;
    int l = -1;
    int r = -1;
    int s = 0;
    for (int i = 0; i < N; i++) {
      int a;
      cin >> a;
      s += a;
      if (a % X != 0) {
        if (l == -1) l = i;
        r = i;
      }
    }
    if (s % X != 0) {
      cout << N << "\n";
    } else {
      if (l == -1)
        cout << "-1\n";
      else
        cout << max(N - l - 1, r) << "\n";
    }
  }
  return 0;
}
