import heapq

def solve():
    n, k = map(int, input().split())
    people = []
    for i in range(n):
        x, y = map(int, input().split())
        people.append((x, y, i+1))
    
    for _ in range(2):
        people = sorted(people)
        pq = []
        for x, y, i in people:
            while len(pq) and pq[0][0] + k <= y:
                heapq.heappop(pq)
            heapq.heappush(pq, (y, x, i))
        people = pq
    
    res = []
    for x, y, i in people:
        res.append(i)
    res = sorted(res)
    print(len(res))
    print(*res)

t = int(input())
for ti in range(t):
    solve()
