#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long mod = 1e9 + 7;
const long long sz = 2e5 + 9;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void bring_me_thanos() {
  long long n, k;
  cin >> n >> k;
  vector<long long> v(n);
  for (long long &x : v) {
    cin >> x;
    x %= k;
    x = (k - x + k) % k;
  }
  long long c = 0, f = 1;
  map<long long, long long> ct;
  for (auto x : v) {
    if (x == 0) {
      continue;
    }
    f = 0;
    c = max(ct[x] * k + x, c);
    ct[x]++;
  }
  if (f) {
    cout << 0 << '\n';
    return;
  }
  cout << c + 1 << '\n';
}
void solve() {
  long long tc;
  cin >> tc;
  while (tc--) bring_me_thanos();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec, Copyright %c 2019 PyThor. \n",
          double(end - beg) / CLOCKS_PER_SEC, 184);
  return 0;
}
