#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  long long a[200005] = {0};
  long long b[200005] = {0};
  while (t--) {
    long long n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      b[i] = a[i] % k == 0 ? 0 : (a[i] / k + 1) * k - a[i];
    }
    long long sum = 0;
    long long s = 1;
    sort(b + 1, b + n + 1);
    for (int i = 1; i <= n; i++) {
      if (b[i] == 0) continue;
      if (b[i] == b[i - 1]) {
        ++s;
        if (s * k + b[i] > sum) sum = s * k + b[i];
      } else {
        s = 0;
        if (b[i] > sum) sum = b[i];
      }
    }
    if (sum != 0)
      cout << 1ll * sum + 1 << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
