#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int a[n], pre[n], pre1[n], sum = 0, sum1 = 0, ma = 0;
    for (long long int x = 0; x < n; x++) {
      cin >> a[x];
    }
    for (long long int x = 0; x < n; x++) {
      sum += a[x];
      pre[x] = sum;
      if (sum % k != 0) {
        ma = max(ma, x + 1);
      }
    }
    for (long long int x = 0; x < n; x++) {
      long long int d = pre[n - 1 - x] - pre[x];
      if (d % k != 0) {
        ma = max(ma, n - 1 - x);
      }
    }
    if (!ma) {
      cout << -1 << endl;
    } else {
      cout << ma << endl;
    }
  }
}
