#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, k;
    long long y;
    cin >> n >> k;
    map<long long, long long> mp;
    map<long long, long long>::iterator it;
    int flag = 0;
    for (int i = 0; i < n; i++) {
      cin >> y;
      if (y % k) {
        flag = 1;
        mp[y % k]++;
      }
    }
    long long maxcnt = 0;
    long long maxidx = 100000000;
    long long maxx = -1;
    for (it = mp.begin(); it != mp.end(); it++) {
      if (it->second >= maxx) {
        if (it->second == maxx && maxidx > it->first) {
          maxidx = it->first;
        }
        if (it->second > maxx) {
          maxidx = it->first;
        }
        maxx = it->second;
      }
    }
    if (flag == 0) {
      cout << 0 << endl;
    } else {
      cout << k * (maxx)-maxidx + 1 << endl;
    }
  }
}
