#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
void out(vector<int> x) {
  for (int i = 0; i < (int)x.size(); ++i) cout << x[i] << " ";
}
int k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n >> k;
    vector<long long> a(n);
    for (auto &it : a) cin >> it;
    map<long long, long long> mp;
    for (int i = 0; i < n; ++i) {
      if (a[i] % k) {
        mp[a[i] % k]++;
      }
    }
    long long ans = 0;
    if (mp.empty()) {
      cout << "0\n";
      continue;
    }
    for (auto it : mp) {
      ans = max(ans, k - it.first + k * (it.second - 1));
    }
    cout << ans + 1 << "\n";
  }
}
