#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, k;
  cin >> n >> k;
  map<int, int> counts;
  counts[0] = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int rem = x % k;
    int missing = rem == 0 ? 0 : (k - rem);
    counts[missing]++;
  }
  auto it = counts.begin();
  long long rec = 0, record = 0;
  for (it++; it != counts.end(); it++) {
    if (it->second > record) {
      record = it->second - 1;
      rec = it->first + 1;
    }
  }
  long long moves = record * k + rec;
  cout << moves << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve();
}
