#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long int u;
  cin >> u;
  while (u--) {
    long long int n, f = 0, x, y, ans = -1, k, mx, ans1;
    cin >> n >> k;
    vector<long long int> a;
    map<long long int, long long int> make_pair;
    for (long long int i = 0; i < n; i++) {
      cin >> x;
      if (x % k != 0) a.push_back(x % k);
    }
    sort((a).begin(), (a).end());
    if (a.size() == 0) {
      cout << 0 << endl;
      continue;
    }
    for (long long int i = 0; i < a.size(); i++) {
      make_pair[a[i]]++;
      if (ans < make_pair[a[i]]) {
        ans = make_pair[a[i]];
        mx = a[i];
      }
    }
    ans1 = (ans - 1) * k;
    ans1 += (k - mx) + 1;
    cout << ans1 << endl;
  }
}
