#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    long long a[n], b[n], c = 0;
    for (int i = 0; i < n; i++) cin >> a[i], b[i] = (a[i] % k);
    sort(b, b + n);
    reverse(b, b + n);
    map<long long, long long> mp;
    for (int i = 0; i < n && b[i]; i++)
      if (i) {
        if (b[i - 1] == b[i])
          mp[b[i]] += k;
        else
          mp[b[i]] = k - b[i] + 1;
      } else
        mp[b[i]] = k - b[i] + 1;
    for (auto &it : mp) c = max(c, it.second);
    cout << c << '\n';
  }
}
