import functools
def my_cmp(o1, o2):
cnt = 0
for i in range(5):
if o1[i] < o2[i]:
cnt += 1
return -1 if cnt >= 3 else 1
for _ in range(int(input())):
n = int(input())
a = [list(map(int, input().split())) + [i + 1] for i in range(n)]
candidate = a[0]
for i in range(1, n):
if my_cmp(candidate, a[i]) > 0:
candidate = a[i]
good = True
for i in range(0, n):
if a[i] != candidate and my_cmp(candidate, a[i]) > 0:
good = False
break
if good:
print(candidate[5])
else:
print(-1)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
vector<vector<int> > a(n, vector<int>(5));
for(int i = 0;i < n;i++)
{
for(int j = 0;j < 5;j++)
{
//cout << "11111"<<endl;
cin >> a[i][j];
}
}
int id = 0;
for(int i = 1;i < n;i++)
{
int sum = 0;
for(int j = 0;j < 5;j++)
{
sum += a[i][j] < a[id][j];
}
if(sum >= 3)
{
id = i;
}
}
for(int i = 0;i < n;i++)
{
int sum = 0;
for(int j = 0;j < 5;j++)
{
sum += a[i][j] < a[id][j];
}
if(sum >= 3)
{
id = -2;
break;
}
}
cout << id + 1<< endl;
}
return 0;
}
507B - Amr and Pins | 379A - New Year Candles |
1154A - Restoring Three Numbers | 750A - New Year and Hurry |
705A - Hulk | 492B - Vanya and Lanterns |
1374C - Move Brackets | 1476A - K-divisible Sum |
1333A - Little Artem | 432D - Prefixes and Suffixes |
486A - Calculating Function | 1373B - 01 Game |
1187A - Stickers and Toys | 313B - Ilya and Queries |
579A - Raising Bacteria | 723A - The New Year Meeting Friends |
302A - Eugeny and Array | 1638B - Odd Swap Sort |
1370C - Number Game | 1206B - Make Product Equal One |
131A - cAPS lOCK | 1635A - Min Or Sum |
474A - Keyboard | 1343A - Candies |
1343C - Alternating Subsequence | 1325A - EhAb AnD gCd |
746A - Compote | 318A - Even Odds |
550B - Preparing Olympiad | 939B - Hamster Farm |