#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 76 * 78;
const int maxm = maxn * 2;
int cnt;
struct Edge {
  int from, to, cap, flow, cost;
  Edge() {}
  Edge(int u, int v, int ca, int fl, int co)
      : from(u), to(v), cap(ca), flow(fl), cost(co) {}
};
struct MCFC {
  int n, m, s, t;
  Edge edges[maxm];
  int first[maxn];
  int next[maxm];
  int inq[maxn];
  int d[maxm];
  int p[maxn];
  int a[maxn];
  int Q[maxn];
  MCFC() {}
  void init(int n) {
    this->n = n;
    memset(first, -1, sizeof(first));
    m = 0;
  }
  void addEdge(int u, int v, int cap, int cost) {
    edges[m] = Edge(u, v, cap, 0, cost);
    next[m] = first[u];
    first[u] = m++;
    edges[m] = Edge(v, u, 0, 0, -cost);
    next[m] = first[v];
    first[v] = m++;
  }
  bool bellmanFord(int s, int t, int &flow, long long &cost) {
    for (int i = 0; i < n; i++) d[i] = INF;
    memset(inq, false, sizeof(inq));
    d[s] = 0;
    inq[s] = true;
    p[s] = 0;
    a[s] = INF;
    int front, rear;
    Q[rear = front = 0] = s;
    while (front <= rear) {
      int u = Q[front++];
      inq[u] = false;
      for (int i = first[u]; i != -1; i = next[i]) {
        Edge &e = edges[i];
        if (e.cap > e.flow && d[e.to] > d[u] + e.cost) {
          d[e.to] = d[u] + e.cost;
          p[e.to] = i;
          a[e.to] = min(a[u], e.cap - e.flow);
          if (!inq[e.to]) {
            Q[++rear] = e.to;
            inq[e.to] = true;
          }
        }
      }
    }
    if (d[t] == INF) return false;
    flow += a[t];
    cost += (long long)d[t] * (long long)a[t];
    int u = t;
    while (u != s) {
      edges[p[u]].flow += a[t];
      edges[p[u] ^ 1].flow -= a[t];
      u = edges[p[u]].from;
    }
    return true;
  }
  int mincostMaxflow(int s, int t, long long &cost) {
    int flow = 0;
    cost = 0;
    while (bellmanFord(s, t, flow, cost))
      ;
    return flow;
  }
} g;
int res[120], pos;
int A[120], B[120];
int main() {
  int T, N, K, s, t, u, v, cap, cost, totFlow = 0;
  long long totCost = 0;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &N, &K);
    for (int i = 1; i <= N; ++i) scanf("%d %d", &A[i], &B[i]);
    if (N == K) {
      printf("%d\n", N);
      for (int i = 1; i <= N; ++i) {
        int minp = 1;
        for (int j = 1; j <= N; ++j)
          if (B[j] < B[minp]) minp = j;
        B[minp] = INF;
        printf("%d ", minp);
      }
      printf("\n");
      continue;
    }
    for (int i = 1; i <= N; ++i) res[i] = 0;
    pos = K;
    cnt = 0;
    s = 0;
    t = N * K + N + K + 9;
    g.init(t + 1);
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= K; ++j) {
        u = i, v = N + (i - 1) * K + j, cap = 1,
        cost = -(A[i] + (j - 1) * B[i]);
        g.addEdge(u, v, cap, cost);
      }
      u = i, v = t, cap = 1, cost = -((K - 1) * B[i]);
      g.addEdge(u, v, cap, cost);
    }
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= K; ++j) {
        u = N + (i - 1) * K + j, v = N * K + N + j, cap = 1, cost = 0;
        g.addEdge(u, v, cap, cost);
      }
    }
    for (int i = 1; i <= N; ++i) {
      u = s, v = i, cap = 1, cost = 0;
      g.addEdge(u, v, cap, cost);
    }
    for (int j = 1; j <= K; j++) {
      u = N * K + N + j, v = t, cap = 1, cost = 0;
      g.addEdge(u, v, cap, cost);
    }
    totFlow = g.mincostMaxflow(s, t, totCost);
    for (int i = 0; i < N * K + N; ++i) {
      if (g.edges[i << 1].flow == 1) {
        if (i % (K + 1) + 1 <= K)
          res[i % (K + 1) + 1] = i / (K + 1) + 1;
        else
          res[++pos] = i / (K + 1) + 1;
      }
    }
    printf("%d\n", K + 2 * (N - K));
    for (int i = 1; i <= K - 1; ++i) printf("%d ", res[i]);
    for (int i = K + 1; i <= N; ++i) printf("%d %d ", res[i], -res[i]);
    printf("%d\n", res[K]);
  }
  return 0;
}
