#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    int arr[n];
    std::vector<long long> v;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] % k != 0) v.push_back(arr[i]);
    }
    sort(v.begin(), v.end());
    map<long long, long long> m;
    long long res = 0;
    for (int i = 0; i < v.size(); i++) {
      long long temp = k - v[i] % k;
      if (m.find(temp) != m.end()) temp = m[temp] + k;
      m[k - v[i] % k] = temp;
      res = max(res, temp);
    }
    if (res != 0) res++;
    cout << res << "\n";
  }
  return 0;
}
