import sys
 
readline = sys.stdin.readline
read = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
 
 
def solve():
    n, k = nm()
    mini = [tuple(nl() + [i+1]) for i in range(n)]
    mini.sort(key = lambda x: -x[1]*(10**5 + 1) -x[0])
    dp = [[-10**9]*(k+1) for _ in range(n+1)]
    # dp[i][j]: i 番目まで見て j 匹最後まで残す（採用する）
    dp[0][0] = 0
    f = [[0]*(k+1) for _ in range(n+1)] # 採用か否か
    for i in range(n):
        for j in range(k-1, -1, -1):
            if dp[i+1][j+1] < dp[i+1][j] + mini[i][0] + (k - j - 1)*mini[i][1]:
                dp[i+1][j+1] = dp[i+1][j] + mini[i][0] + (k - j - 1)*mini[i][1] # 自身を採用
                f[i+1][j+1] = 1
            if dp[i+1][j] < dp[i+1][j] + (k - 1) * mini[i][1]:
                dp[i+1][j] = dp[i+1][j] + (k - 1) * mini[i][1] # サポート役（消す）
    cx = k
    a = list()
    b = list()
    # 復元　採用フラグが立っていればa　それ以外はb
    for i in range(n, 0, -1):
        if f[i][cx]:
            a.append(mini[i-1][2])
            cx -= 1
        else:
            if mini[i-1][1]:
                b.append(mini[i-1][2])
    com = list()
    for x in a[:-1]:
        com.append(x)
    for x in b:
        com.append(x)
        com.append(-x)
    com.append(a[-1])
    print(len(com))
    print(*com)
    return
 
 
# solve()
 
T = ni()
for _ in range(T):
    solve()