#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long a[N], b[N], c[N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, x;
    scanf("%lld%lld", &n, &x);
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    if (sum % x) {
      cout << n << endl;
    } else {
      long long s = -1;
      sum = 0;
      for (long long i = 1; i <= n; i++) {
        sum += a[i];
        if (sum % x) {
          s = max(n - i, s);
        }
      }
      sum = 0;
      for (long long i = n; i >= 1; i--) {
        sum += a[i];
        if (sum % x) {
          s = max(i - 1, s);
        }
      }
      cout << s << endl;
    }
  }
  return 0;
}
