import sys
t = int(input())
for _ in range(t):
    n = int(input())
    A,B,C = [],[],[]
    for i in range(n):
        a,b,c = map(int,sys.stdin.readline().split())
        A.append(a)
        B.append(b)
        C.append(c)
    maxvals = [(-1,-1,)]
    for i in range(n):
        if C[i] >= maxvals[-1][0]:
            maxvals.append((C[i],i,))
    j = len(maxvals)-1
    maxinds = [maxvals[-1][1]]
    while j > 0 and maxvals[j-1][0] == maxvals[j][0]:
        maxinds.append(maxvals[j-1][1])
        j-=1
    