#include <bits/stdc++.h>
using namespace std;
void i_o() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  map<int, int> count;
  int mx = 0;
  for (auto &it : v) {
    if (it % k == 0) continue;
    ++count[k - it % k];
    mx = max(mx, count[k - it % k]);
  }
  long long ans = 0;
  for (auto x : count) {
    if (x.second == mx) {
      ans = k * 1ll * (x.second - 1) + x.first + 1;
    }
  }
  cout << ans << "\n";
}
int main() {
  i_o();
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
