#include <bits/stdc++.h>
using namespace std;
void cp() {}
void solve() {
  long long a, n, k, mxkey = 0, mxval = 0;
  cin >> n >> k;
  map<int, int> m;
  for (int i = (0); i < (n); i++) {
    cin >> a;
    if (a % k == 0) continue;
    m[k - (a % k)]++;
    if (m[k - (a % k)] > mxval) {
      mxval = m[k - (a % k)];
      mxkey = k - (a % k);
    }
  }
  long long ans = 0;
  for (auto [key, value] : m) {
    if (value == mxval) {
      ans = k * 1ll * (value - 1) + key + 1;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}
