fork download
  1. import math
  2.  
  3. def f(i,j):
  4. if i==-1:
  5. return False
  6. if i==j:
  7. return True
  8. ct=0
  9.  
  10. for k in range(5):
  11. if r[i][k]<r[j][k]:
  12. ct+=1
  13.  
  14. return ct>=3
  15.  
  16.  
  17. T=int(input())
  18. # T=1
  19. for __ in range(T):
  20. n=int(input())
  21. r=[]
  22. for i in range(n):
  23. tmp=list(map(int,input().split()))
  24. r.append(tmp)
  25. # print(r)
  26. mx=-1
  27.  
  28. for i in range(n):
  29. if f(mx,i):
  30. continue
  31. else:
  32. mx=i
  33.  
  34. fg=True
  35. for i in range(n):
  36. if f(mx,i):
  37. continue
  38. else:
  39. fg=False
  40.  
  41. if fg:
  42. print(mx+1)
  43.  
  44. continue
  45. print(-1)
  46.  
Success #stdin #stdout 0.07s 14208KB
stdin
4
1
50000 1 50000 50000 50000
3
10 10 20 30 30
20 20 30 10 10
30 30 10 20 20
3
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
6
9 5 3 7 1
7 4 1 6 8
5 6 7 3 2
6 7 8 8 6
4 2 2 4 5
8 3 6 9 4
stdout
1
-1
1
5