#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    map<long long, long long> sum;
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) {
      long long a;
      scanf("%lld", &a);
      if (a % k != 0) sum[a % k]++;
    }
    long long Max = 0, value = 0;
    for (auto t : sum)
      if (Max < t.second) Max = t.second, value = t.first;
    if (value == 0)
      printf("%d\n", 0);
    else
      printf("%lld\n",
             ((long long)Max - 1) * (long long)k + ((long)k - value) + 1);
  }
  return 0;
}
