#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAX = 5e3 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long MOD2 = 1000005329;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 2000;
int tc, n, k, res, nw;
pair<int, pair<int, int> > x[MAX];
vector<int> ans, tmp;
vector<pair<int, pair<int, int> > > v;
bool cmp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
  return a.first - a.second.first > b.first - b.second.first;
}
bool cmp2(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
  return a.second.first < b.second.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tc;
  for (long long ntc = 1; ntc <= tc; ++ntc) {
    cin >> n >> k;
    for (long long i = 1; i <= n; ++i)
      cin >> x[i].first >> x[i].second.first, x[i].second.second = i;
    res = 0;
    for (long long o = 1; o <= n; ++o) {
      v.clear(), tmp.clear();
      for (long long i = 1; i <= n; ++i)
        if (i != o) v.push_back(x[i]);
      sort(v.begin(), v.end(), cmp);
      sort(v.begin(), v.begin() + k, cmp2);
      nw = 0;
      for (long long i = 0; i <= k - 2; ++i)
        nw += v[i].first + i * v[i].second.first,
            tmp.push_back(v[i].second.second);
      for (long long i = k - 1; i <= n - 2; ++i)
        nw += (k - 1) * v[i].second.first, tmp.push_back(v[i].second.second),
            tmp.push_back(-v[i].second.second);
      nw += x[o].first + x[o].second.first * (k - 1),
          tmp.push_back(x[o].second.second);
      if (nw > res) res = nw, ans = tmp;
    }
    cout << ans.size() << '\n';
    for (auto i : ans) cout << i << ' ';
    cout << '\n';
  }
  return 0;
}
