#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  return gcd(b % a, a);
}
long long pow(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long half = pow(a, b / 2);
  long long ans = (half * half);
  if (b % 2) {
    ans = (ans * a);
  }
  return ans;
}
int main() {
  long long T;
  cin >> T;
  long long n, k;
  while (T--) {
    cin >> n >> k;
    set<long long> S;
    long long x;
    map<long long, long long> A;
    for (int i = 0; i < n; i++) {
      cin >> x;
      x %= k;
      if (x != 0) {
        x = (k - x);
        if (A.find(x) == A.end()) {
          A[x] = x;
        }
        S.insert(A[x]);
        A[x] += k;
      }
    }
    long long val = 0;
    long long ans = 0;
    while (S.size() > 0) {
      long long top_elem = *(S.begin());
      ans += (top_elem - val) + 1;
      val = top_elem + 1;
      S.erase(top_elem);
    }
    cout << ans << endl;
  }
  return 0;
}
