#include <bits/stdc++.h>
using namespace std;
long long pwr(long long a, long long b);
long long pwr(long long a, long long b, long long m);
int baap[200002];
int prime[1000002];
int find(int i);
bool Union(int x, int y);
long long inv(long long x) { return pwr(x, 1000000007 - 2, 1000000007); }
void init();
long long max(long long x, long long y, long long z) {
  return max(x, max(y, z));
}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1};
void solve() {
  long long n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  ;
  map<int, int> freq;
  long long mx = INT_MIN, mxi = 0;
  for (int i = 0; i < n; i++) {
    int x = (k - (a[i] % k)) % k;
    freq[x]++;
  }
  for (auto i : freq) {
    if (i.first == 0) continue;
    if (i.second >= mx) {
      mx = i.second;
      mxi = i.first;
    }
  }
  if (mxi == 0)
    cout << 0;
  else {
    long long ans = k * (mx - 1) + (mxi + 1);
    cout << ans;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int _ = 1;
  cin >> _;
  while (_--) {
    solve();
    cout << endl;
  }
}
long long pwr(long long a, long long b) {
  if (b == 0) return 1;
  long long c = pwr(a, b / 2);
  c = c * c;
  if (b % 2) return c * a;
  return c;
}
long long pwr(long long a, long long b, long long m) {
  if (b == 0) return 1;
  long long c = pwr(a, b / 2, m) % m;
  c = (c * c) % m;
  if (b % 2) return (c * a % m) % m;
  return c;
}
int find(int i) {
  if (baap[i] != i) baap[i] = find(baap[i]);
  return baap[i];
}
bool Union(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return false;
  baap[x] = y;
  return true;
}
void init() {
  for (long long i = 2; i < 1000002; i++) {
    if (prime[i]) continue;
    for (long long j = 2 * i; j < 1000002; j += i) prime[j] = i;
  }
}
