import sys
input = sys.stdin.readline
for f in range(int(input())):
    n,k=map(int,input().split())
    mons=[0]*n
    for i in range(n):
        mons[i]=[0,0,0,0]
        a,b=map(int,input().split())
        mons[i][1]=a
        mons[i][2]=b
        mons[i][0]=a-b
        mons[i][3]=i
    mons.sort(reverse=True)
    i=0
    m1=[]
    m2=[]
    while i<n and i<k-1:
        m1.append([0,0])
        m1[i][0]=mons[i][2]
        m1[i][1]=mons[i][3]
        i+=1
    if k==n:
        m1.append([0,0])
        m1[i][0]=mons[i][2]
        m1[i][1]=mons[i][3]
        i+=1
    while i<n:
        m2.append([0,0])
        m2[-1][0]=mons[i][1]
        m2[-1][1]=mons[i][3]
        i+=1
    m1.sort()
    m2.sort()
    sol=[]
    for x in m1:
        sol.append(x[1]+1)
    for x in m2:
        sol.append(x[1]+1)
        sol.append(-x[1]-1)
    if k<n:
        sol.pop(-1)
    print(len(sol))
    print(*sol)
        