#include <bits/stdc++.h>
using namespace std;
long long fastexp(long long b, long long e) {
  long long ans = 1;
  long long lpow = b;
  while (e) {
    if (e & 1) ans *= lpow;
    lpow *= lpow;
    e = (e >> 1);
  }
  return ans;
}
bool isprime(long long x) {
  for (long long i = 2; i <= sqrt(x); i++)
    if (x % i == 0) return false;
  return true;
}
void solve() {
  long long ele, n, k, lv, ans = 0;
  long long maxr = -1, mocc = 0;
  bool need = false;
  cin >> n >> k;
  map<long long, long long> um;
  um.clear();
  for (lv = 1; lv <= n; lv++) {
    cin >> ele;
    if (ele % k) {
      need = true;
      ++um[k - (ele % k)];
      mocc = max(mocc, um[k - (ele % k)]);
    }
  }
  if (need == false) {
    cout << 0;
    return;
  }
  maxr = -1;
  for (auto it = um.rbegin(); it != um.rend(); it++) {
    if (it->second == mocc) {
      maxr = it->first;
      break;
    }
  }
  ans = (mocc - 1) * k + (maxr + 1);
  cout << ans;
}
int main() {
  long long tc;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> tc;
  while (tc--) {
    solve();
    cout << "\n";
  }
}
