#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = ((res % p) * (x % p)) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int pow1(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = x * x;
  }
  return res;
}
const long long int N = 1e5 + 1;
void solve() {
  long long int n, k, p = 0, q = 0, s = 0, c = 0, i, j;
  cin >> n >> k;
  vector<int> v;
  map<int, int> m;
  for (long long int i = 0; i < n; i++) {
    cin >> p;
    p = k - p % k;
    if (p < k) m[p]++;
  }
  for (auto it : m) {
    if (it.second > 1)
      c = (it.second - 1) * k + it.first + 1;
    else
      c = it.first + 1;
    s = max(c, s);
  }
  cout << s << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
