#include
#include
#include
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int n,k;
cin>>n>>k;
long long int arr[n],sum=0;
for(int i=0;i<n;i++)
cin>>arr[i];
for(int i=0;i<n;i++)
sum+=arr[i];
sort(arr,arr+n);
long long int s=0,e=sum,mid,min=INT_MAX;
if(n<=k){
min = sum;
}
else{
while(s<=e){
mid = (s+e)/2;
int tempsum=0,i=0,j=1,tempmax=0;
for(i=0;i<n;i++){
if(tempsum + arr[i]>mid){
if(tempmax<=tempsum)
tempmax = tempsum;
tempsum = 0;
j++;
}
tempsum += arr[i];
if(i==n-1 && tempsum>tempmax)
tempmax = tempsum;
if(j>k){
s = mid+1;
break;
}
}
if(j<k)
e = mid-1;
else if(i==n){
if(min>tempmax)
min = tempmax;
e=mid-1;
}
}
}
cout<<min<<endl;
}
return 0;
}