#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
void solve() {
  int n, x, ans = -1, sum = 0;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    a[i] %= x, sum += a[i];
    if (a[i]) ans = 0;
  }
  if (ans == -1)
    puts("-1");
  else if (sum % x)
    printf("%d\n", n);
  else {
    int l = 1, r = n;
    while (l <= n && a[l] == 0) l += 1;
    while (r > l && a[r] == 0) r -= 1;
    printf("%d\n", max(n - l, r - 1));
  }
}
int main() {
  int t;
  for (scanf("%d", &t); t >= 1; t--) solve();
}
