#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, bad;
  cin >> n >> bad;
  vector<long long> v(n);
  bool has = 0;
  for (long long &i : v) {
    cin >> i;
    i %= bad;
    if (i != 0) has = 1;
  }
  if (!has) {
    cout << -1 << endl;
    return;
  }
  long long sum = 0;
  long long l = 0;
  while (v[l] == 0) l++;
  long long r = n - 1;
  while (v[r] == 0) r--;
  for (long long i = l; i <= r; i++) sum += v[i];
  sum %= bad;
  if (sum != 0)
    cout << max(r + 1, n - l) << endl;
  else
    cout << max(r + 1, n - l) - 1 << endl;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n = 1;
  cin >> n;
  while (n--) solve();
  return 0;
}
