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