#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int t = 0; t < T; ++t) {
    int N, X;
    cin >> N >> X;
    vector<int> v(N);
    int icount = 0;
    for (auto& x : v) {
      cin >> x;
      icount += x;
    }
    if (icount % X)
      cout << N << '\n';
    else {
      int find1 = -1;
      for (int n = 0; n < N; ++n) {
        if (v[n] % X) {
          find1 = n;
          break;
        }
      }
      int find2 = -1;
      for (int n = N - 1; n >= 0; --n) {
        if (v[n] % X) {
          find2 = n;
          break;
        }
      }
      if (find1 == -1)
        cout << -1 << '\n';
      else {
        int ans = max({N - find1 - 1, find1, N - find2 - 1, find2});
        cout << ans << '\n';
      }
    }
  }
  return 0;
}
