#include <bits/stdc++.h>
using namespace std;
int n,k;
long long a[1005],b[1005];
long long dp[1005][1005];
void f_min(int x,int l,int r,int ll,int rr){
if (l>r || ll>rr) return;
int mid=(l+r)>>1;
int pos=ll;
long long cur;
for (int i=ll;i<=min(rr,mid);++i) {
cur=dp[x-1][i-1]+a[i]*b[mid];
if (cur<dp[x][mid]) {
pos=i;
dp[x][mid]=cur;
}
}
f_min(x,l,mid-1,ll,pos);
f_min(x,mid+1,r,pos,rr);
}
inline long long solve_min() {
for (int i=0;i<=n;++i)
for (int j=0;j<=k;++j)
dp[j][i]=1e18;
dp[0][0]=0;
for (int i=1;i<=k;++i)
f_min(i,1,n,1,n);
return dp[k][n];
}
void f_max(int x,int l,int r,int ll,int rr){
if (l>r || ll>rr) return;
int mid=(l+r)>>1;
int pos=ll;
long long cur;
for (int i=ll;i<=min(rr,mid);++i) {
cur=dp[x-1][i-1]+a[i]*b[mid];
if (cur>dp[x][mid]) {
pos=i;
dp[x][mid]=cur;
}
}
f_max(x,l,mid-1,ll,pos);
f_max(x,mid+1,r,pos,rr);
}
inline long long solve_max() {
for (int i=0;i<=n;++i)
for (int j=0;j<=k;++j)
dp[j][i]=-1e18;
dp[0][0]=0;
for (int i=1;i<=k;++i)
f_max(i,1,n,1,n);
return dp[k][n];
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int tt;
cin>>tt;
while (tt--) {
cin>>n>>k;
for (int i=1;i<=n;++i) {
cin>>a[i]>>b[i];
}
long long last=1e9;
for (int i=n;i>0;--i) {
last=min(last,a[i]);
a[i]=last;
}
last=-1e9;
for (int i=1;i<=n;++i) {
last=max(last,b[i]);
b[i]=last;
}
cout<<solve_min()<<" "<<solve_max()<<'\n';
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKaW50IG4sazsKbG9uZyBsb25nIGFbMTAwNV0sYlsxMDA1XTsKbG9uZyBsb25nIGRwWzEwMDVdWzEwMDVdOwoKdm9pZCBmX21pbihpbnQgeCxpbnQgbCxpbnQgcixpbnQgbGwsaW50IHJyKXsKICAgIGlmIChsPnIgfHwgbGw+cnIpIHJldHVybjsKICAgIGludCBtaWQ9KGwrcik+PjE7CiAgICBpbnQgcG9zPWxsOwogICAgbG9uZyBsb25nIGN1cjsKICAgIGZvciAoaW50IGk9bGw7aTw9bWluKHJyLG1pZCk7KytpKSB7CiAgICAgICAgY3VyPWRwW3gtMV1baS0xXSthW2ldKmJbbWlkXTsKICAgICAgICBpZiAoY3VyPGRwW3hdW21pZF0pIHsKICAgICAgICAgICAgcG9zPWk7CiAgICAgICAgICAgIGRwW3hdW21pZF09Y3VyOwogICAgICAgIH0KICAgIH0KICAgIGZfbWluKHgsbCxtaWQtMSxsbCxwb3MpOwogICAgZl9taW4oeCxtaWQrMSxyLHBvcyxycik7Cn0KCmlubGluZSBsb25nIGxvbmcgc29sdmVfbWluKCkgewogICAgZm9yIChpbnQgaT0wO2k8PW47KytpKQogICAgICAgIGZvciAoaW50IGo9MDtqPD1rOysraikKICAgICAgICAgICAgZHBbal1baV09MWUxODsKICAgIGRwWzBdWzBdPTA7CiAgICBmb3IgKGludCBpPTE7aTw9azsrK2kpCiAgICAgICAgZl9taW4oaSwxLG4sMSxuKTsKICAgIHJldHVybiBkcFtrXVtuXTsKfQoKdm9pZCBmX21heChpbnQgeCxpbnQgbCxpbnQgcixpbnQgbGwsaW50IHJyKXsKICAgIGlmIChsPnIgfHwgbGw+cnIpIHJldHVybjsKICAgIGludCBtaWQ9KGwrcik+PjE7CiAgICBpbnQgcG9zPWxsOwogICAgbG9uZyBsb25nIGN1cjsKICAgIGZvciAoaW50IGk9bGw7aTw9bWluKHJyLG1pZCk7KytpKSB7CiAgICAgICAgY3VyPWRwW3gtMV1baS0xXSthW2ldKmJbbWlkXTsKICAgICAgICBpZiAoY3VyPmRwW3hdW21pZF0pIHsKICAgICAgICAgICAgcG9zPWk7CiAgICAgICAgICAgIGRwW3hdW21pZF09Y3VyOwogICAgICAgIH0KICAgIH0KICAgIGZfbWF4KHgsbCxtaWQtMSxsbCxwb3MpOwogICAgZl9tYXgoeCxtaWQrMSxyLHBvcyxycik7Cn0KCgppbmxpbmUgbG9uZyBsb25nIHNvbHZlX21heCgpIHsKICAgIGZvciAoaW50IGk9MDtpPD1uOysraSkKICAgICAgICBmb3IgKGludCBqPTA7ajw9azsrK2opCiAgICAgICAgICAgIGRwW2pdW2ldPS0xZTE4OwogICAgZHBbMF1bMF09MDsKICAgIGZvciAoaW50IGk9MTtpPD1rOysraSkKICAgICAgICBmX21heChpLDEsbiwxLG4pOwogICAgcmV0dXJuIGRwW2tdW25dOwp9CmludCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBpbnQgdHQ7CiAgICBjaW4+PnR0OwogICAgd2hpbGUgKHR0LS0pIHsKICAgICAgICBjaW4+Pm4+Pms7CiAgICAgICAgZm9yIChpbnQgaT0xO2k8PW47KytpKSB7CiAgICAgICAgICAgIGNpbj4+YVtpXT4+YltpXTsKICAgICAgICB9CiAgICAgICAgbG9uZyBsb25nIGxhc3Q9MWU5OwogICAgICAgIGZvciAoaW50IGk9bjtpPjA7LS1pKSB7CiAgICAgICAgICAgIGxhc3Q9bWluKGxhc3QsYVtpXSk7CiAgICAgICAgICAgIGFbaV09bGFzdDsKICAgICAgICB9CiAgICAgICAgbGFzdD0tMWU5OwogICAgICAgIGZvciAoaW50IGk9MTtpPD1uOysraSkgewogICAgICAgICAgICBsYXN0PW1heChsYXN0LGJbaV0pOwogICAgICAgICAgICBiW2ldPWxhc3Q7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PHNvbHZlX21pbigpPDwiICI8PHNvbHZlX21heCgpPDwnXG4nOwogICAgfQp9Cg==