#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll pwr(ll x, ll n) {
  if (n == 0) {
    return 1;
  }
  if (n & 1) {
    return mul(x, pwr(mul(x, x), (n - 1) / 2));
  } else {
    return pwr(mul(x, x), n / 2);
  }
}
ll modinv(ll n) { return pwr(n, mod - 2); }
ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
void speed_solve() {
  ll n, k;
  cin >> n >> k;
  ll a[n];
  map<ll, ll> f;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    ll needed = (k - a[i] % k) % k;
    f[needed]++;
  }
  ll mx = 0;
  for (auto it : f) {
    if (it.first) {
      mx = max(mx, it.first + (it.second - 1) * k);
    }
  }
  cout << (mx > 0 ? mx + 1 : mx) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll test_cases = 1;
  cin >> test_cases;
  for (ll i = 0; i < test_cases; i++) {
    speed_solve();
  }
  return 0;
}
