///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2 * 75 + 4;

struct edge {
    int u, v, w, c, f;

    edge(int u_, int v_, int w_, int c_, int f_) :
        u(u_), v(v_), w(w_), c(c_), f(f_) {}
};

vector<edge> edges;
vector<int> g[N];

int n, k, s, t, a[N], b[N];

void read() {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
    }
}

void add(int u, int v, int w) {
    int sz = size(edges);
    edges.em_back(u, v, w, 1, 0);
    edges.em_back(v, u, -w, 0, 0);
    g[u].em_back(sz);
    g[v].em_back(sz ^ 1);
}

void prepare() {
    edges.clear();
    s = 0, t = 2 * n + 1;
    for (int i = 1; i <= n; ++i) {
        add(s, i, 0);
        add(n + i, t, 0);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            int l = i, r = j + n;
            int cost = 0;
            if (j == n) {
                cost = a[i] + b[i] * (k - 1);
            } else if (j < k) {
                cost = a[i] + b[i] * j;
            } else {
                cost = b[i] * (k - 1);
            }
            add(l, r, -cost);
        }
    }
}

const int INF = 1e9 + 4;

ll d[N], phi[N];
int p[N];

void bellmanFord() {
    fill_n(phi, N, INF);
    phi[s] = 0;
    for (int i = 0; i < t - 1; ++i) {
        for (edge& e : edges) {
            if (e.c > 0 && phi[e.u] < INF) {
                phi[e.v] = min(phi[e.v], phi[e.u] + e.w);
            }
        }
    }
}

bool dijk() {
    memset(p, -1, sizeof p);
    vector<bool> used(t + 4);
    fill(d, d + N, INF);
    d[s] = 0;

    while (true) {
        int u = -1;
        for (int v = s; v <= t; ++v) {
            if (!used[v] && (u == -1 || d[v] < d[u])) {
                u = v;
            }
        }

        if (u == -1 || d[u] == INF) {
            break;
        }

        used[u] = true;
        for (int num : g[u]) {
            edge& e = edges[num];
            ll len = e.w + phi[u] - phi[e.v];
            if (e.f < e.c && d[u] + len < d[e.v]) {
                d[e.v] = d[u] + len;
                p[e.v] = num;
            }
        }
    }

    return p[t] != -1;
}

void mincost() {
    bellmanFord();
    while (dijk()) {
        for (int i = s; i <= t; ++i) {
            phi[i] += d[i];
        }

        int cmin = INF;
        for (int v = t; v != s;) {
            edge& e = edges[p[v]];
            cmin = min(cmin, e.c - e.f);
            v = e.u;
        }

        for (int v = t; v != s;) {
            edge& e = edges[p[v]];
            edge& re = edges[p[v] ^ 1];

            e.f += cmin;
            re.f -= cmin;
            v = e.u;
        }
    }
}

vector<int> op;
vector<int> stonks;

void getStonks(int num) {
    if (size(stonks) < k) {
        op.em_back(num);
        stonks.em_back(num);
    } else {
        if (size(stonks)) {
            op.em_back(-stonks.back());
        }
        op.em_back(num);

        if (size(stonks)) {
            stonks.pop_back();
        }
        stonks.em_back(num);
    }
}

bool check(int u, int v) {
    for (int num : g[u]) {
        edge& e = edges[num];
        if (e.v == v && e.f > 0 && e.c > 0) {
            return true;
        }
    }
    return false;
}

void calc() {
    op.clear();
    stonks.clear();
    for (int j = 1; j <= n; ++j) {
        for (int i = 1; i <= n; ++i) {
            int l = i, r = j + n;
            if (check(l, r)) {
                getStonks(i);
                break;
            }
        }
    }
}

void write() {
    cout << size(op) << "\n";
    for (int i : op) {
        cout << i << " ";
    }
    cout << "\n";
}

void solve() {
    read();
    prepare();
    mincost();
    calc();
    write();
}

int main() {
    ios::sync_with_stdio(0);
    cout.tie(0), cin.tie(0);

    int z = 1;
    cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}
