#include <bits/stdc++.h>
using namespace std;
namespace IO {
inline long long read() {
  long long o = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    o = o * 10 + c - '0';
    c = getchar();
  }
  return o * f;
}
}  // namespace IO
using namespace IO;
const int N = 2e5 + 7, M = N << 1, inf = 0x3f3f3f3f;
long long a[N], b[N];
int n, t, k;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], a[i] %= k;
    sort(a + 1, a + n + 1, greater<int>());
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == 0) break;
      if (a[i] != a[i - 1]) {
        b[i] = k - a[i];
      } else {
        b[i] = b[i - 1] + k;
      }
      ans = max(ans, b[i] + 1);
    }
    cout << ans << endl;
  }
  return 0;
}
