#include <bits/stdc++.h>
using namespace std;
const long long int hell = (long long int)(1e18 + 100LL);
int main() {
  long long int t, i, j, k, m, n, x, y;
  t = 1;
  cin >> t;
  while (t--) {
    long long int flag = 0;
    long long int K;
    cin >> n >> K;
    vector<long long int> ar(n, 0);
    long long int sum = 0;
    for (i = 0; i < n; i++) {
      cin >> x;
      ar[i] = x;
      sum += x;
    }
    long long int ans = 0;
    x = sum;
    if (sum % K != 0) {
      cout << n << "\n";
      continue;
    }
    for (i = 0; i < n; i++) {
      x -= ar[i];
      if (x % K != 0) {
        ans = max(ans, n - 1 - i);
        break;
      }
    }
    x = sum;
    for (i = n - 1; i >= 0; i--) {
      x -= ar[i];
      if (x % K != 0) {
        ans = max(ans, i);
        break;
      }
    }
    if (ans == 0) {
      cout << "-1"
           << "\n";
      continue;
    }
    cout << ans << "\n";
  }
  return 0;
}
