#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long int INF = 1e12;
const int N = 1e5 + 1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int arr[n], after[n], len = 0;
    memset(after, 0, sizeof(after));
    int i = 0, j = 0;
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] % x != 0) after[i] = 1;
    }
    for (int i = n - 2; i >= 0; i--) after[i] += after[i + 1];
    while (i < n && j < n) {
      sum += arr[j];
      if (sum % x != 0 || (j < n - 1 && after[j + 1] > 0)) {
        j++;
        len = max(len, j - i);
      } else {
        sum -= arr[i++];
        sum -= arr[j];
      }
    }
    if (len == 0)
      cout << -1 << "\n";
    else
      cout << len << "\n";
  }
  return 0;
}
