#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int arr[n], sum = 0, count = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      sum += arr[i];
      if (!(sum % x)) count += 1;
    }
    if (count == n)
      cout << "-1" << endl;
    else if (sum % x)
      cout << n << endl;
    else {
      int p = 0, q = n - 1;
      for (int i = 0; i < n; i++) {
        if (arr[i] % x) {
          p = i;
          break;
        }
      }
      for (int i = n - 1; i > -1; i--) {
        if (arr[i] % x) {
          q = i;
          break;
        }
      }
      int l = min(p + 1, n - q);
      cout << n - l << endl;
    }
  }
}
