#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int x, j = 0, s = 0;
  map<long long int, int> a;
  bool flag = 1;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    x %= k;
    if (x) {
      flag = 0;
      if (a[k - x] == j) {
        if (s < (k - x)) s = k - x;
      } else if (a[k - x] > j) {
        s = k - x;
        j = a[k - x];
      }
      ++a[k - x];
    }
  }
  j *= k;
  j += (s + 1ll);
  if (flag) j = 0;
  cout << j << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
