#include <bits/stdc++.h>
using namespace std;
long long int m = 1000000007;
string toString(char x) {
  string s(1, x);
  return s;
}
long long int pow1(long long int x, long long int y) {
  long long int temp;
  if (y == 0) return 1;
  temp = pow1(x, y / 2);
  if (y % 2 == 0)
    return (temp % m * temp % m) % m;
  else
    return ((x % m * temp % m) % m * temp % m) % m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    int flag = 0, flag1 = 0;
    long long int max1 = 1;
    long long int a[n];
    map<long long int, long long int> s;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] % k != 0)
        a[i] = k - a[i] % k;
      else {
        a[i] = 0;
      }
      if (a[i] != 0) {
        flag = 1;
        if (s.find(a[i]) != s.end()) {
          s[a[i]]++;
          a[i] = s[a[i]] * k + a[i];
        } else {
          s.insert({a[i], 0});
        }
      }
      max1 = max(a[i], max1);
    }
    if (flag == 0) {
      cout << 0 << "\n";
      continue;
    }
    cout << max1 + 1 << "\n";
  }
  return 0;
}
