#include <bits/stdc++.h>
using namespace std;
void cerr_(istream_iterator<string> it) { (void)it; }
template <class T, class... Args>
void cerr_(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  cerr_(++it, args...);
}
template <class T, class S>
ostream &operator<<(ostream &os, const pair<T, S> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << '{';
  string sep;
  for (const auto &x : v) os << sep << x, sep = ", ";
  return os << '}';
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << '{';
  string sep;
  for (const auto &x : s) os << sep << x, sep = ", ";
  return os << '}';
}
template <class T, class S>
ostream &operator<<(ostream &os, const map<T, S> &m) {
  os << '{';
  string sep;
  for (const auto &x : m) os << sep << x, sep = ", ";
  return os << '}';
}
template <class T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
  os << '{';
  string sep;
  for (const auto &x : arr) os << sep << x, sep = ", ";
  return os << '}';
}
void run_test() {
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a % k != 0) m[(k - a % k) % k]++;
  }
  long long ans = 0;
  for (auto [x, cnt] : m) {
    ans = max(ans, (long long)x + (long long)(cnt - 1) * k + 1);
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t_;
  cin >> t_;
  while (t_--) run_test();
  return 0;
}
