#include <bits/stdc++.h>
using namespace std;
long long res, x, test, n, k, q[200005];
multiset<int> w;
multiset<int>::iterator e;
int main() {
  cin >> test;
  while (test--) {
    cin >> n >> k;
    res = x = 0;
    for (int i = 0; i < n; ++i) {
      cin >> q[i];
      if (q[i] % k) {
        w.insert(k - q[i] % k);
      }
    }
    while (!w.empty()) {
      e = w.lower_bound(x);
      if (e == w.end()) {
        e = w.begin();
      }
      if (*e >= x) {
        res += *e - x + 1;
      } else {
        res += *e + k - x + 1;
      }
      x = (*e + 1) % k;
      w.erase(e);
    }
    cout << res << "\n";
  }
}
