#include <bits/stdc++.h>
using namespace std;
long long int ar[500009], br[500009], cr[500009], tr[500009];
long long int fx[] = {-1, 1, 0, 0};
long long int fy[] = {0, 0, 1, -1};
map<long long int, long long int> mp;
vector<long long int> v;
string s;
struct evan {
  long long int l, r, pos;
} st[500009];
bool com(evan i1, evan i2) { return (i1.r < i2.r); }
int main() {
  long long int a, b, c, d, e, i, j, k, x, y, z, f, g, h, n, m;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> a;
  while (a--) {
    cin >> b >> c;
    map<long long int, long long int> mp;
    for (i = 1; i <= b; i++) {
      cin >> j;
      k = (c - (j % c)) % c;
      if (k > 0) {
        v.push_back(k);
      }
    }
    z = 0;
    for (i = 0; i < v.size(); i++) {
      if (mp[v[i]] == 0) {
        z = max(z, v[i]);
        mp[v[i]]++;
      } else {
        k = mp[v[i]] * c + v[i];
        z = max(z, k);
        mp[v[i]]++;
      }
    }
    if (z == 0)
      cout << z << endl;
    else
      cout << z + 1 << endl;
    v.clear();
  }
}
