#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k, maxfreq = 0, maxfreqrem = 0, temp = 0, ans = 0;
  cin >> n >> k;
  vector<long long> a(n);
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> temp;
    if (temp % k == 0) continue;
    temp = k - temp % k;
    m[temp]++;
    if (m[temp] >= maxfreq) {
      maxfreq = m[temp];
      maxfreqrem = max(maxfreqrem, temp);
    }
  }
  for (auto i : m) {
    if (i.second == maxfreq) {
      ans = k * (i.second - 1) + i.first + 1;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
