#include <bits/stdc++.h>
using namespace std;
struct Dinic {
  const static int maxn = 1000 + 10;
  const static int INT_INF = 1061109567;
  const static long long LLONG_INF = 4557430888798830399;
  struct Edge {
    int from, to;
    long long cap, flow, cost;
  };
  vector<Edge> edges;
  vector<int> G[maxn];
  bool ins[maxn];
  long long d[maxn], a[maxn], pre[maxn];
  long long maxFlow, minCost;
  void AddEdge(int from, int to, int cap, long long cost) {
    cost = -cost;
    edges.push_back((Edge){from, to, cap, 0, cost});
    edges.push_back((Edge){to, from, 0, 0, -cost});
    int m = edges.size();
    G[from].push_back(m - 2);
    G[to].push_back(m - 1);
  }
  bool BellManFord(int s, int t) {
    memset(d, 0x3f, sizeof(d));
    d[s] = 0;
    memset(pre, -1, sizeof(pre));
    memset(ins, false, sizeof(ins));
    ins[s] = true;
    queue<int> Q;
    Q.push(s);
    a[s] = LLONG_INF;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      ins[u] = false;
      for (int i = 0; i < (int)G[u].size(); i++) {
        Edge& e = edges[G[u][i]];
        if (e.cap > e.flow && d[e.to] > d[u] + e.cost) {
          d[e.to] = d[u] + e.cost;
          pre[e.to] = G[u][i];
          a[e.to] = min(a[u], e.cap - e.flow);
          if (!ins[e.to]) {
            Q.push(e.to);
            ins[e.to] = true;
          }
        }
      }
    }
    if (d[t] == LLONG_INF) {
      return false;
    }
    maxFlow += a[t];
    minCost += d[t] * a[t];
    for (int i = t; i != s; i = edges[pre[i]].from) {
      edges[pre[i]].flow += a[t];
      edges[pre[i] ^ 1].flow -= a[t];
    }
    return true;
  }
  void MCMF(int s, int t) {
    while (BellManFord(s, t))
      ;
  }
} mcmf[100];
const int N = 1000 + 10;
int a[N], b[N];
int main() {
  int T;
  scanf("%d", &T);
  for (int t = 1; t <= T; t++) {
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
      scanf("%d %d", a + i, b + i);
    }
    int S = 3 * n + 1, T = 3 * n + 2;
    for (int i = 1; i <= n; i++) {
      mcmf[t].AddEdge(S, i, 1, 0);
      mcmf[t].AddEdge(i + n, T, 1, 1e10);
      mcmf[t].AddEdge(i + n + k, T, 1, 0);
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= k; j++) {
        mcmf[t].AddEdge(i, j + n, 1, a[i] + (j - 1) * b[i]);
        mcmf[t].AddEdge(i, j + n + k, 1, (j - 1) * b[i]);
      }
    }
    mcmf[t].MCMF(S, T);
    vector<int> vec[2][N];
    int ans = 0;
    for (auto e : mcmf[t].edges) {
      if (e.flow == e.cap) {
        if (1 <= e.from && e.from <= n) {
          if (n + 1 <= e.to && e.to <= n + k) {
            vec[0][e.to - n].push_back(e.from);
            ans++;
          } else if (n + 1 + k <= e.to && e.to <= n + 2 * k && e.cost != 0) {
            vec[1][e.to - n - k].push_back(e.from);
            vec[1][e.to - n - k].push_back(-e.from);
            ans += 2;
          }
        }
      }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 2; j++) {
        for (auto k : vec[j][i]) {
          printf("%d ", k);
        }
      }
    }
    puts("");
  }
}
