#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> a(n);
    for (auto &i : a) cin >> i.first >> i.second;
    sort(a.begin(), a.end(), [](pair<int, int> x, pair<int, int> y) {
      return x.second < y.second;
    });
    vector<vector<int>> dp(n + 1, vector<int>(k + 2, -2e9));
    dp[0][0] = 0;
    for (int p = 0; p < n; ++p)
      for (int i = k; i >= 0; --i) {
        dp[p + 1][i + 1] =
            max(dp[p + 1][i + 1], dp[p][i] + a[p].first + i * a[p].second);
        dp[p + 1][i] = dp[p][i] + (k - 1) * a[p].second;
      }
    deque<int> d;
    int p = n, i = k;
    for (; p > 0; --p) {
      int c1 = -2e9, c0 = c1;
      if (i > 0)
        c1 = dp[p - 1][i - 1] + a[p - 1].first + (i - 1) * a[p - 1].second;
      c0 = dp[p - 1][i] + (k - 1) * a[p - 1].second;
      if (c1 == dp[p][i]) {
        d.push_front(p);
        --i;
        continue;
      }
      d.push_back(p);
      d.push_back(-p);
    }
    vector<int> ans;
    while (!d.empty()) ans.push_back(d.front()), d.pop_front();
    if (k != n) rotate(ans.begin() + k - 1, ans.begin() + k, ans.end());
    cout << ans.size() << "\n";
    for (auto &i : ans) cout << i << " \n"[&i == &ans.back()];
  }
  return 0;
}
