#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, temp;
map<long long, long long> cnt;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    cnt.clear();
    for (long long i = 0; i < n; i++) {
      cin >> temp;
      temp %= k;
      if (temp != 0) {
        temp = k - temp;
        if (cnt.find(temp) == cnt.end()) cnt[temp] = 0;
        cnt[temp]++;
      }
    }
    ans = 0;
    for (auto it = cnt.begin(); it != cnt.end(); it++) {
      ans = max(ans, (it->second - 1ll) * k + it->first);
    }
    if (ans) ans++;
    cout << ans << "\n";
  }
}
