for _ in range(int(input())):
    n, k = map(int, input().split())
    values = []
    for i in range(n):
        a, b = map(int, input().split())
        values.append((i + 1, a, b))
    
    if k == 1:
        best = -1
        score = 0
        for (i, a, b) in values:
            if a > score:
                best = i
                score = a

        print(best)
    
    else:
        values = sorted(values, key=lambda x: x[1], reverse=True)
        keepers = sorted(values[:k], key=lambda x: x[2])
        destroyers = sorted([x for x in values[k:] if x[2] > 0], key=lambda x: x[2])
        if len(destroyers):
            turns = []
            for i, a, b in keepers[:-1]:
                turns.append(i)
            
            for i, a, b in destroyers:
                turns.append(i)
                turns.append(-i)

            turns.append(keepers[-1][0])

        else:
            turns = [i for i,a, b in keepers]
        
        print(len(turns))
        print(*turns)
