#include<iostream>
#define ll long long
#include<vector>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
void solve()
{
ll n, m;
cin >> n >> m;
vector<ll> v(n);
for (ll i = 0; i < n; i++)
{
cin >> v[i];
}
sort(v.begin(), v.end());
ll mx = INT_MIN;
for (ll i = 0; i < n; i++)
{
mx = max(mx, v[i] - v[n - 1] + ((v[i] + v[n - 1] % m) + m));
}
cout << mx << "
";
}
int main()
{
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}