#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    map<long long, long long> mm;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] % k != 0) {
        long long p = ceil((double)a[i] / k);
        p = p * k - a[i];
        mm[p]++;
      }
    }
    long long ans = 0;
    for (auto i : mm) {
      ans = max(ans, i.first + (i.second - 1) * k);
    }
    if (ans == 0)
      cout << ans << "\n";
    else
      cout << ans + 1 << "\n";
  }
}
