def m(e):
  return e['m']
def h(e):
  return e['h']
a = int(input())
for i in range(a):
    num = [int(x) for x in input().split()]
    mi = []
    for j in range(num[0]):
        a = [int(x) for x in input().split()]
        k = {}
        k['m'] = a[0]
        k['h'] = a[1]
        k['i'] = j+1
        mi.append(k)
    mi.sort(key=m,reverse = True)
    cho = mi
    nch = mi
    cho = mi[:num[1]]
    nch = mi[num[1]:]
    klen = 0
    k = []
    for element in cho[:num[1]-1]:
        
        #print(element['i'],end = " ")
        k.append(element['i'])
        klen +=1
    #print()
    #print(nch)
    if(num[1]!=1):
        for element in nch:
            if(element['h']!=0):
                #print(element['i'],end = " ")
                #print(-1*element['i'],end = " ")
                k.append(element['i'])
                klen +=1
                k.append(-1*element['i'])
                klen +=1
    k.append(cho[num[1]-1]['i'])
    klen+=1
    #print(cho[num[1]-1]['i'],end = " ")
    print(klen)
    for j in k:
        print(j,end = " ")
    print()