#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> a;
    for (int e = 0; e < n; e++) {
      int y;
      cin >> y;
      a.push_back(y);
    };
    int x = 0;
    for (int i = 0; i < n; i++) {
      a[i] %= k;
    }
    map<int, int> m;
    int c = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] != 0) {
        m[k - a[i]]++;
        c++;
      }
    }
    int i = c, p = 0;
    long long res = 0;
    int s = m.size();
    for (auto it = m.begin(); i > 0; it++) {
      if (p % s == 0) {
        it = m.begin();
        p = 0;
      }
      if (it->second != 0) {
        res += ((it->first - x) < 0 ? (it->first + k - x) + 1
                                    : (it->first - x) + 1);
        x = (it->first + 1) % k;
        it->second = it->second - 1;
        i--;
      }
      p++;
    }
    cout << res << endl;
  }
}
