Running for Gold
The Olympic Games have just started and Federico is eager to watch the marathon race.There will be $$$n$$$ athletes, numbered from $$$1$$$ to $$$n$$$, competing in the marathon, and all of them have taken part in $$$5$$$ important marathons, numbered from $$$1$$$ to $$$5$$$, in the past. For each $$$1\le i\le n$$$ and $$$1\le j\le 5$$$, Federico remembers that athlete $$$i$$$ ranked $$$r_{i,j}$$$-th in marathon $$$j$$$ (e.g., $$$r_{2,4}=3$$$ means that athlete $$$2$$$ was third in marathon $$$4$$$).Federico considers athlete $$$x$$$ superior to athlete $$$y$$$ if athlete $$$x$$$ ranked better than athlete $$$y$$$ in at least $$$3$$$ past marathons, i.e., $$$r_{x,j}<r_{y,j}$$$ for at least $$$3$$$ distinct values of $$$j$$$.Federico believes that an athlete is likely to get the gold medal at the Olympics if he is superior to all other athletes.Find any athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes), or determine that there is no such athlete.
Explanation of the first test case: There is only one athlete, therefore he is superior to everyone else (since there is no one else), and thus he is likely to get the gold medal.Explanation of the second test case: There are $$$n=3$$$ athletes.   Athlete $$$1$$$ is superior to athlete $$$2$$$. Indeed athlete $$$1$$$ ranks better than athlete $$$2$$$ in the marathons $$$1$$$, $$$2$$$ and $$$3$$$.  Athlete $$$2$$$ is superior to athlete $$$3$$$. Indeed athlete $$$2$$$ ranks better than athlete $$$3$$$ in the marathons $$$1$$$, $$$2$$$, $$$4$$$ and $$$5$$$.  Athlete $$$3$$$ is superior to athlete $$$1$$$. Indeed athlete $$$3$$$ ranks better than athlete $$$1$$$ in the marathons $$$3$$$, $$$4$$$ and $$$5$$$. Explanation of the third test case: There are $$$n=3$$$ athletes.   Athlete $$$1$$$ is superior to athletes $$$2$$$ and $$$3$$$. Since he is superior to all other athletes, he is likely to get the gold medal.  Athlete $$$2$$$ is superior to athlete $$$3$$$.  Athlete $$$3$$$ is not superior to any other athlete. Explanation of the fourth test case: There are $$$n=6$$$ athletes.   Athlete $$$1$$$ is superior to athletes $$$3$$$, $$$4$$$, $$$6$$$.  Athlete $$$2$$$ is superior to athletes $$$1$$$, $$$4$$$, $$$6$$$.  Athlete $$$3$$$ is superior to athletes $$$2$$$, $$$4$$$, $$$6$$$.  Athlete $$$4$$$ is not superior to any other athlete.  Athlete $$$5$$$ is superior to athletes $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$, $$$6$$$. Since he is superior to all other athletes, he is likely to get the gold medal.  Athlete $$$6$$$ is only superior to athlete $$$4$$$. 
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow.The first line of each test case contains a single integer $$$n$$$ ($$$1\le n\le 50\,000$$$) — the number of athletes.Then $$$n$$$ lines follow, each describing the ranking positions of one athlete.The $$$i$$$-th of these lines contains the $$$5$$$ integers $$$r_{i,1},\,r_{i,2},\,r_{i,3},\,r_{i,4},\, r_{i,5}$$$ ($$$1\le r_{i,j}\le 50\,000$$$) — the ranking positions of athlete $$$i$$$ in the past $$$5$$$ marathons. It is guaranteed that, in each of the $$$5$$$ past marathons, the $$$n$$$ athletes have distinct ranking positions, i.e., for each $$$1\le j\le 5$$$, the $$$n$$$ values $$$r_{1,j},\, r_{2, j},\, \dots,\, r_{n, j}$$$ are distinct.It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$50\,000$$$.
For each test case, print a single integer — the number of an athlete who is likely to get the gold medal (that is, an athlete who is superior to all other athletes). If there are no such athletes, print $$$-1$$$. If there is more than such one athlete, print any of them.
t = int(input())

