#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k, final = 0;
  cin >> n >> k;
  vector<long long> v;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    if (x % k != 0) v.push_back(k - (x % k));
  }
  if (v.size() == 0) {
    cout << 0 << "\n";
    return;
  }
  sort(v.begin(), v.end());
  for (long long i = 0; i < v.size(); i++) {
    long long ans = mp[v[i]] * k + v[i];
    mp[v[i]]++;
    final = max(final, ans);
  }
  cout << final + 1 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; i++) solve();
  return 0;
}
