#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, n, k, i, j, x = 0, y = 0, m, flag, ans, val;
  cin >> t;
  long long int a[200001];
  while (t--) {
    ans = 0;
    flag = 0;
    cin >> n >> k;
    for (i = 0; i < n; ++i) {
      cin >> a[i];
    }
    std::map<long long int, long long int> v;
    for (i = 0; i < n; ++i) {
      x = k - (a[i] % k);
      if (a[i] % k != 0) v[x]++;
    }
    m = 0;
    for (auto it = v.begin(); it != v.end(); it++) {
      i = it->first;
      if (v[i] != 0) m = max(((v[i] - 1) * k + i), m);
    }
    if (m != 0)
      cout << m + 1;
    else
      cout << 0;
    v.clear();
    cout << "\n";
  }
  return 0;
}
