#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) {
      if (a[i] % k != 0) {
        a[i] = k - (a[i] % k);
      } else
        a[i] = 0;
    }
    sort(a.begin(), a.end());
    int i = 0;
    while (i < n && a[i] == 0) ++i;
    int cnt = 1, maxCnt = 1, rem = 0;
    while (i < n) {
      if (a[i] == a[i - 1]) {
        ++cnt;
      } else {
        if (cnt >= maxCnt) {
          maxCnt = cnt;
          rem = a[i - 1];
        }
        cnt = 1;
      }
      ++i;
    }
    if (cnt >= maxCnt) {
      maxCnt = cnt;
      rem = a[i - 1];
    }
    ll ans = 0;
    if (rem != 0) {
      ans = (ll)(maxCnt - 1) * k + rem + 1;
    }
    cout << ans << '\n';
  }
  return 0;
}
