#include <bits/stdc++.h>
using namespace std;
long long ar[100010];
unordered_map<long long, long long> um;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, n, x, ans, y, prev;
  scanf("%lld", &t);
  long long sm = 0;
  while (t--) {
    scanf("%lld", &n);
    scanf("%lld", &x);
    for (int i = 0; i < n; i++) {
      scanf("%lld", &ar[i]);
    }
    sm = 0;
    prev = ans = -1;
    for (long long i = 0; i < n; i++) {
      sm = (sm + ar[i]) % x;
      if (sm && prev == -1) prev = i;
      if (sm)
        ans = i + 1;
      else if (prev != -1)
        ans = max(ans, i - prev);
    }
    cout << ans << "\n";
  }
  return 0;
}
