#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, s = 0, ans1 = 0, ans2 = 0;
    cin >> n >> x;
    long long a[n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      s += a[i];
    }
    if (s % x)
      cout << n << "\n";
    else {
      long long sum1 = 0, sum2 = 0;
      for (long long i = 0; i < n; i++) {
        sum1 += a[i];
        if (sum1 % x) {
          ans1 = n - i - 1;
          break;
        }
      }
      for (long long i = n - 1; i >= 0; i--) {
        sum2 += a[i];
        if (sum2 % x) {
          ans2 = i;
          break;
        }
      }
      long long ans = max(ans1, ans2);
      if (ans == 0)
        cout << -1 << "\n";
      else
        cout << ans << "\n";
    }
  }
}
