#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long int n, x, sum = 0, k = 0;
    cin >> n >> x;
    long int a[n], b1 = 0, b2 = 0, c = n - 1;
    for (long int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
      if (a[i] % x == 0) k++;
    }
    if (sum % x != 0)
      cout << n << endl;
    else {
      if (k == n)
        cout << "-1 \n";
      else {
        while (a[b1] % x == 0) b1++;
        while (a[c] % x == 0) {
          c--;
          b2++;
        }
        if (b1 >= b2)
          cout << n - 1 - b2 << endl;
        else
          cout << n - 1 - b1 << endl;
      }
    }
  }
}
