
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author MasterEx
 */
public class ECR87F {

    static class Minion {

        int pos;
        long power;
        long benefit;

        public Minion(int p, long po, long b) {
            pos = p + 1;
            power = po;
            benefit = b;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            int n = in.nextInt();
            int k = in.nextInt();
            LinkedList<Minion> minions = new LinkedList<>();
            for (int j = 0; j < n; j++) {
                long a = in.nextInt();
                long b = in.nextInt();
                minions.add(new Minion(j, a, b));
            }
            minions.sort((Minion m1, Minion m2) -> {
                if (m1.power == m2.power) {
                    return Long.compare(m1.benefit, m2.benefit);
                }
                return Long.compare(m2.power, m1.power);
            });
            String s = "";
            int m = 0;
            for (int j = 0; j < k - 1 && !minions.isEmpty(); j++) {
                m++;
                s += minions.removeFirst().pos + " ";
            }
            if (!minions.isEmpty()) {
                minions.sort((m1, m2) -> {
                    if (m1.benefit == m2.benefit) {
                        return Long.compare(m2.power, m1.power);
                    }
                    return Long.compare(m2.benefit, m1.benefit);
                });
            }
            while (!minions.isEmpty() && m <= 2 * n) {
                Minion minion = minions.removeFirst();
                m++;
                s += minion.pos;
                if (minion.benefit == 0
                        || !minions.isEmpty() && minion.benefit == minions.peek().benefit) {
                    break;
                }
                if (!minions.isEmpty()) {
                    m++;
                    s += " -" + minion.pos + " ";
                }
            }
            System.out.println(m);
            System.out.println(s);
        }
    }

}
