#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  map<int, int> cnt;
  for (int& e : a) {
    cin >> e;
    e %= k;
    if (e == 0) continue;
    e = k - e;
    cnt[e]++;
  }
  ll ans = -1;
  for (auto p : cnt) ans = max(ans, p.first + 1LL * (p.second - 1) * k);
  cout << ans + 1 << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
