#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int flag[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      cin >> flag[i];
      flag[i] %= x;
      sum += flag[i];
      sum %= x;
    }
    if (sum) {
      cout << n << endl;
      continue;
    }
    int bj = -1, len = -1;
    for (int i = 1; i <= n; i++) {
      if (flag[i]) {
        bj = i;
        break;
      }
    }
    if (bj != -1) {
      if (n == bj)
        len = -1;
      else
        len = max(n - bj, len);
    }
    for (int i = n; i >= 1; i--) {
      if (flag[i]) {
        if (i > 1)
          len = max(len, i - 1);
        else
          len = max(len, -1);
        break;
      }
    }
    cout << len << endl;
  }
  return 0;
}
