#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int max1 = n;
    int max2 = -1;
    int pre[n + 1];
    pre[0] = 0;
    for (int i = 1; i <= n; i++) {
      int y;
      cin >> y;
      pre[i] = pre[i - 1] + (y % x);
      pre[i] %= x;
    }
    for (int i = n - 1; i >= 0; i--) {
      if (pre[i] != pre[n]) {
        max2 = i;
        break;
      }
    }
    int maxim = -1;
    for (int i = 0; i < n; i++) {
      if (pre[i] == pre[n])
        maxim = (maxim > max2 - i ? maxim : max2 - i);
      else
        maxim = (maxim > n - i ? maxim : n - i);
    }
    cout << maxim << "\n";
  }
}
