#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    static int n, k;
    cin >> n >> k;
    map<int, int> count;
    for (int i = 0; i < n; ++i) {
      static int a;
      cin >> a;
      ++count[(k - a % k) % k];
    }
    count[0] = 0;
    int max = 0;
    int maxPos = 0;
    for (const auto& x : count) {
      if (x.second >= max) {
        maxPos = x.first;
        max = x.second;
      }
    }
    cout << ((max == 0) ? 0 : ((long long)(max - 1) * k + maxPos + 1)) << '\n';
  }
  return 0;
}
