#include "bits/stdc++.h"
using namespace std;
const int maxn = 1111;
long long P[maxn], Q[maxn];
long long dp[maxn][maxn];
using ll = long long;
const ll is_query = -(1LL<<62);
struct Line {
    ll m, b;
    mutable function<const Line*()> succ;
    bool operator<(const Line& rhs) const {
        if (rhs.b != is_query) return m < rhs.m;
        const Line* s = succ();
        if (!s) return 0;
        ll x = rhs.m;
        return b - s->b < (s->m - m) * x;
    }
};
struct HullDynamic : public multiset<Line> { // will maintain upper hull for maximum
    bool bad(iterator y) {
        auto z = next(y);
        if (y == begin()) {
            if (z == end()) return 0;
            return y->m == z->m && y->b <= z->b;
        }
        auto x = prev(y);
        if (z == end()) return y->m == x->m && y->b <= x->b;
        return (x->b - y->b)*(z->m - y->m) >= (y->b - z->b)*(y->m - x->m);
    }
    void insert_line(ll m, ll b) {
        auto y = insert({ m, b });
        y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
        if (bad(y)) { erase(y); return; }
        while (next(y) != end() && bad(next(y))) erase(next(y));
        while (y != begin() && bad(prev(y))) erase(prev(y));
    }
    ll eval(ll x) {
        auto l = *lower_bound((Line) { x, is_query });
        return l.m * x + l.b;
    }
};
int main(){
    int cs;
    scanf("%d", &cs);
    while(cs--){
        int n, k;
        scanf("%d %d", &n, &k);
        for(int e = 1; e <= n; e++) scanf("%lld %lld", P + e, Q + e);
        for(int e = n-1; e >= 1; e--) P[e] = min(P[e], P[e+1]);
        for(int e = 2; e <= n; e++) Q[e] = max(Q[e], Q[e-1]);
        long long mi, ma;
        const long long inf = 1ll<<56;
        {
            for(int e = 0; e <= k; e++){
                for(int f = 0; f <= n; f++){
                    dp[e][f] = -inf;
                }
            }
            dp[0][0] = 0;
            for(int e = 1; e <= k; e++){
                HullDynamic q;
                if(dp[e-1][0] != -inf)
                    q.insert_line(P[1], dp[e-1][0]);
                for(int f = 1; f <= n; f++){
                    if(!q.empty()) dp[e][f] = max(dp[e][f], q.eval(Q[f]));
                    if(dp[e-1][f] != -inf)
                        q.insert_line(P[f+1], dp[e-1][f]);
                }
            }
            mi = dp[k][n];
        }
        {
            for(int e = 0; e <= k; e++){
                for(int f = 0; f <= n; f++){
                    dp[e][f] = inf;
                }
            }
            dp[0][0] = 0;
            for(int e = 1; e <= k; e++){
                HullDynamic q;
                if(dp[e-1][0] != inf)
                    q.insert_line(-P[1], -dp[e-1][0]);
                for(int f = 1; f <= n; f++){
                    if(!q.empty()) dp[e][f] = min(dp[e][f], -q.eval(Q[f]));
                    if(dp[e-1][f] != inf)
                        q.insert_line(-P[f+1], -dp[e-1][f]);
                }
            }
            ma = dp[k][n];
        }
        cout << ma << " " << mi << endl;
    }
    return 0;
}
