#include <bits/stdc++.h>
int main() {
  int t, size, x;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d %d", &size, &x);
    int arr[size];
    int flag = 0, sum = 0;
    for (int j = 0; j < size; j++) {
      scanf("%d", &arr[j]);
      if ((arr[j] % x) != 0) {
        flag = 1;
      }
      sum = sum + arr[j];
    }
    if (flag == 0) {
      printf("-1\n");
    } else if (flag == 1 && (sum % x) != 0) {
      printf("%d\n", size);
    } else {
      for (int k = 0; k < size; k++) {
        if (((arr[k] % x) != 0) || ((arr[size - k - 1] % x) != 0)) {
          printf("%d\n", size - k - 1);
          break;
        }
      }
    }
  }
}
