#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;
}