#include <bits/stdc++.h>
using namespace std;
template <typename H>
bool chmin(H& v1, const H v2) {
  if (v1 > v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H>
bool chmax(H& v1, const H v2) {
  if (v1 < v2) {
    v1 = v2;
    return true;
  }
  return false;
}
template <typename H>
void read(H& head) {
  cin >> head;
}
template <typename H, typename... T>
void read(H& head, T&... tail) {
  cin >> head;
  read(tail...);
}
template <typename H>
void write(H head) {
  cout << head << '\n';
}
template <typename H, typename... T>
void write(H head, T... tail) {
  cout << head << " ";
  write(tail...);
}
template <typename... T>
void die(T... tok) {
  write(tok...);
  exit(0);
}
void solve() {
  int n, k;
  read(n, k);
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) {
    read(a[i]);
    a[i] = (k - a[i] % k) % k;
  }
  multiset<int> m(begin(a), end(a));
  while (m.find(0) != m.end()) m.erase(m.find(0));
  long long cur = 0;
  while (m.size()) {
    auto it = m.upper_bound(cur % k);
    if (it == m.end()) {
      it = m.begin();
      cur += k - cur % k;
    }
    cur += (*it - cur % k);
    m.erase(it);
  }
  if (cur) ++cur;
  write(cur);
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int t;
  read(t);
  for (int i = 0; i < (t); ++i) solve();
}
