#include <bits/stdc++.h>
using namespace std;
struct EdmondsKarp {
  struct edge {
    int from, to, f, cap, cost;
  };
  vector<vector<long long> > G;
  vector<edge> E;
  int source, sink;
  const int inf = 1e9;
  EdmondsKarp(int s, int t) : source(s), sink(t), G(t + 1){};
  void add_edge(int from, int to, int cap, int cost) {
    G[from].push_back(E.size());
    E.push_back({from, to, cap, cap, -cost});
    G[to].push_back(E.size());
    E.push_back({to, from, 0, cap, cost});
  }
  int solve() {
    auto bfs = [&]() {
      vector<int> dad(sink + 1, -1), e(sink + 1);
      vector<int> cost(sink + 1, 1e9);
      dad[source] = -2;
      cost[source] = 0;
      queue<int> q;
      q.push(source);
      while (!q.empty()) {
        int v = q.front();
        q.pop();
        if (v == sink) continue;
        for (int i = 0; i < G[v].size(); ++i) {
          int idx = G[v][i];
          int next = E[idx].to;
          if (E[idx].f) {
            if (cost[v] + E[idx].cost < cost[next]) {
              if (dad[next] == -1) q.push(next);
              dad[next] = v;
              e[next] = idx;
              cost[next] = cost[v] + E[idx].cost;
            }
          }
        }
      }
      if (dad[sink] == -1) return 0;
      int cur = sink, flow = inf;
      while (cur != source) {
        int idx = e[cur];
        flow = min(flow, E[idx].f);
        cur = dad[cur];
      }
      cur = sink;
      while (cur != source) {
        int idx = e[cur];
        E[idx].f -= flow;
        E[idx ^ 1].f += flow;
        cur = dad[cur];
      }
      return flow;
    };
    int flow = 0, f;
    while (f = bfs()) flow += f;
    return flow;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<int> data(n), cost(n);
    for (int i = 0; i < n; ++i) cin >> data[i] >> cost[i];
    int s = 0, t = 2 * n + 1;
    EdmondsKarp flow(s, t);
    for (int i = 1; i <= n; ++i) {
      flow.add_edge(s, i, 1, 0);
      flow.add_edge(i + n, t, 1, 0);
      for (int j = 1; j < m; ++j)
        flow.add_edge(i, j + n, 1, data[i - 1] + cost[i - 1] * (j - 1));
      for (int j = m; j < n; ++j)
        flow.add_edge(i, j + n, 1, cost[i - 1] * (m - 1));
      flow.add_edge(i, n + n, 1, data[i - 1] + cost[i - 1] * (m - 1));
    }
    flow.solve();
    vector<int> pos(n + 1);
    for (auto &e : flow.E) {
      if (e.from <= n && e.to > n && !e.f) pos[e.to - n] = e.from;
    }
    cout << m + (n - m) * 2 << "\n";
    for (int i = 1; i < m; ++i) cout << pos[i] << " ";
    for (int i = m; i < n; ++i) cout << pos[i] << " " << -pos[i] << " ";
    cout << pos[n] << "\n";
  }
  return 0;
}
