#include <bits/stdc++.h>
using namespace std;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
void solve() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  map<int, int> a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[(k - t % k) % k]++;
  }
  long long ans = 0;
  for (map<int, int>::iterator it = a.begin(); it != a.end(); it++) {
    if (it->first == 0) continue;
    ans = max(ans, it->first + 1ll * (it->second - 1) * k);
  }
  if (ans == 0) {
    cout << ans << endl;
  } else {
    cout << ans + 1 << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
