#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n, x;
    cin >> n >> x;
    long long int sum = 0, count = -1, max_count = -1;
    vector<int> v(n), dp(n + 1);
    dp[0] = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> v[i];
    }
    bool check = true;
    for (int i = 0; i < n; i++) {
      dp[i + 1] = dp[i] + v[i];
      if (dp[i + 1] % x != 0) {
        check = false;
        count = i + 1;
      }
    }
    if (check) {
      cout << "-1\n";
      continue;
    }
    int j = 0;
    for (int i = n; i >= 1; i--) {
      if (dp[i] % x == 0 && i > count) {
        j = i;
        break;
      }
    }
    int k = 0;
    for (int i = 1; i < n + 1; i++) {
      if (dp[i] % x != 0) {
        k = i;
        break;
      }
    }
    if (j - k > count) count = j - k;
    cout << count << '\n';
  }
}
