#include <bits/stdc++.h>
using namespace std;
int t, n, nrne;
long long x, k, a[200001];
int main() {
  cin >> t;
  for (int tt = 1; tt <= t; tt++) {
    cin >> n >> k;
    x = nrne = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      a[i] = (k - a[i] % k) % k;
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
      if (a[i] != 0) {
        if (a[i] != a[i + 1]) {
          x = max(x, nrne * k + a[i] + 1);
          nrne = 0;
        } else
          nrne++;
      }
    }
    cout << x << endl;
  }
  return 0;
}
