#include <bits/stdc++.h>
using namespace std;
long long int b_s(long long int a[], long long int l, long long int r,
                  long long int result) {
  long long int m;
  while (r >= l) {
    m = l + (r - l) / 2;
    if (a[m] == result)
      return m;
    else if (a[m] > result)
      r = m - 1;
    else
      l = m + 1;
  }
  return -1;
}
void solve() {
  long long int x, y, n, k, b, c, d, i, l, f;
  vector<long long int> v;
  cin >> n >> k;
  map<long long int, long long int> m;
  for (i = 0; i < n; i++) {
    cin >> b;
    c = b % k;
    if (c) {
      c = k - c;
      if (m.count(c))
        m[c]++;
      else
        m[c] = 1;
    }
  }
  for (__typeof(m.begin()) it = m.begin(); it != m.end(); it++) {
    i = (*it).first;
    f = (*it).second;
    v.push_back(i + 1 + (f - 1) * k);
  }
  sort((v).begin(), (v).end());
  if (v.size())
    cout << v.back() << '\n';
  else
    cout << 0 << '\n';
}
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
