#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int binarySearch(int arr[], int l, int r, int x) {
  while (l <= r) {
    int m = l + (r - l) / 2;
    if (arr[m] == x) {
      return m;
    }
    if (arr[m] < x) {
      l = m + 1;
    } else {
      r = m - 1;
    }
  }
  return -1;
}
long long int binomialCoeff(long long int n, long long int k) {
  long long int res = 1, i;
  if (k > n - k) k = n - k;
  for (i = 0; i < k; ++i) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
int findMinDiff(vector<int> ar, int a[]) {
  std::vector<int> arr;
  for (int i = 0; i < ar.size(); ++i) {
    arr.push_back(a[ar[i]]);
  }
  sort(arr.begin(), arr.end());
  int n = arr.size();
  int diff = INT_MAX;
  for (int i = 0; i < n - 1; i++)
    if (arr[i + 1] - arr[i] < diff) diff = arr[i + 1] - arr[i];
  return diff;
}
int power(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k, i, j;
    cin >> n >> k;
    long long int a[n], z = 0;
    map<long long int, long long int> m;
    std::vector<long long int> v;
    for (i = 0; i < n; ++i) {
      cin >> a[i];
      if (a[i] % k != 0) {
        int xx = k - (a[i] % k);
        v.push_back(xx);
      }
    }
    sort(v.begin(), v.end());
    int q = 0;
    if (v.size() == 0) {
      cout << "0\n";
      continue;
    }
    m[v[0]] = 1;
    for (int i = 1; i < v.size(); ++i) {
      if (v[i] == v[i - 1]) {
        q++;
        m[k * q + v[i]] = 1;
      } else {
        m[v[i]] = 1;
        q = 0;
      }
    }
    long long int ans = 0, temp = 0;
    for (auto i : m) {
      ans += i.first - temp;
      temp = i.first;
    }
    if (ans != 0) {
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
