#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n];
    long long temp, sum = 0, pre = -1, suf = -1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
      if (pre == -1 && sum % m != 0) pre = i;
    }
    if (sum % m != 0) {
      cout << n << "\n";
      continue;
    }
    temp = 0;
    for (int i = n - 1; i >= 0; i--) {
      temp += a[i];
      if (suf == -1 && temp % m != 0) suf = i;
    }
    if (suf == -1 && pre == -1) {
      cout << -1 << "\n";
      continue;
    }
    int ans = 0;
    ans = max(suf, n - pre - 1);
    cout << ans << "\n";
  }
  return 0;
}
