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])
    s = sum(i[1] for i in l)
    l.sort(key = lambda x:(x[0],-x[1]),reverse = 1)

    ans = []
    l[:k] = sorted(l[:k],key = lambda x:x[1])
    for i in range(k-1):
        ans.append(l[i][-1] + 1)

    for i in range(k,n):
        ans.append(l[i][-1] + 1)
        ans.append(-l[i][-1] - 1)
    ans.append(l[k-1][-1] + 1)
    

    print(len(ans))
    print(*ans)