#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t; cin >> t;
while(t--) {
int n, k; cin >> n >> k;
vector<ll> arr(n);
for(int i = 0; i < n; i++) {
cin >> arr[i];
arr[i] %= k;
if(arr[i] != 0)
arr[i] = k - arr[i];
}
multiset<ll> myset;
for(int i = 0; i < n; i++) {
if(arr[i] == 0)
continue;
myset.insert(arr[i]);
}
ll x = 0;
ll ans = 0;
while(!myset.empty()) {
auto itm = myset.begin();
ll itmVal = *itm;
while(itmVal < x)
itmVal += k;
ll needed = itmVal-x;
ans += needed+1;
x += needed+1;
myset.erase(itm);
auto tmp = myset.find(x);
while(tmp != myset.end()) {
x ++;
ans ++;
myset.erase(tmp);
tmp = myset.find(x);
}
}
cout << ans << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKSwgY2luLnRpZSgwKSwgY291dC50aWUoMCk7CiAgICAKICAgIGludCB0OyBjaW4gPj4gdDsKICAgIHdoaWxlKHQtLSkgewogICAgICAgIGludCBuLCBrOyBjaW4gPj4gbiA+PiBrOwogICAgICAgIHZlY3RvcjxsbD4gYXJyKG4pOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgY2luID4+IGFycltpXTsKICAgICAgICAgICAgYXJyW2ldICU9IGs7CiAgICAgICAgICAgIGlmKGFycltpXSAhPSAwKQogICAgICAgICAgICAgICAgYXJyW2ldID0gayAtIGFycltpXTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgbXVsdGlzZXQ8bGw+IG15c2V0OwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspIHsKICAgICAgICAgICAgaWYoYXJyW2ldID09IDApCiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgbXlzZXQuaW5zZXJ0KGFycltpXSk7CiAgICAgICAgfQoKICAgICAgICBsbCB4ID0gMDsKICAgICAgICBsbCBhbnMgPSAwOwogICAgICAgIHdoaWxlKCFteXNldC5lbXB0eSgpKSB7CiAgICAgICAgICAgIGF1dG8gaXRtID0gbXlzZXQuYmVnaW4oKTsKICAgICAgICAgICAgbGwgaXRtVmFsID0gKml0bTsKICAgICAgICAgICAgd2hpbGUoaXRtVmFsIDwgeCkKICAgICAgICAgICAgICAgIGl0bVZhbCArPSBrOwogICAgICAgICAgICBsbCBuZWVkZWQgPSBpdG1WYWwteDsKICAgICAgICAgICAgYW5zICs9IG5lZWRlZCsxOwogICAgICAgICAgICB4ICs9IG5lZWRlZCsxOwogICAgICAgICAgICBteXNldC5lcmFzZShpdG0pOwogICAgICAgICAgICBhdXRvIHRtcCA9IG15c2V0LmZpbmQoeCk7CiAgICAgICAgICAgIHdoaWxlKHRtcCAhPSBteXNldC5lbmQoKSkgewogICAgICAgICAgICAgICAgeCArKzsKICAgICAgICAgICAgICAgIGFucyArKzsKICAgICAgICAgICAgICAgIG15c2V0LmVyYXNlKHRtcCk7CiAgICAgICAgICAgICAgICB0bXAgPSBteXNldC5maW5kKHgpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgYW5zIDw8ICJcbiI7CiAgICB9CiAgICAKICAgIHJldHVybiAwOwp9
NQo0IDMKMSAyIDEgMwoxMCA2CjggNyAxIDggMyA3IDUgMTAgOCA5CjUgMTAKMjAgMTAwIDUwIDIwIDEwMDUwMAoxMCAyNQoyNCAyNCAyNCAyNCAyNCAyNCAyNCAyNCAyNCAyNAo4IDgKMSAyIDMgNCA1IDYgNyA4Cg==
5
4 3
1 2 1 3
10 6
8 7 1 8 3 7 5 10 8 9
5 10
20 100 50 20 100500
10 25
24 24 24 24 24 24 24 24 24 24
8 8
1 2 3 4 5 6 7 8