← Home
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,k,res=0;cin>>n>>k;map<int,int>mp;set<int>xS;
    for(int i=1,x;i<=n;i++)cin>>x,mp[-x]++;
    for(int i=1;i<=n*3;i++)xS.insert(i);
    for(auto [h,c]:mp)while(c)
    {
        int p=*xS.lower_bound(-h);xS.erase(p);
        if(c==k)res=max(res,p+h);c--;
    }
    cout<<res<<'\n';
}
int main()
{
	ios::sync_with_stdio(0),cin.tie(0);
	int t=1;cin>>t;while(t--)solve();
}