#include <bits/stdc++.h>
using namespace std;
int withSwaps(vector<int> equivs, int n, int k) {
  int x = 0;
  int iters = 0;
  while (equivs[0] < n) {
    if (x != 0) {
      int c = k - x;
      if (equivs[c] > 0) {
        equivs[c]--;
        equivs[0]++;
      } else {
        int max = -1;
        int loc = -1;
        for (int i = 0; i < k; i++) {
          int next = (i + x) % k;
          int delta = equivs[i] - equivs[next];
          if (next < i) {
            if (delta > 2 && delta > max) {
              max = delta;
              loc = i;
            }
          } else {
            if (delta > 1 && delta > max - 1) {
              max = delta + 1;
              loc = i;
            }
          }
        }
        if (loc > 0) {
          equivs[loc]--;
          equivs[(loc + x) % k]++;
        }
      }
    }
    x++;
    x %= k;
    iters++;
  }
  return iters;
}
int main() {
  int t;
  cin >> t;
  while (t-- > 0) {
    int n, k;
    cin >> n >> k;
    vector<int> nums = vector<int>(n);
    map<int, int> equivs = map<int, int>();
    int max = -1;
    int loc = -1;
    for (int i = 0; i < n; i++) {
      cin >> nums[i];
      nums[i] %= k;
      equivs[nums[i]]++;
      if (nums[i] == 0) continue;
      if (equivs[nums[i]] > max) {
        max = equivs[nums[i]];
        loc = nums[i];
      }
      if (equivs[nums[i]] == max && nums[i] < loc) {
        loc = nums[i];
      }
    }
    if (equivs[0] == n) {
      cout << 0 << endl;
    } else {
      long long answer = (long long)k * (equivs[loc] - 1) + (k - loc) + 1;
      cout << answer << endl;
    }
  }
  return 0;
}
