#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int q;
  cin >> q;
  for (int qq = 0; qq < q; qq++) {
    int n, x;
    cin >> n >> x;
    vector<int> arr;
    size_t sum = 0;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      sum += a;
      arr.push_back(a);
    }
    bool isND = false;
    int indR = 1000000;
    int indL = -100000;
    for (int i = 0; i < n; i++) {
      if (arr[i] % x != 0) {
        indR = i;
        isND = true;
        break;
      }
    }
    for (int i = n - 1; i != 0; i--) {
      if (arr[i] % x != 0) {
        indL = i;
        isND = true;
        break;
      }
    }
    indL = n - indL - 1;
    indL++;
    indR++;
    if (sum % x != 0)
      cout << n << std::endl;
    else {
      if (isND)
        cout << max(n - indR, n - indL) << std::endl;
      else
        cout << -1 << std::endl;
    }
  }
}
