#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int k;
    cin >> n >> k;
    int arr[n];
    map<int, int> mp;
    vector<int> vec;
    int flag = 0;
    int count = 0;
    for (int i = 0; i < n; ++i) {
      cin >> arr[i];
      if (arr[i] % k > 0) {
        if (mp.find(arr[i] % k) != mp.end())
          mp[arr[i] % k]++;
        else
          mp.insert({arr[i] % k, 1});
        count++;
        flag = 1;
      }
    }
    if (flag == 0) {
      cout << 0 << endl;
      continue;
    }
    int max = -1;
    int key = -1;
    for (auto it : mp) {
      if (it.second > max) {
        max = it.second;
        key = it.first;
      }
    }
    long long int answer = (k - (key - 1)) + (max - 1) * 1ll * k;
    cout << answer << endl;
  }
}
