#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
inline long long int max(long long int a, long long int b) {
  return a > b ? a : b;
}
inline long long int min(long long int a, long long int b) {
  return a < b ? a : b;
}
void show(vector<long long int> v) {
  for (long long int i = 0; i < (v.size()); ++i) cout << v[i] << " ";
  cout << "\n";
}
void show(vector<int> v) {
  for (long long int i = 0; i < (v.size()); ++i) cout << v[i] << " ";
  cout << "\n";
}
void show(int a[], int arraysize) {
  for (int i = 0; i < arraysize; ++i) cout << a[i] << " ";
  cout << "\n";
}
void show(long long int a[], long long int arraysize) {
  for (long long int i = 0; i < arraysize; ++i) cout << a[i] << " ";
  cout << "\n";
}
void show(unordered_set<int> s) {
  for (auto it = s.begin(); it != s.end(); it++) {
    cout << *it << " ";
  }
  cout << "\n";
}
void show(unordered_map<long long int, long long int> mp) {
  for (auto it = mp.begin(); it != mp.end(); it++) {
    cout << it->first << " " << it->second << "\n";
  }
  cout << "\n";
}
int main() {
  long long int t, n, m;
  cin >> t;
  while (t) {
    long long int k, tmp, y;
    cin >> n >> k;
    if (k == 1) {
      for (long long int i = 0; i < (n); ++i) cin >> tmp;
      cout << 0 << "\n";
      t--;
      continue;
    } else if (k == 2) {
      long long int o = 0, e = 0, x, y;
      for (long long int i = 0; i < (n); ++i) {
        cin >> y;
        x = y % k;
        if (x == 1) o++;
      }
      if (o == 0)
        cout << 0 << "\n";
      else
        cout << 2 * o << "\n";
      t--;
      continue;
    }
    long long int x;
    map<long long int, int> mp;
    long long int mx = 0;
    for (long long int i = 0; i < (n); ++i) {
      cin >> y;
      x = y % k;
      if (x != 0) {
        long long int tmp = k - x;
        long long int cnt = ++mp[tmp];
        m = k * (cnt - 1) + tmp;
        if (mx < m) mx = m;
      }
    }
    if (mx == 0)
      cout << mx << "\n";
    else
      cout << mx + 1 << "\n";
    t--;
  }
  return 0;
}
