#include <bits/stdc++.h>
using namespace std;
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cerr << b << " = " << a << " ";
    call(++it, ed, rest...);
  }
};
const double PI = 2.0 * acos(0.0);
string a;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long int k;
    cin >> n >> k;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      x %= k;
      if (x > 0) {
        mp[k - x]++;
      }
    }
    long long int cycle = 0, num = -1;
    for (auto it : mp) {
      int x = it.first;
      int y = it.second;
      if (y > cycle) {
        num = x;
        cycle = y;
      } else if (y == cycle && num < x) {
        num = x;
      }
    }
    234;
    long long int ans = k * (cycle - 1LL) + num + 1;
    if (cycle == 0) {
      ans = num + 1;
    }
    cout << ans << endl;
  }
}
