#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
read:
  while (t--) {
    int n, m, sum = 0, cnt = 0;
    cin >> n >> m;
    vector<int> a(n + 1), b, c;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      sum += a[i];
      if (a[i] % m == 0) {
        cnt++;
      }
    }
    if (cnt == n) {
      cout << -1 << endl;
      goto read;
    }
    if (sum % m != 0) {
      cout << n << endl;
      goto read;
    }
    int f = 0, l = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] % m == 0) {
        f++;
      } else {
        f++;
        break;
      }
    }
    for (int i = n; i >= 1; i--) {
      if (a[i] % m == 0) {
        l++;
      } else {
        l++;
        break;
      }
    }
    ans = min(f, l);
    cout << n - ans << endl;
  }
  return 0;
}
