#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    map<long long, long long> mp;
    long long mam = 0, indx = -1;
    for (long long i = 0, u; i < n; i++) {
      cin >> u;
      if (u % k == 0) continue;
      mp[k - (u % k)]++;
      if (mp[k - (u % k)] >= mam) {
        if (mp[k - (u % k)] > mam) {
          mam = mp[k - (u % k)];
          indx = k - (u % k);
        } else {
          indx = max(indx, k - (u % k));
        }
      }
    }
    if (indx == -1)
      cout << 0 << " \n";
    else
      cout << (mam - 1) * k + indx + 1 << " \n";
  }
  return 0;
}
