#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
struct mob {
  int a, b, id;
};
void solve() {
  int n, k;
  cin >> n >> k;
  vector<mob> m(n);
  for (int i = 0; i < n; ++i) {
    cin >> m[i].a >> m[i].b;
    m[i].id = i;
  }
  sort(m.begin(), m.end(), [&](mob a, mob b) { return a.b < b.b; });
  vector<vector<int>> dp(n + 1, vector<int>(k + 1, -inf));
  dp[0][0] = 0;
  vector<vector<int>> p = dp;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < k; ++j) {
      if (dp[i][j] >= 0) {
        if (dp[i + 1][j] < dp[i][j] + m[i].b * (k - 1)) {
          dp[i + 1][j] = dp[i][j] + m[i].b * (k - 1);
          p[i + 1][j] = j;
        }
        if (dp[i + 1][j + 1] < dp[i][j] + m[i].b * j + m[i].a) {
          dp[i + 1][j + 1] = dp[i][j] + m[i].b * j + m[i].a;
          p[i + 1][j + 1] = j;
        }
      }
    }
  }
  vector<int> g1, g2;
  int nn = k;
  for (int i = n; i; --i) {
    if (p[i][nn] == nn)
      g2.push_back(m[i - 1].id);
    else
      g1.push_back(m[i - 1].id);
    nn = p[i][nn];
  }
  reverse(g1.begin(), g1.end());
  reverse(g2.begin(), g2.end());
  cout << g1.size() + g2.size() * 2 << '\n';
  for (int i = 0; i < (int)g1.size() - 1; ++i) cout << g1[i] + 1 << ' ';
  for (int i = 0; i < (int)g2.size(); ++i)
    cout << g2[i] + 1 << ' ' << -(g2[i] + 1) << ' ';
  cout << g1.back() + 1 << '\n';
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) solve();
}
