#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return a.first.first > b.first.first;
}
int Main() {
  int n, k;
  cin >> n >> k;
  vector<pair<pair<int, int>, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first.second >> a[i].first.first;
    a[i].second = i;
  }
  sort(a.begin(), a.end(), cmp);
  vector<vector<int> > DP(k + 1, vector<int>(n + 1));
  vector<vector<bool> > op(k + 1, vector<bool>(n + 1));
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= n; j++) {
      DP[i][j] = max(DP[i - 1][j - 1] + a[j - 1].first.second +
                         (i - 1) * a[j - 1].first.first,
                     DP[i][j - 1] + a[j - 1].first.first * (k - 1));
      if (DP[i][j] == DP[i - 1][j - 1] + a[j - 1].first.second +
                          (i - 1) * a[j - 1].first.first)
        op[i][j] = 1;
    }
  }
  vector<int> steps;
  int i = k;
  int j = n;
  while (i != 0 && j != 0) {
    if (op[i][j]) {
      steps.push_back(j - 1);
      j--;
      i--;
    } else {
      j--;
    }
  }
  reverse(steps.begin(), steps.end());
  vector<int> rez;
  vector<bool> Added(n);
  for (int i = 0; i < steps.size() - 1; i++) {
    rez.push_back(a[steps[i]].second + 1);
    Added[steps[i]] = 1;
  }
  Added[steps[steps.size() - 1]] = 1;
  for (int i = 0; i < n; i++) {
    if (Added[i]) continue;
    rez.push_back(a[i].second + 1);
    rez.push_back(-(a[i].second + 1));
  }
  rez.push_back(a[steps[steps.size() - 1]].second + 1);
  cout << rez.size() << endl;
  for (int i = 0; i < rez.size(); i++) {
    cout << rez[i] << " ";
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) Main();
}
