#include <bits/stdc++.h>
using namespace std;
long long int pow1(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    map<long long int, long long int> m;
    long long int temp;
    long long int adder = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> temp;
      adder = k - (temp % k);
      if (adder == k)
        m[0]++;
      else
        m[adder]++;
    }
    long long int ans = 0;
    long long int temp2 = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
      long long int index = it->first;
      long long int count = it->second;
      if (count == 0 || index == 0)
        continue;
      else {
        temp2 = index + ((m[index] - 1) * k);
        ans = max(ans, temp2);
      }
    }
    if (ans != 0)
      cout << ans + 1 << "\n";
    else
      cout << ans << "\n";
  }
}
