#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t-- > 0) {
    long long n, k;
    cin >> n >> k;
    map<long long, long long> freq;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      x %= k;
      if (x == 0) continue;
      if (freq.find(x) == freq.end()) freq.insert({x, 0});
      freq[x]++;
    }
    if (freq.size() == 0) {
      cout << 0 << "\n";
      continue;
    }
    long long max = freq.begin()->first;
    for (auto itr = freq.begin(); itr != freq.end(); itr++) {
      if (itr->second > freq[max]) max = itr->first;
    }
    cout << (freq[max] - 1) * k + (k - max + 1) << "\n";
  }
}
