#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265359;
const long long mod = 998244353;
const long long INF = (long long)(1e9 + 7);
long long power(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long cnt = 0;
    long long a[n];
    map<long long, long long> mp;
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      a[i] %= k;
      a[i] = (k - a[i]) % k;
      if (a[i] != 0) mp[a[i]]++;
    }
    long long mx = 0;
    long long mxid = -1;
    if (mp.empty()) {
      cout << "0" << endl;
      continue;
    }
    for (auto u : mp) {
      if (u.second > mx) {
        mx = u.second;
        mxid = u.first;
      } else if (u.second == mx) {
        mxid = max(mxid, u.first);
      }
    }
    cnt += (mx - 1) * k + mxid + 1;
    cout << cnt << endl;
  }
  return 0;
}
