#include <bits/stdc++.h>
using namespace std;
const int N = 80;
const long long inf = (long long)1e18;
long long dp[N][N][2];
int from_j[N][N][2];
int from_k[N][N][2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tn;
  cin >> tn;
  while (tn--) {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), p(n);
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= m; j++) {
        for (int k = 0; k <= 1; k++) {
          dp[i][j][k] = -inf;
        }
      }
    }
    dp[0][0][0] = 0;
    memset(from_j, -1, sizeof from_j);
    memset(from_k, -1, sizeof from_k);
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
      p[i] = i;
    }
    sort(p.begin(), p.end(), [&](const int& i, const int& j) {
      if (b[i] == b[j]) {
        return a[i] > a[j];
      }
      return b[i] < b[j];
    });
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= m; j++) {
        for (int k = 0; k < 2; k++) {
          if (dp[i + 1][j + 1][k] < dp[i][j][k] + j * 1LL * b[p[i]] + a[p[i]]) {
            dp[i + 1][j + 1][k] = max(
                dp[i + 1][j + 1][k], dp[i][j][k] + j * 1LL * b[p[i]] + a[p[i]]);
            from_j[i + 1][j + 1][k] = j;
            from_k[i + 1][j + 1][k] = k;
          }
          if (k == 0) {
            if (dp[i + 1][j + 1][k + 1] <
                dp[i][j][k] + (m - 1) * 1LL * b[p[i]] + a[p[i]]) {
              dp[i + 1][j + 1][k + 1] =
                  max(dp[i + 1][j + 1][k + 1],
                      dp[i][j][k] + (m - 1) * 1LL * b[p[i]] + a[p[i]]);
              from_j[i + 1][j + 1][k + 1] = j;
              from_k[i + 1][j + 1][k + 1] = k;
            }
          }
          if (dp[i + 1][j][k] < dp[i][j][k] + (m - 1) * 1LL * b[p[i]]) {
            dp[i + 1][j][k] =
                max(dp[i + 1][j][k], dp[i][j][k] + (m - 1) * 1LL * b[p[i]]);
            from_j[i + 1][j][k] = j;
            from_k[i + 1][j][k] = k;
          }
        }
      }
    }
    int i = n, j = m, k = (m < n);
    vector<int> keep;
    vector<int> dont_keep;
    int last = -1;
    while (i > 0) {
      int prev_i = i - 1;
      int prev_j = from_j[i][j][k];
      int prev_k = from_k[i][j][k];
      if (prev_j + 1 == j) {
        if (prev_k + 1 == k) {
          last = p[i - 1];
        } else {
          keep.push_back(p[i - 1]);
        }
      } else {
        dont_keep.push_back(p[i - 1]);
      }
      i = prev_i;
      j = prev_j;
      k = prev_k;
    }
    reverse(keep.begin(), keep.end());
    reverse(dont_keep.begin(), dont_keep.end());
    int ans_length = keep.size() + dont_keep.size() * 2 + (last > -1 ? 1 : 0);
    cout << ans_length << '\n';
    for (auto& e : keep) {
      cout << e + 1 << ' ';
    }
    for (auto& e : dont_keep) {
      cout << e + 1 << ' ';
      cout << -(e + 1) << ' ';
    }
    if (last > -1) {
      cout << last + 1 << ' ';
    }
    cout << '\n';
  }
  return 0;
}
