#include <bits/stdc++.h>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const int maxn = 1e5 + 7;
const int INF = 1e9;
const long long INFF = 1e18;
int t, n, x, a[maxn];
int main() {
  scanf("%d", &t);
  while (t--) {
    int l = INF, r = -1, sum = 0;
    scanf("%d%d", &n, &x);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (a[i] % x != 0) {
        l = min(l, i);
        r = max(r, i);
      }
      sum += a[i];
    }
    if (sum % x != 0)
      printf("%d\n", n);
    else if (l == INF)
      printf("%d\n", -1);
    else
      printf("%d\n", max(n - l, r - 1));
  }
  return 0;
}
