#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
int T, n, m, x;
int sum[N], A[N];
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> x;
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &A[i]);
      sum[i] = sum[i - 1] + A[i];
    }
    if (sum[n] % x != 0) {
      printf("%d\n", n);
      continue;
    }
    int l = 1;
    while (l <= n && A[l] % x == 0) l++;
    int r = 1;
    while (r <= n && A[n - r + 1] % x == 0) r++;
    int ans = n - min(l, r);
    if (ans)
      printf("%d\n", ans);
    else
      printf("-1\n");
  }
  return 0;
}
