#include <bits/stdc++.h>
using namespace std;
int recur_depth = 0;
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type operator<<(
    Ostream& os, const Cont& v) {
  os << "[";
  for (auto& x : v) {
    os << x << ", ";
  }
  return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int a[n];
  long long int maxturn = 1;
  map<long long int, long long int> cnt;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] %= k;
    cnt[k - a[i]]++;
    if (a[i] != 0) maxturn = max(maxturn, cnt[k - a[i]]);
  }
  long long int ans = 1ll * ((maxturn - 1) * (k));
  ;
  long long int turns = -1;
  for (auto e : cnt) {
    if (e.first == k) break;
    if (e.second - maxturn >= 0) {
      turns = max(turns, 1LL * e.first);
    }
  }
  ans += turns + 1;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  ;
  int t;
  cin >> t;
  while (t--) solve();
}
