#include <bits/stdc++.h>
using namespace std;
signed main() {
  std::ios::sync_with_stdio(false);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    vector<long long int> arr(n);
    map<long long int, long long int> m;
    for (long long int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] % k != 0) {
        m[arr[i] % k]++;
      }
    }
    long long int ans = 0;
    for (auto x : m) {
      long long int val = k - x.first + (x.second - 1) * k;
      ans = max(val, ans);
    }
    if (ans != 0)
      cout << ans + 1 << "\n";
    else {
      cout << 0 << "\n";
    }
  }
  return 0;
}