def solve():
    n = int(input())
    ranks = []
    for _ in range(n):
        ranks.append([int(x) for x in input().split()])
    winner = 0
    for i in range(1, n):
        count = 0
        for j in range(5):
            if ranks[i][j] < ranks[winner][j]:
                count += 1
        if count >= 3:
            winner = i
    for i in range(n):
        if winner == i:
            continue
        count = 0
        for j in range(5):
            if ranks[i][j] < ranks[winner][j]:
                count += 1
        if count >= 3:
            print(-1)
            return
    print(winner + 1)
for _ in range(t):
    solve()
import math
import itertools
import heapq
from math import floor, ceil
from collections import deque
import sys
from collections import Counter
I = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
input = sys.stdin.readline
sys.setrecursionlimit(10000)
MOD = 10 ** 9 + 7

def lcm(a, b):
    return abs(a * b) // math.gcd(a, b)

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def isSubsequence(s, t):
    for i in range(0, len(s)):
        try:
            index = t.index(s[i])
        except ValueError:
            return False
        t = t[index + 1:]
    return True

def bisect_right(a, x):
    (lo, hi) = (0, len(a))
    while lo < hi:
        mid = lo + (hi - lo) // 2
        if a[mid] > x:
            hi = mid
        else:
            lo = mid + 1
    return lo

def bisect_left(a, x):
    (lo, hi) = (0, len(a))
    while lo < hi:
        mid = lo + (hi - lo) // 2
        if a[mid] < x:
            lo = mid + 1
        else:
            hi = mid
    return lo

def binary_search(nums, target):
    (left, right) = (0, len(nums) - 1)
    while left <= right:
        pivot = left + (right - left) // 2
        if nums[pivot] == target:
            return pivot
        if target < nums[pivot]:
            right = pivot - 1
        else:
            left = pivot + 1
    return -1

def prefixSum(arr):
    dp = [arr[0]]
    arrLen = len(arr)
    for i in range(1, arrLen):
        dp.append(dp[-1] + arr[i])
    return dp

def suffixSum(arr):
    arrLen = len(arr)
    dp = [0] * arrLen
    dp[-1] = arr[-1]
    for i in range(N - 2, -1, -1):
        dp[i] = dp[i + 1] + arr[i]
    return dp

def fun():
    return
import math

def check(A, B):
    (q, w, e, r, t) = (A[0], A[1], A[2], A[3], A[4])
    (a, b, c, d, f) = (B[0], B[1], B[2], B[3], B[4])
    wins = [q < a, w < b, e < c, r < d, t < f]
    return wins.count(True) >= 3

def nCr(n, r):
    f = math.factorial
    return f(n) // f(r) // f(n - r)

def solve():
    N = int(input())
    games = []
    for i in range(N):
        games.append(I())
    winner = games[0][:]
    wid = 0
    for i in range(N):
        if i != wid:
            if check(games[wid], games[i]):
                pass
            else:
                wid = i
    ans = wid
    for i in range(N):
        if i != wid:
            if check(games[wid], games[i]):
                pass
            else:
                ans = -1
                break
    if ans != -1:
        print(ans + 1)
    else:
        print(ans)
TC = 1
TC = int(input())
for testcases in range(TC):
    solve()
def superior(athlete_i, athlete_j, ranks):
    count = 0
    for k in range(5):
        if ranks[athlete_i][k] < ranks[athlete_j][k]:
            count += 1
    if count >= 3:
        return True
    else:
        return False

def solve(n, ranks):
    gold = 0
    for i in range(n):
        if superior(i, gold, ranks):
            gold = i
    for i in range(n):
        if i == gold:
            continue
        if superior(i, gold, ranks):
            return -1
    return gold + 1
t = int(input())
for _ in range(t):
    n = int(input())
    ranks = [list(map(int, input().split())) for _ in range(n)]
    print(solve(n, ranks))