#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = uint64_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = double;
namespace io {
auto unistd_read = read;
auto unistd_write = write;
const int BUFSIZE = 1 << 20;
int isize, osize;
char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10];
char *is, *it, *os = obuf, *ot = obuf + BUFSIZE;
char getchar() {
  if (is == it) {
    is = ibuf;
    it = ibuf + unistd_read(STDIN_FILENO, ibuf, BUFSIZE);
    if (is == it) return EOF;
  }
  return *is++;
}
char getalpha() {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  return c;
}
void putchar(char c) {
  *os++ = c;
  if (os == ot) {
    unistd_write(STDOUT_FILENO, obuf, BUFSIZE);
    os = obuf;
  }
}
int inp() {
  int x = 0, f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar()) {
    if (ch == EOF) return -1;
    if (ch == '-') f = 1;
  }
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return f ? -x : x;
}
ll inp_ll() {
  ll x = 0;
  int f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') f = 1;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return f ? -x : x;
}
template <class T>
bool read(T& x) {
  x = 0;
  int f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar()) {
    if (ch == EOF) return 0;
    if (ch == '-') f = 1;
  }
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (f) x = -x;
  return 1;
}
bool read(char* s) {
  char* t = s;
  char ch = getchar();
  for (; ch == ' ' || ch == '\n'; ch = getchar())
    ;
  for (; ch != ' ' && ch != '\n' && ch != EOF; ch = getchar()) *t++ = ch;
  *t = 0;
  return s != t;
}
template <class T, class... Args>
bool read(T& x, Args&... args) {
  return read(x) && read(args...);
}
template <class T>
bool readln(T& x) {
  x = 0;
  int f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar()) {
    if (ch == EOF) return 0;
    if (ch == '-') f = 1;
  }
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (f) x = -x;
  for (; ch != '\n' && ch != EOF; ch = getchar())
    ;
  return 1;
}
bool readln(char* s) {
  char* t = s;
  while (1) {
    char ch = getchar();
    if (ch == '\n' || ch == EOF) break;
    *t++ = ch;
  }
  *t = 0;
  return s != t;
}
template <class T, class... Args>
bool readln(T& x, Args&... args) {
  return read(x) && readln(args...);
}
template <class T>
void write(T x) {
  static char s[22];
  static char* it = s + 20;
  static char* end = s + 20;
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  do {
    *--it = x % 10 + '0';
    x /= 10;
  } while (x);
  for (; it < end; ++it) putchar(*it);
}
void write(const char* s) {
  for (; *s; ++s) putchar(*s);
}
template <>
void write(char* s) {
  write((const char*)s);
}
template <>
void write(char c) {
  putchar(c);
}
template <class T, class... Args>
void write(T x, Args... args) {
  write(x);
  write(args...);
}
void writeln() { putchar('\n'); }
template <class T, class... Args>
void writeln(T x, Args... args) {
  write(x);
  writeln(args...);
}
template <class Iterator>
bool input(Iterator st, Iterator ed) {
  for (; st != ed; ++st) {
    if (!read(*st)) return false;
  }
  return true;
}
template <class T>
bool input(T& a) {
  input(a.begin(), a.end());
}
template <class Iterator>
void print(Iterator st, Iterator ed, const char* c = " ") {
  int flag = 0;
  for (; st != ed; ++st) {
    if (flag) write(c);
    flag = 1;
    write(*st);
  }
  writeln();
}
template <class T>
void print(const T& a, const char* c = " ") {
  print(a.begin(), a.end(), c);
}
struct ender {
  ~ender() {
    if (os != obuf) unistd_write(STDOUT_FILENO, obuf, os - obuf);
  }
} __ender;
}  // namespace io
int64_t power(int64_t a, int64_t b, int64_t p) {
  if (!b) return 1;
  int64_t t = power(a, b >> 1, p);
  t = t * t % p;
  if (b & 1) t = t * a % p;
  return t;
}
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
using namespace io;
template <class T>
inline void freshmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
inline void freshmax(T& a, const T& b) {
  if (a < b) a = b;
}
const ll B = 31;
const ll MOD = 1000000007;
const int INF = 1000000010;
const ll INFll = 4000000000000000000LL;
const int MAXN = 5010;
int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
ld det(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3) {
  return x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3;
}
namespace KM {
using T = int;
const int MAXN = 110;
const T INF = 1000000000;
int nx, ny;
int times;
T v[MAXN][MAXN];
T ex[MAXN], ey[MAXN];
T slack[MAXN];
int ux[MAXN], uy[MAXN], mx[MAXN], my[MAXN], pre[MAXN];
void match(int y) {
  while (y) {
    my[y] = pre[y];
    swap(y, mx[pre[y]]);
  }
}
void bfs(int sx) {
  for (int y = 1; y <= ny; ++y) slack[y] = INF;
  queue<int> Q;
  Q.push(sx);
  ++times;
  while (1) {
    while (!Q.empty()) {
      int x = Q.front();
      Q.pop();
      ux[x] = times;
      T gap;
      for (int y = 1; y <= ny; ++y)
        if (uy[y] != times && (gap = ex[x] + ey[y] - v[x][y]) <= slack[y]) {
          pre[y] = x;
          if (!gap) {
            uy[y] = times;
            if (!my[y])
              return match(y);
            else
              Q.push(my[y]);
          } else
            slack[y] = gap;
        }
    }
    T d = INF;
    for (int y = 1; y <= ny; ++y)
      if (uy[y] != times) freshmin(d, slack[y]);
    for (int x = 1; x <= nx; ++x)
      if (ux[x] == times) ex[x] -= d;
    for (int y = 1; y <= ny; ++y)
      if (uy[y] == times)
        ey[y] += d;
      else
        slack[y] -= d;
    for (int y = 1; y <= ny; ++y)
      if (uy[y] != times && !slack[y]) {
        uy[y] = times;
        if (!my[y])
          return match(y);
        else
          Q.push(my[y]);
      }
  }
}
int KM() {
  for (int y = 1; y <= ny; ++y) {
    my[y] = 0;
    ey[y] = 0;
    uy[y] = 0;
  }
  for (int x = 1; x <= nx; ++x) {
    mx[x] = 0;
    ex[x] = *max_element(v[x] + 1, v[x] + ny + 1);
    ux[x] = 0;
  }
  for (int x = 1; x <= nx; ++x) bfs(x);
  T ans = 0;
  for (int y = 1; y <= ny; ++y) ans += v[my[y]][y];
  return ans;
}
void init(int nx_, int ny_) {
  nx = nx_;
  ny = ny_;
  for (int i = 1; i <= nx; ++i)
    for (int j = 1; j <= ny; ++j) v[i][j] = 0;
}
void addedge(int x, int y, T z) { v[x][y] = z; }
}  // namespace KM
int n, k;
void solve() {
  read(n, k);
  KM::init(n, n);
  for (int i = 1; i <= n; ++i) {
    int a, b;
    read(a, b);
    for (int j = 1; j <= n; ++j)
      if (j < k)
        KM::addedge(i, j, a + b * (j - 1));
      else if (j == n)
        KM::addedge(i, j, a + b * k);
      else
        KM::addedge(i, j, b * k);
  }
  int res = KM::KM();
  vector<int> ans;
  for (int j = 1; j < k; ++j) ans.push_back(KM::my[j]);
  for (int j = k; j < n; ++j)
    ans.push_back(KM::my[j]), ans.push_back(-KM::my[j]);
  ans.push_back(KM::my[n]);
  writeln<int>(ans.size());
  print(ans);
}
int main() {
  int T = 1;
  read(T);
  for (int test = 1; test <= T; ++test) {
    solve();
  }
  return 0;
}
