#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

void solve(){
    int a,k; cin>>a>>k;
    vec<pair<pll, ll>> m(a+1);
    for(int q=1; q<=a; q++) {
        cin >> m[q].F.F >> m[q].F.S;
        m[q].S = q;
    }
    sort(m.begin(), m.end(), [](auto &p1, auto &p2){return p1.F.S<p2.F.S;});
    vec<vec<ll>> dp(a+1, vec<ll>(k+1)), take(a+1, vec<ll>(k+1));
    for(int q=1; q<=a; q++){
        for(int w=1; w<=min(q,k); w++){
            ll go = dp[q-1][w-1] + w*m[w].F.S + m[w].F.F;
            ll ne_go = w==q ? 0 : dp[q-1][w] + (k-1)*m[w].S;
            if(go > ne_go) take[q][w] = 1;
            dp[q][w] = max(go, ne_go);
        }
    }
    vec<ll> ord, loxi;
    ll cp = a, ck = k;
    for(; ord.size()<k;){
        if(take[cp][ck]){
            ord.pb(cp);
            ck--;
        }
        else loxi.pb(cp);
        cp--;
    }
    reverse(ord.begin(), ord.end());
    ll lst = ord.back();
    ord.pop_back();
    vec<ll> o;
    for(ll i : ord) o.pb(m[i].S);
    for(ll i : loxi){
        o.pb(m[i].S);
        o.pb(-m[i].S);
    }
    o.pb(m[lst].S);
    cout<<o.size()<<"\n";
    for(ll i : o) cout<<i<<" "; cout<<"\n";
}

int main() {
    fast;
    int z; cin>>z;
    for(; z--;){
        solve();
    }
}
