#include <bits/stdc++.h>
using namespace std;
template <class T>
using V = vector<T>;
template <class T, size_t SZ>
using AR = array<T, SZ>;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); }
long long cdiv(long long a, long long b) {
  return a / b + ((a ^ b) > 0 && a % b);
}
long long fdiv(long long a, long long b) {
  return a / b - ((a ^ b) < 0 && a % b);
}
long long half(long long x) { return fdiv(x, 2); }
template <class T, class U>
T fstTrue(T lo, T hi, U first) {
  hi++;
  assert(lo <= hi);
  while (lo < hi) {
    T mid = half(lo + hi);
    first(mid) ? hi = mid : lo = mid + 1;
  }
  return lo;
}
template <class T, class U>
T lstTrue(T lo, T hi, U first) {
  lo--;
  assert(lo <= hi);
  while (lo < hi) {
    T mid = half(lo + hi + 1);
    first(mid) ? lo = mid : hi = mid - 1;
  }
  return lo;
}
template <class T>
void remDup(vector<T>& v) {
  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
}
template <class A>
void re(complex<A>& c);
template <class A, class B>
void re(pair<A, B>& p);
template <class A>
void re(vector<A>& v);
template <class A, size_t SZ>
void re(array<A, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& d) {
  string t;
  re(t);
  d = stod(t);
}
void re(long double& d) {
  string t;
  re(t);
  d = stold(t);
}
template <class H, class... T>
void re(H& h, T&... t) {
  re(h);
  re(t...);
}
template <class A>
void re(complex<A>& c) {
  A a, b;
  re(a, b);
  c = {a, b};
}
template <class A, class B>
void re(pair<A, B>& p) {
  re(p.first, p.second);
}
template <class A>
void re(vector<A>& x) {
  for (auto& a : x) re(a);
}
template <class A, size_t SZ>
void re(array<A, SZ>& x) {
  for (auto& a : x) re(a);
}
string to_string(char c) { return string(1, c); }
string to_string(const char* second) { return (string)second; }
string to_string(string second) { return second; }
string to_string(bool b) { return to_string((int)b); }
template <class A>
string to_string(complex<A> c) {
  stringstream ss;
  ss << c;
  return ss.string();
}
string to_string(vector<bool> v) {
  string res = "{";
  for (int i = (0); i < ((int)(v).size()); ++i) res += char('0' + v[i]);
  res += "}";
  return res;
}
template <size_t SZ>
string to_string(bitset<SZ> b) {
  string res = "";
  for (int i = (0); i < (SZ); ++i) res += char('0' + b[i]);
  return res;
}
template <class A, class B>
string to_string(pair<A, B> p);
template <class T>
string to_string(T v) {
  bool fst = 1;
  string res = "";
  for (const auto& x : v) {
    if (!fst) res += " ";
    fst = 0;
    res += to_string(x);
  }
  return res;
}
template <class A, class B>
string to_string(pair<A, B> p) {
  return to_string(p.first) + " " + to_string(p.second);
}
template <class A>
void pr(A x) {
  cout << to_string(x);
}
template <class H, class... T>
void pr(const H& h, const T&... t) {
  pr(h);
  pr(t...);
}
void ps() { pr("\n"); }
template <class H, class... T>
void ps(const H& h, const T&... t) {
  pr(h);
  if (sizeof...(t)) pr(" ");
  ps(t...);
}
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << to_string(h);
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int max(int a, int b, int c) { return max(a, max(b, c)); }
int min(int a, int b, int c) { return min(a, min(b, c)); }
long long max(long long a, long long b, long long c) {
  return max(a, max(b, c));
}
long long min(long long a, long long b, long long c) {
  return min(a, min(b, c));
}
void dbga(int arr[], int n) {
  vector<int> v;
  for (int i = (0); i < (n); ++i) v.push_back(arr[i]);
  0;
}
void dbga(long long arr[], int n) {
  vector<int> v;
  for (int i = (0); i < (n); ++i) v.push_back(arr[i]);
  0;
}
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(string second = "") {
  unsyncIO();
  if ((int)(second).size()) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
const int MOD = 1e9 + 7;
const int MX = 75 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
int n, k;
int dp[MX][MX];
vector<pair<pair<int, int>, int> > ev;
vector<int> del;
vector<int> ord;
int LST = -1;
void CONSTRUCT(int i, int j) {
  if (i == 0) return;
  if (i - 1 == LST) {
    CONSTRUCT(i - 1, j - 1);
    return;
  }
  int a = ev[i - 1].first.second, b = ev[i - 1].first.first;
  if (j && dp[i][j] == dp[i - 1][j - 1] + (j - 1) * b + a) {
    ord.push_back(i - 1);
    CONSTRUCT(i - 1, j - 1);
  } else {
    assert(dp[i][j] == dp[i - 1][j] + (k - 1) * b);
    del.push_back(i - 1);
    CONSTRUCT(i - 1, j);
  }
}
void solve() {
  ev.clear();
  del.clear();
  ord.clear();
  re(n, k);
  for (int i = (0); i < (n); ++i) {
    int a, b;
    re(a, b);
    ev.push_back({{b, a}, i + 1});
  }
  sort(begin(ev), end(ev));
  0;
  for (int i = (0); i < (n + 1); ++i)
    for (int j = (0); j < (k + 1); ++j) dp[i][j] = -MOD;
  dp[0][0] = 0;
  int mx = 0;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (k + 1); ++j) {
      int a = ev[i].first.second, b = ev[i].first.first;
      ckmax(dp[i + 1][j + 1], dp[i][j] + a + j * b);
      ckmax(dp[i + 1][j], dp[i][j] + (k - 1) * b);
    }
  LST = n - 1;
  ps(dp[n][k]);
  CONSTRUCT(n, k);
  0;
  reverse(begin(ord), end(ord));
  0;
  ps((int)(ord).size() + 1 + 2 * (int)(del).size());
  for (auto& x : ord) pr(ev[x].second, " ");
  for (auto& x : del) pr(ev[x].second, " ", -ev[x].second, " ");
  ps(ev[LST].second);
}
int main() {
  setIO();
  int t = 1;
  re(t);
  while (t--) solve();
}
