#include <bits/stdc++.h>
const int BIG = 1e5 + 55;
const int BIGG = 1e9 + 7;
const long long BIGGE = 1e12 + 55;
const double SML = (1e-7);
using namespace std;
int t;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) {
    long long n, k, ma = 0, c = 0;
    cin >> n >> k;
    map<long long, long long> m;
    for (int i = 0; i < n; i++) {
      long long a;
      cin >> a;
      long long x = a % k;
      if (x == 0) continue;
      x = k - x;
      m[x]++;
      if (ma < m[x]) {
        ma = m[x];
        c = x;
      } else if (ma == m[x]) {
        c = max(c, x);
      }
    }
    if (c)
      cout << c + 1 + k * (m[c] - 1) << "\n";
    else
      cout << c << "\n";
  }
  return 0;
}
