#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t > 0) {
    long long n, k;
    cin >> n >> k;
    map<long long, long long> add;
    long long max_repeat = 0, max_add = 0;
    for (long long i = 0; i < n; i++) {
      long long tmp;
      cin >> tmp;
      add[(k - (tmp % k)) % k]++;
      if (add[k - (tmp % k)] > max_repeat) {
        max_repeat = add[k - (tmp % k)];
      }
    }
    for (auto it : add) {
      if (it.second == max_repeat && it.first + 1 > max_add) {
        max_add = it.first + 1;
      }
    }
    if (max_repeat == 0) {
      cout << 0 << endl;
    } else {
      cout << ((max_repeat - 1) * k) + max_add << endl;
    }
    t--;
  }
  return 0;
}
