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])
    # print(mini)
    dp = [-10**9]*(k+1)
    dp[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[j+1] < dp[j] + mini[i][0] + (k - j - 1)*mini[i][1]:
                dp[j+1] = dp[j] + mini[i][0] + (k - j - 1)*mini[i][1]
                f[i+1][j+1] = 1
            if dp[j] < dp[j] + (k - 1) * mini[i][1]:
                dp[j] = dp[j] + (k - 1) * mini[i][1]
        # print(dp)
            
  
    cx = k
    a = list()
    b = list()
    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()
