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