#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int sm = 0;
    long long int n, x;
    cin >> n >> x;
    long long int a[n + 5];
    int f = 0;
    long long int ans = -1;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      sm += a[i];
      if (sm % x != 0) {
        ans = max(ans, max(i + 1, n - i - 1));
      }
    }
    cout << ans << endl;
  }
  return 0;
}
