#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 7;
const int INF = INT_MAX;
const double EPS = 10;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  map<int, int> cnt;
  while (T--) {
    int n, k;
    cin >> n >> k;
    cnt.clear();
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      if (x % k == 0) continue;
      if (x <= k)
        cnt[k - x]++;
      else
        cnt[k - x % k]++;
    }
    long long ans = 0;
    for (auto i : cnt) {
      if (i.first == 0) continue;
      ans = max(ans, (long long)(i.second - 1) * k + i.first);
    }
    if (ans)
      cout << ans + 1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
