#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, s, c, d, q, i, j, k, l, m, n, sum = 0, temp = 0, f = 0,
                                                  cnt = 0;
    cin >> n >> k;
    long long arr[n], brr[n];
    for (i = 0; i < n; i++) {
      cin >> l;
      if (l % k == 0)
        arr[i] = 0;
      else {
        arr[i] = ((l / k) * k);
        while (arr[i] < l) arr[i] += k;
        arr[i] -= l;
      }
    }
    sort(arr, arr + n);
    long long o = 0;
    brr[0] = arr[0];
    for (i = 1; i < n; i++) {
      if (arr[i] == arr[i - 1] && arr[i] != 0)
        brr[i] = brr[i - 1] + k;
      else
        brr[i] = arr[i];
    }
    sort(brr, brr + n);
    if (brr[n - 1] == 0)
      cout << 0 << endl;
    else
      cout << brr[n - 1] + 1 << endl;
  }
}
