#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long test = 1;
  cin >> test;
  while (test--) {
    long long n, k, i, j;
    cin >> n >> k;
    vector<long long> a(n);
    map<long long, long long> mp;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] % k != 0) mp[k - (a[i] % k)]++;
    }
    if (mp.empty()) {
      cout << 0 << '\n';
      continue;
    }
    long long ans = 0;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      ans = max(ans, (it->second - 1) * k + it->first);
    }
    cout << ans + 1 << '\n';
  }
  return 0;
}
