#include <bits/stdc++.h>
using namespace std;
int t;
void abc() {
  int n, k;
  long long j, ans = 0;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i], a[i] = a[i] / k * k + k - a[i];
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++)
    if (a[i] == k)
      break;
    else {
      if (i && a[i] == a[i - 1])
        j += k;
      else
        j = 1;
      ans = max(ans, a[i] + j);
    }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) abc();
  return 0;
}
