#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  int t;
  cin >> t;
  while (t--) {
    v.clear();
    map<long long, bool> m;
    map<long long, long long> next;
    long long n, k, maximum = -1;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
      int val;
      cin >> val;
      v.push_back(val);
    }
    for (int i = 0; i < n; i++) {
      int val = v[i];
      int diff = val / k;
      if (val % k != 0) {
        int r = ((diff + 1) * k) - val;
        if (m[r] == false) {
          m[r] = true;
          next[r] = r + k;
          if (r > maximum) maximum = r;
        } else {
          m[next[r]] = true;
          if (next[r] > maximum) maximum = next[r];
          next[r] = next[r] + k;
        }
      }
    }
    cout << maximum + 1 << "\n";
  }
}
