#include <bits/stdc++.h>
using namespace std;
bool Prime(long long int n) {
  if (n <= 1) return 0;
  if (n <= 3) return 1;
  if (n % 2 == 0 || n % 3 == 0) return 0;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return 0;
  return 1;
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n, k;
    cin >> n >> k;
    ;
    vector<long long int> ar;
    for (long long int i = 0; i < n; i++) {
      long long int a;
      cin >> a;
      ;
      ar.push_back(a);
    }
    map<long long int, long long int> make_pair;
    long long int p = 0;
    for (long long int i = 0; i <= ar.size() - 1; i++) {
      if (ar[i] % k) {
        long long int d = k - (ar[i] % k);
        if (make_pair[d] == 0) {
          p = max(p, d);
          make_pair[d]++;
        } else {
          long long int s = make_pair[d];
          while (make_pair[d + (k * s)] != 0) s++;
          p = max(p, d + (s * k));
          make_pair[d] = s + 1;
          make_pair[d + (k * s)]++;
        }
      }
    }
    if (p)
      cout << p + 1 << "\n";
    else
      cout << p << "\n";
    ;
  }
  return 0;
}
