#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long base = 998244353;
const long long oo = 1e6 + 10;
const long long gh = 1e3 + 3;
const long long inf = 1e15 + 5;
double pi = 2 * asin(1);
long long n, m, k;
long long a[oo];
long long a1[oo], a2[oo];
long long sum[oo];
string s;
char c[oo];
void print() {}
void proc() {}
void Main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  long long ans = -1;
  for (long long i = 1; i <= n; i++) {
    a[i] = a[i] % k;
  }
  sort(a + 1, a + n + 1);
  long long t = -1;
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 0) continue;
    if (a[i] != a[i - 1]) {
      ans = max(ans, t);
      t = k - a[i];
    } else
      t += k;
  }
  ans = max(ans, t);
  cout << ans + 1 << "\n";
}
int32_t main() {
  if (ifstream("test.txt")) {
    freopen("test.txt", "r", stdin);
  } else if (ifstream(""
                      ".inp")) {
    freopen(
        ""
        ".inp",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
  long long t = 1;
  cin >> t;
  while (t--) {
    Main();
  }
}
