#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    int arr[n];
    vector<int> v, vp;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] % k) v.push_back(k - arr[i] % k);
    }
    map<int, int> mp, mp2;
    set<int> st;
    for (auto e : v) {
      st.insert(e);
      mp[e]++;
    }
    n = v.size();
    while (vp.size() < n) {
      vector<int> p;
      for (auto e : st) {
        vp.push_back(e);
        mp2[e]++;
        if (mp[e] == mp2[e]) p.push_back(e);
      }
      for (auto e : p) st.erase(st.find(e));
    }
    long long int ans = 0;
    if (vp.size() > 0) ans += (vp[0] + 1);
    for (int i = 1; i < n; i++) {
      if (vp[i] > vp[i - 1])
        ans += (vp[i] - vp[i - 1]);
      else
        ans += (k - vp[i - 1] + vp[i]);
    }
    cout << ans << endl;
  }
}
