#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int req = 0; req < t; ++req) {
    int64_t n, k;
    cin >> n >> k;
    vector<int64_t> a(n);
    map<int64_t, int64_t> mod_counters;
    int64_t max_diff = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      if (a[i] % k == 0) {
        continue;
      }
      int64_t min_diff = k - a[i] % k;
      max_diff = max(min_diff + mod_counters[min_diff] * k, max_diff);
      ++mod_counters[min_diff];
    }
    cout << ((max_diff == 0) ? 0 : max_diff + 1) << "\n";
  }
  return 0;
}
