#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long temp, curAdd, max = 0;
    map<long long, long long> m;
    for (int i = 0; i < n; ++i) {
      cin >> temp;
      if (temp % k == 0)
        curAdd = 0;
      else {
        if (m.count(temp % k))
          curAdd = m[temp % k];
        else
          curAdd = k - temp % k;
        m[temp % k] = curAdd + k;
        if (curAdd > max) max = curAdd;
      }
    }
    cout << ((max == 0) ? max : max + 1) << "\n";
  }
  return 0;
}
