#include <bits/stdc++.h>
using namespace std;
long long bs(vector<long long> &a, long long x, long long n) {
  long long start = 0;
  long long end = n - 1;
  long long ans = 0;
  while (start <= end) {
    long long mid = start + (end - start) / 2;
    if (a[mid] > x) {
      end = mid - 1;
    } else if (a[mid] <= x) {
      start = mid + 1;
      ans = (mid + 1);
    }
  }
  return (n - ans);
}
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  map<long long, long long> map;
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    map[v[i] % k]++;
  }
  long long ans = 0, key = 0;
  for (auto &i : map) {
    if (i.first % k != 0) {
      key = k - (i.first % k);
      key += (i.second - 1) * k;
      ans = max(ans, key);
    }
  }
  if (key > 0) ans++;
  cout << ans << endl;
  return;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
