from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop
import math
from collections import *
from functools import reduce,cmp_to_key,lru_cache
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# import sys
# input = sys.stdin.readline

M = mod = 10**9 + 7 
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip().split()]
def st():return str(input().rstrip())[2:-1]
def val():return int(input().rstrip())
def li2():return [str(i)[2:-1] for i in input().rstrip().split()]
def li3():return [int(i) for i in st()]



for _ in range(val()):
    n,k = li()
    l = []
    for i in range(n):l.append(li() + [i])

    l.sort(key = lambda x:(-x[0],x[1]))
    he = []
    ans = []
    for i in range(k):
        for j in range(len(he)):
            he[j][0] += l[i][1]
        heappush(he,l[i])
        ans.append(l[i][2])
    maxans = sum(i[0] for i in he)
    maxiter = ans[:]
    l.sort(key= lambda x:(-x[1],x[0]))
    for i in range(k,n):
        ans.append(-heappop(he)[-1])
        currsum = 0
        for j in range(len(he)):
            he[j][0] += l[i][1]
            currsum += he[j][0]
        currsum += l[i][0]
        heappush(he,l[i])
        ans.append(l[i][2])
        if currsum > maxans:
            maxans = currsum
            maxiter = ans[:]
    for i in range(len(maxiter)):
        if maxiter[i] < 0:
            maxiter[i]-=1
        else:maxiter[i] += 1
    print(len(maxiter))
    print(*maxiter)
        