#include <bits/stdc++.h>

#ifndef LOCAL
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2")
#endif

#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back

#define sz(x) (ll)(x).size()
#define pw(x) (1ll << (x))
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

const int N = 100;
const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const ld eps = 1e-9;

struct PairIdx {
    int first, second, idx;
};

int n, k;
PairIdx a[N];
int dp[N][N];
int from[N][N];
vector<int> path;

void trace(pair<int, int> state) {
    pair<int, int> next = {state.fi - 1, from[state.fi][state.se]};
    if(state.fi > 0) {
        trace(next);
    }
    path.pb(a[state.fi].idx + 1);
    if(state.se == next.se) path.pb(-(a[state.fi].idx + 1));
}

void solve() {
    cin >> n >> k;
    fr(i, 0, n - 1) {
        cin >> a[i].fi >> a[i].se;
        a[i].idx = i;
    }
    if(k == 1) {
        int mxi = 0, mx = -inf;
        fr(i, 0, n - 1) {
            if(umx(mx, a[i].fi)) {
                mxi = i;
            }
        }
        cout << 1 << "\n" << mxi + 1 << "\n";
        return;
    }
    sort(a, a + n, [](PairIdx a, PairIdx b) {
        return a.se < b.se;
    });
    fr(i, 0, n - 1) fr(j, 0, k) dp[i][j] = -inf;
    dp[0][0] = 0;
    dp[0][1] = a[0].fi;
    fr(i, 1, n - 1) {
        dp[i][0] = 0;
        fr(j, 0, k - 1) {
            if(umx(dp[i][j], dp[i - 1][j] + a[i].se * j)) {
                from[i][j] = j;
            }
            if(umx(dp[i][j + 1], dp[i - 1][j] + a[i].se * j + a[i].fi)) {
                from[i][j + 1] = j;
            }
        }
    }
    int best = -inf;
    int best_add = -1;
    pair<int, int> state;
    int cur = 0;
    fr(i, 1, n - 1) cur += (k - 1) * a[i].se;
    fr(i, 0, n - 1) {
         if(dp[i][k - 1] == inf) continue;
         fr(j, i + 1, n - 1) {
            if(umx(best, cur + a[j].fi + dp[i][k - 1])) {
                best_add = j;
                state = {i, k - 1};
            }
        }
        if(i + 1 < n) cur -= (k - 1) * a[i + 1].se;
    }
    trace(state);
    fr(i, state.fi + 1, n - 1) {
        if(i == best_add) continue;
        path.pb(a[i].idx + 1);
        path.pb(-(a[i].idx + 1));
    }
    path.pb(a[best_add].idx + 1);
    cerr << best << "\n";
    cout << sz(path) << "\n";
    fe(x, path) {
        cout << x << " ";
    }
    cout << "\n";
}

int main() {
#ifndef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
    int test;
    cin >> test;
    while(test--) {
        solve();
    }
}