#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long k, x;
    cin >> n >> k;
    map<long long, int> mp;
    for (int i = 0; i < n; i++) {
      cin >> x;
      x %= k;
      if (x) mp[k - x]++;
    }
    map<long long, int>::iterator it;
    long long mx = 0;
    for (it = mp.begin(); it != mp.end(); it++) {
      long long temp = (it->second - 1) * k + it->first;
      mx = max(mx, temp);
    }
    if (mx) mx++;
    cout << mx << endl;
  }
  return 0;
}
