#include <bits/stdc++.h>
using namespace std;
bool s_end(size_t c) { return (c == string ::npos) ? true : false; }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int a[n];
    long long sumf = 0;
    long long sumb = 0;
    int forw = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sumf += a[i];
      if (sumf % x) forw = (i + 1);
    }
    reverse(a, a + n);
    int backw = 0;
    for (int i = 0; i < n; i++) {
      sumb += a[i];
      if (sumb % x) backw = (i + 1);
    }
    if (!max(forw, backw))
      cout << -1 << endl;
    else
      cout << max(forw, backw) << endl;
  }
  return 0;
}
