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