#include <bits/stdc++.h>
using namespace std;
double pie = 3.14159265358979323846;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T, i, j, j1, k = 0, n, m, co = 0, check, mi, l;
  long long int ans = 0;
  cin >> T;
  for (i = 0; i < T; i++) {
    cin >> n >> l;
    long long int a[n], b[n + 1];
    for (j = 0; j < n; j++) cin >> a[j];
    b[0] = 0;
    for (j = 0; j < n; j++) b[j + 1] = a[j] + b[j];
    m = 0;
    j = 0;
    k = 0;
    ans = a[0];
    if ((b[n] - b[0]) % l != 0)
      m = n;
    else {
      co = n + 1;
      for (j = 0; j < n; j++) {
        if (a[j] % l == 0)
          continue;
        else if (j + 1 < n) {
          co = j + 1;
          break;
        }
      }
      long long int x = -1;
      for (j = n - 1; j >= 0; j--) {
        if (a[j] % l == 0)
          continue;
        else if (j - 1 >= 0) {
          x = j - 1;
          break;
        }
      }
      co = n - co;
      x = x + 1;
      m = max(m, co);
      m = max(m, x);
    }
    if (m == 0)
      cout << -1 << "\n";
    else
      cout << m << "\n";
  }
}
