#include <bits/stdc++.h>
using namespace std;
const int N = 333333, M = 12222222;
long long MOD = 1e9 + 7;
int intINF = int(1e9);
long long llINF = long long(2e18);
double eps = 1e-8;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
long double pi = acos(-1.0L);
long double s2 = sqrt(2.0);
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
inline char nc() {
  static char buf[100000], *p1, *p2;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
int rd() {
  int x = 0;
  char ch = nc();
  while (ch < '0' || ch > '9') ch = nc();
  while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = nc();
  return x;
}
struct node {
  long long a, b;
  int id;
} a[N];
struct record {
  int x, y, z;
} pre[111][111];
long long dp[111][111];
int ans[111], n, K;
vector<int> c;
bool cmp(node a, node b) { return a.b < b.b; }
void init() {
  n = read(), K = read();
  for (int i = (int)1; i <= (int)n; i++)
    a[i].a = readll(), a[i].b = readll(), a[i].id = i;
}
void solve() {
  sort(a + 1, a + n + 1, cmp);
  memset(dp, 0, sizeof(dp));
  memset(pre, 0, sizeof(pre));
  memset(ans, 0, sizeof(ans));
  for (int i = (int)1; i <= (int)n; i++) {
    for (int j = (int)0; j <= (int)i; j++) {
      if (j > K) continue;
      int k = i - j;
      if (k < 0 || k > n - K || k > i) continue;
      if (j - 1 >= 0) {
        long long t = dp[j - 1][k] + a[i].a + (j - 1) * a[i].b;
        if (t > dp[j][k]) {
          dp[j][k] = t;
          pre[j][k] = (record){j - 1, k, 0};
        }
      }
      if (k - 1 >= 0) {
        long long t = dp[j][k - 1] + a[i].b * (K - 1);
        if (t > dp[j][k]) {
          dp[j][k] = t;
          pre[j][k] = (record){j, k - 1, 1};
        }
      }
    }
  }
  printf("ans=%I64d\n", dp[K][n - K]);
  int i = K, j = n - K;
  while (i + j) {
    record tmp = pre[i][j];
    ans[i + j] = tmp.z;
    i = tmp.x, j = tmp.y;
  }
  c.clear();
  int s = 0;
  for (int i = (int)1; i <= (int)n; i++)
    if (!ans[i] && s + 1 <= K - 1) {
      c.push_back(a[i].id), s++;
    }
  for (int i = (int)1; i <= (int)n; i++)
    if (ans[i]) {
      c.push_back(a[i].id), c.push_back(-a[i].id);
    }
  for (int i = (int)n; i >= (int)1; i--)
    if (!ans[i]) {
      c.push_back(a[i].id);
      break;
    }
  printf("%d\n", (int)c.size());
  for (auto t : c) printf("%d ", t);
  printf("\n");
}
int main() {
  int cas = read();
  while (cas--) {
    init();
    solve();
  }
  return 0;
}
