#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int sum = 0;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum += a[i];
    }
    int lft = 0, ryt = 0;
    while (lft < n && a[lft] % x == 0) lft++;
    while (ryt < n && a[n - ryt - 1] % x == 0) ryt++;
    if (sum % x != 0)
      cout << n << "\n";
    else
      cout << n - min(lft, ryt) - 1 << "\n";
  }
}
