#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1), EPS = 1e-7;
const int dx[] = {-1, 0, 0, 1, -1, 1, 1, -1};
const int dy[] = {0, -1, 1, 0, 1, 1, -1, -1};
long long gcd(long long x, long long y) { return (!y) ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return ((x / gcd(x, y)) * y); }
long long power(long long x, long long y) {
  if (y == 0) return 1;
  if (y == 1) return x;
  long long r = power(x, y / 2);
  return r * r * power(x, y % 2);
}
void file() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
struct Data {
  long long from, to, w;
  Data(long long f, long long t, long long ww) {
    from = f;
    to = t;
    w = ww;
  }
  bool operator<(const Data &rhs) const { return w > rhs.w; }
};
int main() {
  file();
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    map<int, int> mp;
    int mx = 0;
    for (int i = 0; i < n; ++i) {
      if (v[i] % k != 0) {
        ++mp[k - v[i] % k];
        mx = max(mx, mp[k - (v[i] % k)]);
      }
    }
    long long ans = 0;
    for (const auto &ch : mp) {
      if (ch.second == mx) ans = (long long)k * (ch.second - 1) + ch.first + 1;
    }
    cout << ans << '\n';
  }
}
