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]:]
    ksum = 0
    klen = 0
    k = []
    cho.sort(key=h)
    for element in cho[:num[1]-1]:
        
        #print(element['i'],end = " ")
        k.append(element['i'])
        klen +=1
        ksum+=element['m']
        ksum+=element['h']*(klen-1)
    fix = klen
    #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
                ksum+=(element['h']*fix)
    k.append(cho[num[1]-1]['i'])
    klen+=1
    ksum+=cho[num[1]-1]['m']
    ksum+=cho[num[1]-1]['h']*(klen-1)
    #print(cho[num[1]-1]['i'],end = " ")
    
    mi.sort(key = h)
    csum = 0
    clen = 0
    c = []
    if(num[1]>1):
        c.append(mi[0]['i'])
        clen +=1
        csum+=mi[0]['m']
        mi = mi[1:]
        mi.sort(key=m,reverse = True)
        cho = mi
        nch = mi
        cho = mi[:num[1]-1]
        nch = mi[num[1]-1:]
        cho.sort(key=h)
        for element in cho[:num[1]-2]:
            
            #print(element['i'],end = " ")
            c.append(element['i'])
            clen +=1
            csum+=element['m']
            csum+=element['h']*(clen-1)
        fix = clen
        #print()
        #print(nch)
        if(num[1]!=1):
            for element in nch:
                if(element['h']!=0):
                    #print(element['i'],end = " ")
                    #print(-1*element['i'],end = " ")
                    c.append(element['i'])
                    clen +=1
                    c.append(-1*element['i'])
                    clen +=1
                    csum+=(element['h']*fix)
        c.append(cho[num[1]-2]['i'])
        clen+=1
        csum+=cho[num[1]-2]['m']
        csum+=cho[num[1]-2]['h']*(clen-1)
        #print(cho[num[1]-1]['i'],end = " ")
    if(csum>ksum):
        print(clen)
        for j in c:
            print(j,end = " ")
        print()
    else:
        print(klen)
        for j in k:
            print(j,end = " ")
        print()
    '''        print(c)
        print(csum)
        print(k)
        print(ksum)'''
""""5 5
60005 41309
13864 47046
63344 20154
42138 43756
16588 37266 
5
3 1 4 5 2 
5
3 5 1 4 2 
"""