#include <bits/stdc++.h>
using namespace std;
const int N = 200 * 1000 + 20;
long long n, k, a[N], ans;
map<long long, long long> cnt;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++)
      if (a[i] % k) cnt[k - a[i] % k]++;
    for (auto P : cnt) ans = max(ans, (P.second - 1) * k + P.first + 1);
    cout << ans << "\n";
    ans = 0;
    cnt.clear();
  }
  return 0;
}
