#include <bits/stdc++.h>
using namespace std;
long long t, n, k, arr[200005], maks, tmp, num;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n >> k;
    map<int, int> m;
    maks = 0;
    num = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      arr[i] %= k;
      if (arr[i] == 0) continue;
      m[k - arr[i]]++;
      if (m[k - arr[i]] > maks) {
        maks = m[k - arr[i]];
        num = k - arr[i];
      } else if (m[k - arr[i]] == maks) {
        num = max(num, k - arr[i]);
      }
    }
    if (maks == 0) {
      cout << 0 << "\n";
      continue;
    }
    cout << k * (maks - 1) + num + 1 << "\n";
  }
  return 0;
}
