#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long ans = 0;
    map<long long, long long> mp;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      x %= k;
      if (x == 0) continue;
      x = k - x;
      long long cur = mp[x];
      mp[x]++;
      ans = max(ans, x + k * cur + 1);
    }
    cout << ans << "\n";
  }
  return 0;
}
