#include <bits/stdc++.h>
int main() {
  int casos, n, i, suma, l, u, arr[100000], x;
  ;
  scanf("%d", &casos);
  while (casos--) {
    scanf("%d %d", &n, &x);
    suma = 0;
    for (i = 0; i < n; ++i) {
      scanf("%d", arr + i);
      arr[i] %= x;
      suma += arr[i];
    }
    if (suma % x)
      printf("%d\n", n);
    else {
      l = 0;
      while (l < n && arr[l] == 0) ++l;
      if (l == n)
        printf("-1\n");
      else {
        u = n - 1;
        while (n >= 0 && arr[u] == 0) --u;
        printf("%d\n", (n - l - 1 > u) ? n - l - 1 : u);
      }
    }
  }
  return 0;
}
