#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long n, k;
    cin >> n >> k;
    vector<int> a(n);
    map<int, int> mp;
    for (long long i = 0; i < n; ++i) {
      cin >> a[i];
      mp[a[i] % k]++;
    }
    long long ma = 0;
    long long idx = 0;
    for (auto &p : mp) {
      if (p.first == 0) continue;
      if (ma < p.second) {
        ma = p.second;
        idx = p.first;
      }
    }
    long long ans = k * (ma - 1) + (k - idx);
    if (ans != 0) ans++;
    cout << ans << endl;
  }
  return 0;
}
