#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int count = 0, n, k, i;
    cin >> n >> k;
    vector<int> a(n);
    for (i = 0; i < n; i++) cin >> a[i];
    map<int, int> m;
    for (i = 0; i < n; i++) {
      m[k - (a[i] % k)]++;
    }
    for (auto x : m) {
      if (x.first != k) {
        long long int val = x.first + 1;
        val += (x.second - 1) * k;
        count = max(count, val);
      }
    }
    cout << count << endl;
  }
}
