#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> a(n), b(n), id(n);
vector<int> L;
void solve() {
  cin >> n >> k;
  a.resize(n);
  b.resize(n);
  id.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
    id[i] = i;
  }
  int ans = 0, ret = 0;
  auto run = [](int cur, int &ans, int &ret) {
    for (int i = 0; i < n; ++i) b[i] *= (cur != k ? cur : cur - 1);
    L.resize(0);
    sort(id.begin(), id.end(),
         [](int i, int j) { return a[i] + b[j] > a[j] + b[i]; });
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += (i < cur ? a[id[i]] : b[id[i]]);
      if (cur == k && i == 0) continue;
      L.push_back(id[i] + 1);
      if (i >= cur) L.push_back(-id[i] - 1);
    }
    if (cur == k) L.push_back(id[0] + 1);
    if (sum > ans) {
      ans = sum;
      ret = cur;
    }
    for (int i = 0; i <= n; ++i) b[i] /= cur;
  };
  for (int cur = 1; cur <= k; ++cur) run(cur, ans, ret);
  run(ret, ans, ret);
  cout << L.size() << '\n';
  for (auto i : L) cout << i << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
