#include <bits/stdc++.h>
using namespace std;
long long int n, m, q;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int T = 1;
  cin >> T;
  while (T--) {
    long long int x, i, j;
    cin >> n >> x;
    long long int a[n], cnt = 0, sum = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] % x != 0) cnt++;
      sum += a[i];
    }
    if (cnt == 0)
      cout << -1 << "\n";
    else {
      long long int sum = 0, flag = -1, ans = 0;
      for (i = 0; i < n; i++) {
        sum = (sum + a[i]) % x;
        if (sum != 0) {
          ans = max(ans, i + 1);
          if (flag == -1) flag = i;
        } else {
          if (flag != -1) ans = max(ans, i - flag);
        }
      }
      cout << ans << "\n";
    }
  }
}
