#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t-- > 0) {
    int n, k;
    cin >> n >> k;
    int a[n];
    int cnt = 0, sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum = sum + a[i];
      if (a[i] % k == 0) cnt++;
    }
    if (cnt == n) {
      cout << -1 << "\n";
      continue;
    }
    if (sum % k != 0) {
      cout << n << "\n";
      continue;
    }
    int l1 = 0, l2 = 0;
    int temp = sum;
    for (int i = 0; i < n; i++) {
      temp -= a[i];
      if (temp % k != 0) {
        l1 = n - (i + 1);
        break;
      }
    }
    temp = sum;
    for (int i = n - 1; i >= 0; i--) {
      temp -= a[i];
      if (temp % k != 0) {
        l2 = n - (n - i);
        break;
      }
    }
    cout << max(l1, l2) << "\n";
  }
  return 0;
}
