#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long test;
  cin >> test;
  while (test--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> v(n);
    map<long long, long long> mpp;
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
      v[i] %= k;
      if (v[i] == 0) continue;
      mpp[v[i]]++;
    }
    long long ans = 0;
    for (auto& [key, val] : mpp) {
      long long re = (k - key) + (val - 1) * k + 1;
      ans = max(re, ans);
    }
    cout << ans << "\n";
  }
  return 0;
}
