#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
int n, k;
int a[maxn];
long long b[maxn];
int main() {
  ios::sync_with_stdio(false);
  int _;
  cin >> _;
  while (_--) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], b[i] = (k - a[i] % k) % k;
    sort(b + 1, b + 1 + n);
    long long ans = 0, now = 0;
    long long mx_Same = 0;
    long long mx_number = -1;
    long long temp_ans = 0;
    for (int i = 1; i <= n; i++) {
      if (b[i] == 0) continue;
      if (i + 1 <= n && b[i] == b[i + 1]) {
        int same = 2;
        i++;
        while (i + 1 <= n && b[i] == b[i + 1]) {
          same++;
          i++;
        }
        if (same >= mx_Same) {
          mx_Same = same;
          mx_number = b[i];
        }
      } else
        temp_ans += 1;
    }
    if (temp_ans == 0 && mx_number == -1)
      cout << 0 << endl;
    else {
      if (mx_Same == 0) {
        cout << b[n] + 1 << endl;
      } else {
        cout << 1ll * mx_number + 1ll * (mx_Same - 1) * k + 1ll << endl;
      }
    }
  }
  return 0;
}
