#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, k, massimo = 0, val, altro = 0;
    map<long long, long long> d;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      cin >> val;
      if (val % k != 0) {
        auto cerca = d.find(val % k);
        if (cerca != d.end())
          d[val % k]++;
        else
          d[val % k] = 1;
      }
    }
    if (d.size() == 0)
      cout << "0\n";
    else {
      for (auto it = d.begin(); it != d.end(); it++) {
        if (it->second > massimo) {
          massimo = it->second;
          altro = k - it->first;
        }
      }
      cout << (massimo - 1) * k + altro + 1 << endl;
    }
  }
  return 0;
}
