#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
void QUiCK() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
void Local() {
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
}
void solve() {
  map<long long, long long> MP;
  int n, k;
  cin >> n >> k;
  bool ok = true;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x % k) ok = false;
    x = (k - x % k) % k;
    if (x) MP[x]++;
  }
  if (ok) {
    cout << 0 << '\n';
    return;
  }
  vector<pair<long long, long long> > a;
  for (auto i : MP) a.push_back(make_pair(i.second, i.first));
  sort(a.rbegin(), a.rend());
  long long ans = (a[0].first - 1) * k + a[0].second + 1;
  cout << ans << '\n';
}
int main() {
  QUiCK();
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
