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