#include <bits/stdc++.h>
using namespace std;
void mer(int *a, int *l, int ln, int *r, int rn) {
  int i = 0, j = 0, k = 0;
  while (i < ln && j < rn) {
    if (l[i] < r[j])
      a[k++] = l[i++];
    else
      a[k++] = r[j++];
  }
  while (i < ln) a[k++] = l[i++];
  while (j < rn) a[k++] = r[j++];
}
void mers(int *a, int n) {
  if (n < 2) return;
  int i, mid = n / 2;
  int l[mid], r[n - mid];
  for (i = 0; i < mid; i++) l[i] = a[i];
  for (i = mid; i < n; i++) r[i - mid] = a[i];
  mers(l, mid);
  mers(r, n - mid);
  mer(a, l, mid, r, n - mid);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int x = 0, m, n, k, pk = 0, px = 0, z = 0, l = 0;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> m;
      a[i] = m % k;
    }
    m = 0;
    mers(a, n);
    for (int i = n - 1; i >= 0; i--) {
      if (z == 0) {
        if (a[i] != 0) {
          if ((a[i] + x) % k == 0)
            x += 1;
          else
            x = x + (k - (x + a[i]) % k) + 1;
        }
      }
      while (a[i] == a[i - 1] && a[i] != 0 && i >= 0) {
        z = 1;
        i--;
        l++;
        if (l >= pk) {
          if ((a[i] + x) % k == 0)
            x += 1;
          else
            x = x + (k - (x + a[i]) % k) + 1;
        }
      }
      if (l > pk) {
        pk = l;
        l = 0;
      } else
        l = 0;
      px = x;
    }
    cout << x << endl;
  }
}
