#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 4;
long long n, k;
set<int> st;
map<int, long long> mp;
void solve() {
  cin >> n >> k;
  st.clear();
  mp.clear();
  long long mx = 0, idx = k;
  for (long long i = 0, x; i < n; i++) {
    cin >> x;
    st.insert(x % k);
    mp[x % k]++;
    if (x % k) mx = max(mx, mp[x % k]);
  }
  if (mx == 0) {
    cout << 0 << '\n';
    return;
  }
  for (pair<int, int> p : mp) {
    long long i, x;
    tie(i, x) = p;
    if (i == 0) continue;
    if (mx == x) idx = min(idx, i);
  }
  cout << (mx - 1) * k + k - idx + 1 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  int tt;
  cin >> tt;
  while (tt--) solve();
}
