#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    map<long long, long long> m;
    for (long long i = 0; i < n; i++) {
      long long q;
      cin >> q;
      if (q % k != 0) {
        long long x = k - (q % k);
        if (m.find(x) != m.end()) {
          m[x]++;
        } else
          m[x] = 0;
      }
    }
    if (!m.empty()) {
      long long res = -999;
      for (auto it : m) {
        long long value = it.first + (k * it.second);
        if (value > res) res = value;
      }
      cout << res + 1 << endl;
    } else
      cout << "0" << endl;
  }
  return 0;
}
