#include <bits/stdc++.h>
using namespace std;
bool cmp(array<int, 3> a, array<int, 3> b) {
  if (a[1] != b[1]) return a[1] < b[1];
  return a[0] < b[0];
}
int main() {
  ios_base::sync_with_stdio(0);
  istream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  for (; q > 0; q--) {
    int n, k;
    cin >> n >> k;
    vector<array<int, 3> > g(n);
    for (int i = 0; i < n; i++) {
      cin >> g[i][0] >> g[i][1];
      g[i][2] = i;
    }
    sort(g.begin(), g.end(), cmp);
    pair<long long, vector<int> > f[n + 1][k + 1];
    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= k; j++) f[i][j].first = -1;
    vector<int> nl;
    nl.clear();
    f[0][0] = {0, nl};
    nl.push_back(g[0][2] + 1);
    f[0][1] = {g[0][0], nl};
    for (int i = 0; i < n - 1; i++)
      for (int j = 0; j < k; j++) {
        if (f[i][j].first == -1) continue;
        long long sum = f[i][j].first;
        vector<int> gr = f[i][j].second;
        if (sum + g[i + 1][1] * (k - 1) > f[i + 1][j].first)
          f[i + 1][j] = {sum + g[i + 1][1] * (k - 1), gr};
        sum += g[i + 1][0] + j * g[i + 1][1];
        gr.push_back(g[i + 1][2] + 1);
        if (sum > f[i + 1][j + 1].first) f[i + 1][j + 1] = {sum, gr};
      }
    vector<int> event = f[n - 1][k].second;
    int last = event.back();
    bool mk[n + 1];
    memset(mk, 0, sizeof(mk));
    for (auto it : event) mk[it] = 1;
    event.pop_back();
    for (int i = 0; i < n; i++) {
      int nm = g[i][2] + 1;
      if (mk[nm]) continue;
      event.push_back(nm);
      event.push_back(-nm);
    }
    event.push_back(last);
    cout << int(event.size()) << '\n';
    for (auto it : event) cout << it << " ";
    cout << '\n';
  }
}
