#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d\n", &t);
  while (t--) {
    long long n, k;
    scanf("%lld %lld", &n, &k);
    map<long long, long long> cnt;
    vector<int> arr(n);
    for (auto &a : arr) scanf("%d", &a);
    long long mx = 0;
    for (auto &it : arr) {
      if (it % k == 0) continue;
      cnt[k - it % k]++;
      mx = max(mx, cnt[k - it % k]);
    }
    long long res = 0;
    for (auto [key, value] : cnt) {
      if (value == mx) res = max(res, k * (value - 1) + key + 1);
    }
    printf("%lld\n", res);
  }
  return 0;
}
