#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ar[n];
    int divisibleCount = 0;
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
      if (ar[i] % k == 0) divisibleCount++;
    }
    if (divisibleCount == n) {
      cout << 0 << endl;
      continue;
    }
    sort(ar, ar + n);
    long long int maximim = 0;
    map<long long int, long long int> mymap;
    for (int i = 0; i < n; i++) {
      if (ar[i] % k != 0) {
        long long int number = k - ar[i] % k;
        if (mymap.find(number) == mymap.end()) {
          mymap[number]++;
          maximim = max(number, maximim);
        } else {
          long long int count = mymap[number];
          maximim = max(number + (count * k * 1ll), maximim);
          mymap[number]++;
        }
      }
    }
    cout << maximim + 1 << endl;
  }
  return 0;
}
