#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 200500;
const long long mod = 1e9 + 7;
bool cmp(int a, int b) { return a > b; }
int a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    long long ans = 0;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      a[i] %= k;
    }
    sort(a + 1, a + 1 + n);
    int j = 1;
    while (j <= n && a[j] == 0) j++;
    if (j == n + 1) {
      cout << "0\n";
      continue;
    }
    for (int i = j; i <= n; i++) {
      b[i - j + 1] = k - a[i];
    }
    n -= (j - 1);
    int l = b[1], cnt = 1, l1 = b[1], cnt1 = 1;
    b[n + 1] = -1;
    for (int i = 2; i <= n + 1; i++) {
      if (b[i] == b[i - 1])
        cnt++;
      else {
        if (cnt > cnt1) {
          cnt1 = cnt;
          l1 = l;
        } else if (cnt == cnt1 && l > l1) {
          l1 = l;
        }
        cnt = 1;
        l = b[i];
      }
    }
    for (int i = 2; i <= cnt1; i++) {
      ans += k;
    }
    ans += (1 + l1);
    cout << ans << endl;
  }
  return 0;
}
