#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int T, n, k, a[maxn];
long long ans;
map<int, int> num;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &k);
    num.clear();
    ans = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), num[(k - a[i] % k) % k]++;
    for (auto i : num)
      if (i.first != 0)
        ans = max(ans, 1ll * i.first + 1ll * (i.second - 1) * k);
    if (ans != 0) ans++;
    printf("%lld\n", ans);
  }
  return 0;
}
