#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int a[n];
    int sum = 0;
    for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
    if (sum % x != 0)
      cout << n << endl;
    else {
      int idx = n - 1;
      for (int i = 0; i < n; i++) {
        if (a[i] % x != 0) {
          idx = i;
          break;
        }
      }
      int j = 0;
      for (int i = n - 1; i >= 0; i--) {
        if (a[i] % x != 0) {
          j = i;
          break;
        }
      }
      int ans = max(n - idx - 1, j);
      if (ans == 0)
        cout << -1 << endl;
      else
        cout << ans << endl;
    }
  }
}
