Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. 

Every Friday Chef and his N - 1 friends go for a party. At these parties, they play board games. This Friday, they are playing a game named "Boats! Boats! Boats!". In this game players have to transport cookies between Venice and Constantinople. Each player has a personal storage. The players are numbered from 1 to N, Chef is numbered 1. Rules for determining a winner are very difficult, therefore Chef asks you to write a program, which will determine who is a winner. 

There are 6 types of cookies. For each cookie in the storage player gets 1 point. Also player gets additional points if he packs his cookies in some boxes as follows: 
A box containing 4 different types of cookies fetches 1 additional point.
A box containing 5 different types of cookies fetches 2 additional points.
A box containing 6 different types of cookies fetches 4 additional points.

Obviously a cookie can be put into a single box.

For each player, you know the number of cookies in his storage (denoted by c[i]), also the types of cookies in the storage given denoted by type[i][j].

Your task is to determine the winner of this game. Output "tie" if there are two or more players with same maximum score, "chef" if only Chef has a maximum score, winner's index in all other cases.

------ Input ------ 

The first line of input contains a single integer T denoting the number of test cases. This will be followed by T test cases.
The first line of each test case contains an integer N denoting the number of players.
The second line of each test case contains an integer c[i] denoting the number of cookies in the i-th storage, followed by c[i] space-separated integers type[i][j] which denote the type if j-th cookie in the storage i-th.

------ Output ------ 

For each test case, output a single line containing the answer as specified in the statement.
  
------ 
------ Constraints -----
Subtask #1 : (20 points)  
$1 ≤ T ≤ 10 $
$1 ≤  N  ≤ 100  $
$1 ≤  c[i]  ≤  100  $
$1 ≤  type[i][j]  ≤  3  $
Subtask #2 : (80 points)  
$1 ≤ T ≤ 10 $
$1 ≤  N  ≤ 100  $
$1 ≤  c[i]  ≤  100  $
$1 ≤  type[i][j]  ≤  6  $

----- Sample Input 1 ------ 
3
2
6 1 2 3 4 5 6
9 3 3 3 4 4 4 5 5 5
2
5 2 3 4 5 6
7 1 1 2 2 3 3 4
3
4 1 1 2 3
4 1 2 2 3
4 1 2 3 3
----- Sample Output 1 ------ 
chef
2
tie
----- explanation 1 ------ 
Example case 1.
Chef has total 6 cookie, so he gets 6 points for that. Also, he can put all his cookies (as they are all distinct) in a bag of size 6. It will fetch him additional 4 points. So, Chef's total points will be 10.
The second player has 9 cookies, he gets 9 points for that. Other than this, he can't create a bag with either 4, 5 or 6 distinct cookies. So, his final score is 9.
10 > 9 - Chef wins.

Example case 2.
Chef has 5 + 2 (a bag with 5 different cookies) = 7.
The second player has 7 + 1(a bag with 4 different cookies) = 8.
7 

Example case 3.
Every player has 4 cookies and can't create any bag of sweets. So, it's a tie.

Difficulty: MEDIUM
Tags: Bit manipulation

Constructive algorithms

Mathematics

Ad-hoc
Skill types: Bit manipulation

Starter code:

Solutions:
t = int(input())
for fh in range(t):
	n = int(input())
	arr = [list(map(int, input().split())) for ifir in range(n)]
	c = [0] * n
	m = 0
	for i in range(n):
		s = arr[i][0]
		arr[i].remove(s)
		uni = len(set(arr[i]))
		unis = set(arr[i])
		while uni > 3:
			if uni == 4:
				s += 1
			if uni == 5:
				s += 2
			if uni == 6:
				s += 4
			for jj in unis:
				arr[i].remove(jj)
			uni = len(set(arr[i]))
			unis = set(arr[i])
		c[i] = s
		if s > m:
			m = s
			indx = i
	if c.count(m) > 1:
		print('tie')
	elif indx == 0:
		print('chef')
	else:
		print(indx + 1)


def ser(l):
	s = [l.count(1), l.count(2), l.count(3), l.count(4), l.count(5), l.count(6)]
	s.sort()
	if len(s) == 6:
		return len(l) + 4 * s[0] + 2 * (s[1] - s[0]) + (s[2] - s[1])
	elif len(s) == 5:
		return len(l) + 2 * s[0] + (s[1] - s[0])
	elif len(s) == 4:
		return len(l) + s[0]
	else:
		return len(l)
for _ in range(int(input())):
	n = int(input())
	l = []
	c = []
	for i in range(n):
		d = list(map(int, input().split()))
		l.append(d[1:])
	for i in range(n):
		c.append(ser(l[i]))
	if c.count(max(c)) > 1:
		print('tie')
	elif c[0] == max(c):
		print('chef')
	else:
		print(c.index(max(c)) + 1)


def cal(l, arr):
	s = l
	st = len(set(arr))
	ast = set(arr)
	while st > 3:
		if st == 4:
			s += 1
		elif st == 5:
			s += 2
		elif st == 6:
			s += 4
		for i in ast:
			arr.remove(i)
		ast = set(arr)
		st = len(ast)
	return s
for _ in range(int(input())):
	n = int(input())
	ans = []
	for i in range(n):
		arr = list(map(int, input().split()))
		x = arr[0]
		y = arr[1:]
		d = cal(x, y)
		ans.append(d)
	mx = max(ans)
	if ans.count(mx) > 1:
		print('tie')
	elif ans.index(mx) == 0:
		print('chef')
	else:
		print(ans.index(mx) + 1)


for __ in range(int(input())):
	n = int(input())
	p = []
	score = []
	for i in range(n):
		p = [int(i) for i in input().split()]
		score_p = p[0]
		p = p[1:]
		while len(set(p)) > 3:
			cookie = set(p)
			if len(cookie) == 4:
				score_p += 1
			elif len(cookie) == 5:
				score_p += 2
			elif len(cookie) == 6:
				score_p += 4
			for x in cookie:
				p.remove(x)
		score.append(score_p)
	maxscore = max(score)
	if score.count(maxscore) > 1:
		print('tie')
	elif score.index(maxscore) == 0:
		print('chef')
	else:
		print(score.index(maxscore) + 1)


t = int(input())
for _ in range(t):
	n = int(input())
	plyr = []
	for _ in range(n):
		k = list(map(int, input().split(' ')))
		val = len(k[1:])
		p = {}
		for i in k[1:]:
			p.setdefault(i, 0)
			x = p[i]
			p[i] = x + 1
		h = set(p.keys())
		while len(h) > 3:
			if len(h) == 4:
				val += 1
			elif len(h) == 5:
				val += 2
			elif len(h) == 6:
				val += 4
			p = {k1: v1 - 1 for (k1, v1) in p.items() if v1 - 1 > 0}
			h = set(p.keys())
		plyr.append(val)
	a = max(plyr)
	if plyr.count(a) > 1:
		print('tie')
	elif plyr.index(a) == 0:
		print('chef')
	else:
		print(plyr.index(a) + 1)


from collections import Counter

def give_point(a):
	nn = len(set(a))
	cur = len(a)
	dic = Counter(a)
	while True:
		val = []
		for i in dic:
			if dic[i] != 0:
				val.append(i)
		if len(val) < 4:
			break
		elif len(val) == 4:
			cur += 1
		elif len(val) == 5:
			cur += 2
		elif len(val) == 6:
			cur += 4
		for i in val:
			dic[i] -= 1
	return cur
t = int(input())
for _ in range(t):
	n = int(input())
	chef = list(map(int, input().split()))
	chef.pop(0)
	val = [0] * n
	val[0] = give_point(chef)
	for i in range(1, n):
		a = list(map(int, input().split()))
		a.pop(0)
		val[i] = give_point(a)
	ele = max(val)
	if val.count(ele) > 1:
		ans = 'tie'
	else:
		pos = val.index(ele)
		if pos == 0:
			ans = 'chef'
		else:
			ans = pos + 1
	print(ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
from random import randint as ri, shuffle
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')

def give_point(a):
	nn = len(set(a))
	cur = len(a)
	dic = Counter(a)
	while True:
		val = []
		for i in dic:
			if dic[i] != 0:
				val.append(i)
		if len(val) < 4:
			break
		elif len(val) == 4:
			cur += 1
		elif len(val) == 5:
			cur += 2
		elif len(val) == 6:
			cur += 4
		for i in val:
			dic[i] -= 1
	return cur
t = int(input())
for _ in range(t):
	n = int(input())
	chef = list(map(int, input().split()))
	chef.pop(0)
	val = [0] * n
	val[0] = give_point(chef)
	for i in range(1, n):
		a = list(map(int, input().split()))
		a.pop(0)
		val[i] = give_point(a)
	ele = max(val)
	if val.count(ele) > 1:
		ans = 'tie'
	else:
		pos = val.index(ele)
		if pos == 0:
			ans = 'chef'
		else:
			ans = pos + 1
	print(ans)


def get_score(arr):
	arr.sort()
	return 3 * arr[0] + 2 * arr[1] + 2 * arr[2] + arr[3] + arr[4] + arr[5]

def count_types(arr):
	out = {x: 0 for x in range(1, 7)}
	for i in range(len(arr)):
		if i and arr[i] in out:
			out[arr[i]] += 1
	return [out[x] for x in range(1, 7)]

def solve(data):
	scores = {}
	for i in range(len(data)):
		if not i:
			chef_score = get_score(count_types(data[i]))
		else:
			score = get_score(count_types(data[i]))
			scores.setdefault(score, []).append(i + 1)
	if scores:
		highest_non_chef = max(scores.keys())
	else:
		highest_non_chef = 0
	if chef_score > highest_non_chef:
		return 'chef'
	scores.setdefault(chef_score, []).append(1)
	if len(scores[highest_non_chef]) > 1:
		return 'tie'
	return str(scores[highest_non_chef][0])
T = int(input().strip())
for tc in range(T):
	N = int(input().strip())
	data = []
	for n in range(N):
		data.append([int(x) for x in input().strip().split(' ')])
	print(solve(data))


from collections import defaultdict
t = int(input())
for i in range(t):
	n = int(input())
	points = [0] * n
	for j in range(n):
		arr = list(map(int, input().split()))
		points[j] += arr[0]
		box = defaultdict(lambda : 0)
		for p in range(arr[0]):
			box[arr[p + 1]] += 1
		while True:
			b_type = 0
			for (k, v) in box.items():
				if v > 0:
					b_type += 1
					box[k] -= 1
			if b_type <= 3:
				break
			else:
				points[j] += 2 ** (b_type - 4)
	c_max = 0
	idx = 0
	for j in range(n):
		if points[j] > c_max:
			c_max = points[j]
			idx = j
	if points.count(c_max) > 1:
		print('tie')
	elif idx == 0:
		print('chef')
	else:
		print(idx + 1)


T = int(input())
for _ in range(T):
	P = []
	N = int(input())
	Score = [0] * N
	for i in range(N):
		a = [int(s) for s in input().split()]
		P.append(a)
	cook = [0] * 6
	for i in range(len(P)):
		for j in range(0, 6):
			cook[j] = P[i][1:].count(j + 1)
		cook.sort()
		Score[i] = P[i][0] + (4 * cook[0] + 2 * (cook[1] - cook[0]) + (cook[2] - cook[1]))
	Win = max(Score)
	if Score.count(Win) > 1:
		print('tie')
	elif Win == Score[0]:
		print('chef')
	else:
		print(Score.index(Win) + 1)


t = int(input())
while t:
	score = []
	n = int(input())
	for i in range(n):
		arr = list(map(int, input().split()))
		s = arr[0]
		type = arr[1:]
		count = s
		types = set(type)
		rest = len(type)
		while len(types) > 3:
			if len(types) == 4 and rest >= 4:
				count += 1
				rest -= 4
			elif len(types) == 5 and rest >= 5:
				count += 2
				rest -= 5
			elif len(types) == 6 and rest >= 6:
				count += 4
				rest -= 6
			for i in types:
				type.remove(i)
			types = set(type)
		score.append(count)
	max = 0
	idx = 0
	flag = 0
	for i in range(len(score)):
		if score[i] > max:
			max = score[i]
			idx = i + 1
	for i in range(len(score)):
		if i != idx - 1:
			if max == score[i]:
				flag = 1
				print('tie')
				break
	if idx == 1 and flag == 0:
		print('chef')
	if idx != 1 and flag == 0:
		print(idx)
	t -= 1


for t in range(int(input())):
	n = int(input())
	scoremax = -1
	scores = []
	pos = -1
	for i in range(n):
		l = list(map(int, input().split()))
		score = l[0]
		l = l[1:]
		while len(set(l)) > 3:
			listset = set(l)
			extra = len(listset)
			if extra == 6:
				score += 4
			elif extra == 5:
				score += 2
			elif extra == 4:
				score += 1
			for val in listset:
				l.remove(val)
		scores.append(score)
	maxscore = max(scores)
	if scores.count(maxscore) > 1:
		print('tie')
	elif scores.index(maxscore) == 0:
		print('chef')
	else:
		print(scores.index(maxscore) + 1)


from collections import Counter
for t in range(int(input())):
	n = int(input())
	c = []
	ct = []
	for i in range(n):
		temp = list(map(int, input().split()))
		c.append(temp[0])
		inp = temp[1:temp[0] + 1]
		ct.append(inp)
	scores = []
	for i in range(n):
		score = c[i]
		length = len(Counter(ct[i]).keys())
		if length == 4:
			score += 1
		elif length == 5:
			score += 2
		elif length == 6:
			score += 4
		ct1 = list(Counter(ct[i]).keys())
		for z in ct1:
			ct[i].remove(z)
		while ct[i] != []:
			length = len(Counter(ct[i]).keys())
			if length == 4:
				score += 1
			elif length == 5:
				score += 2
			elif length == 6:
				score += 4
			ct1 = list(Counter(ct[i]).keys())
			for z in ct1:
				ct[i].remove(z)
		scores.append(score)
	top = max(scores)
	count = 0
	for i in range(n):
		if scores[i] == top:
			ind = i
			count += 1
	if count > 1:
		print('tie')
	elif ind == 0:
		print('chef')
	else:
		print(ind + 1)


for z in range(int(input())):
	players = int(input())
	scores = [0] * players
	for i in range(players):
		cookie = list(map(int, input().split()))
		cookie.pop(0)
		scores[i] = len(cookie)
		num_cook = [0] * 6
		for j in range(0, 6):
			num_cook[j] = cookie.count(j + 1)
		num_cook.sort()
		scores[i] += 4 * num_cook[0] + 2 * (num_cook[1] - num_cook[0]) + (num_cook[2] - num_cook[1])
	maxScore = max(scores)
	if scores.count(maxScore) > 1:
		print('tie')
	elif maxScore == scores[0]:
		print('chef')
	else:
		print(scores.index(maxScore) + 1)


for z in range(int(input())):
	players = int(input())
	Score = [0] * players
	for i in range(players):
		a = list(map(int, input().split()))
		cook = [0] * 6
		for j in range(0, 6):
			cook[j] = a[1:].count(j + 1)
		cook.sort()
		Score[i] = a[0] + (4 * cook[0] + 2 * (cook[1] - cook[0]) + (cook[2] - cook[1]))
	Win = max(Score)
	if Score.count(Win) > 1:
		print('tie')
	elif Win == Score[0]:
		print('chef')
	else:
		print(Score.index(Win) + 1)


for k in range(int(input())):
	c = []
	for i in range(int(input())):
		c.append(list(map(int, input().split())))
	m = []

	def newset(c):
		for i in set(c[1:]):
			c.remove(i)
		return c

	def check(c):
		s = len(set(c[1:]))
		if s < len(c[1:]):
			check(newset(c))
		if s == 4:
			c[0] += 1
		elif s == 5:
			c[0] += 2
		elif s == 6:
			c[0] += 4
		return c[0]
	for i in c:
		m.append(check(i))
	if m.count(max(m)) > 1:
		print('tie')
	elif max(m) == m[0]:
		print('chef')
	else:
		print(m.index(max(m)) + 1)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	scores = []
	for i in range(n):
		types = list(map(int, input().split()))
		c = types[0]
		types = types[1:]
		bags = []
		for x in types:
			new_bag = True
			for bag in bags:
				if x not in bag:
					new_bag = False
					pot_bag = bag
					break
			if new_bag:
				bags.append({x})
			else:
				pot_bag.add(x)
		score = 0
		for bag in bags:
			if len(bag) == 4:
				score += 1
			if len(bag) == 5:
				score += 2
			if len(bag) == 6:
				score += 4
		scores.append(c + score)
	max_score = max(scores)
	if scores.count(max_score) > 1:
		print('tie')
	else:
		index = scores.index(max_score)
		if index == 0:
			print('chef')
		else:
			print(index + 1)


import array
import heapq
for i in range(int(input())):
	num_max = list()
	n = int(input())
	for j in range(n):
		num_array = [int(x) for x in input().split()]
		if n == 1:
			print('chef')
			break
		c = len(num_array) - 1
		num_freq = list()
		for l in range(6):
			num_freq.append(num_array[1:].count(l + 1))
		num_freq.sort(reverse=True)
		for m in range(int(3)):
			if num_freq[-m - 1] > 0:
				if 6 - m == 6:
					c += 4 * num_freq[5]
					y = 0
					y = num_freq[5]
					num_freq[:] = [x - y for x in num_freq]
				elif 6 - m == 5:
					c += 2 * num_freq[4]
					y = 0
					y = num_freq[4]
					num_freq[:] = [x - y for x in num_freq]
				elif 6 - m == 4:
					c += 1 * num_freq[3]
					y = 0
					y = num_freq[3]
					num_freq[:] = [x - y for x in num_freq]
		num_max.append(c)
	sor = sorted(num_max)
	if n > 1:
		second_largest = sor[-2]
		first_largest = sor[-1]
		if first_largest == second_largest:
			print('tie')
		elif first_largest > second_largest:
			indx = num_max.index(first_largest)
			if indx == 0:
				print('chef')
			else:
				print(indx + 1)


t = input()
for i in range(int(t)):
	n = input()
	winner = list()
	for j in range(int(n)):
		li = [int(x) for x in input().split()]
		score = 0
		ty = [0] * 7
		for k in li[1:]:
			ty[k] += 1
		score = len(li) - 1
		c = ty.count(0)
		while c < 4:
			score += 7 - c - 3
			if c == 1:
				score += 1
			for l in range(len(ty)):
				if ty[l] != 0:
					ty[l] -= 1
			c = ty.count(0)
		winner.append(score)
	m = max(winner)
	if winner.count(m) > 1:
		print('tie')
	elif winner.index(m) == 0:
		print('chef')
	else:
		print(winner.index(m) + 1)


n = int(input())
while n:
	result = []
	x = int(input())
	list1 = [[] for i in range(x)]
	k = 0
	w = 0
	for i in range(x):
		list2 = input()
		list2 = list(map(int, list2.split(' ')))
		list1[i].extend(list2)
	for i in range(len(list1)):
		del list1[i][0]
	for i in range(x):
		y = len(list1[i])
		while list1[i]:
			z = set(list1[i])
			if len(z) == 6:
				y = y + 4
			if len(z) == 5:
				y = y + 2
			if len(z) == 4:
				y = y + 1
			if len(z) > 3:
				for j in z:
					list1[i].remove(j)
			else:
				break
		result.append(y)
		rep = result
	max_value = max(result)
	max_index = result.index(max_value)
	ww = max(rep)
	rep.remove(ww)
	if rep:
		kk = max(rep)
		if ww == kk:
			print('tie')
			w = 1
	if w == 0:
		if max_index == 0:
			print('chef')
		else:
			print(max_index + 1)
	n = n - 1


t = int(input())
for i in range(t):
	n = int(input())
	score = []
	for i in range(n):
		s = input()
		a = [int(x) for x in s.split()]
		b = [0 for i in range(6)]
		for i in range(1, len(a)):
			b[a[i] - 1] = b[a[i] - 1] + 1
		b.sort()
		score.append(a[0] + b[0] * 4 + (b[1] - b[0]) * 2 + (b[2] - b[1]) * 1)
	m = max(score)
	if score.count(m) > 1:
		print('tie')
	elif score.index(m) == 0:
		print('chef')
	else:
		print(score.index(m) + 1)


t = int(input())
for zxc in range(t):
	noP = int(input())
	soP = list()
	for qwe in range(noP):
		inp = str(input())
		inp = inp.split()
		noC = int(inp[0])
		playerScore = noC
		array = [0 for i in range(6 + 1)]
		i = 1
		while i < len(inp):
			type = int(inp[i])
			array[type] += 1
			i += 1
		distinct = 0
		for type in range(6 + 1):
			if array[type] > 0:
				distinct += 1
		array = sorted(array)
		if distinct >= 4:
			i = 0
			type = 1
			flag = False
			while i <= distinct - 4:
				if array[type] > 0 or flag:
					flag = True
					i += 1
					j = type
					min = array[type]
					while j <= 6:
						array[j] -= min
						j += 1
					playerScore += pow(2, 3 - type) * min
				type += 1
		soP.append(playerScore)
	s = ''
	max = 0
	i = 0
	index = -1
	while i < len(soP):
		if soP[i] > max:
			max = soP[i]
			index = i
		i += 1
	cnt = 0
	for i in soP:
		if i == max:
			cnt += 1
	if cnt > 1:
		print('tie')
	elif index == 0:
		print('chef')
	else:
		print(str(index + 1))


t = int(input())
for t0 in range(t):
	n = int(input())
	mx = 0
	flg = 0
	for n0 in range(n):
		ctr = [0 for i in range(6)]
		s = [int(i) for i in input().strip().split()]
		m = s[0]
		sc = m
		del s[0]
		for j in range(6):
			ctr[j] = s.count(j + 1)
		while True:
			mn = m
			tmp = 0
			for j in range(6):
				if ctr[j] == 0:
					continue
				else:
					mn = min(mn, ctr[j])
			for j in range(6):
				if ctr[j] == 0:
					continue
				else:
					ctr[j] -= mn
					tmp += 1
			tmp -= 4
			if tmp < 0:
				break
			sc += 2 ** tmp * mn
		if sc > mx:
			flg = 0
			mx = sc
			pos = n0
		elif sc == mx:
			flg = 1
	if flg == 0:
		if pos == 0:
			print('chef')
		else:
			print(pos + 1)
	else:
		print('tie')


import sys
T = int(input().strip())
for tt in range(0, T):
	N = int(input().strip())
	maxs = -1
	maxi = -1
	for p in range(1, N + 1):
		cook = [0, 0, 0, 0, 0, 0]
		arr = [int(i) for i in input().split()]
		score = arr[0]
		for c in arr[1:]:
			cook[c - 1] += 1
		while True:
			count = 0
			for ci in range(0, len(cook)):
				if cook[ci] != 0:
					count += 1
					cook[ci] -= 1
			if count < 4:
				if score > maxs:
					maxs = score
					maxi = p
				elif score == maxs:
					maxs = score
					maxi = 1001
				break
			elif count == 4:
				score += 1
			elif count == 5:
				score += 2
			elif count == 6:
				score += 4
	if maxi == 1:
		print('chef')
	elif maxi == 1001:
		print('tie')
	elif maxs == 0:
		print('chef')
	else:
		print(maxi)


t = int(input())
for i in range(t):
	n = int(input())
	output = []
	for j in range(n):
		c = list(map(int, input().split()))
		total = c[0]
		counter = []
		for p in range(1, 7):
			counter.append(c[1:].count(p))
		while True:
			nonzeros = len(counter) - counter.count(0)
			if nonzeros < 4:
				break
			elif nonzeros == 4:
				total += 1
			elif nonzeros == 5:
				total += 2
			else:
				total += 4
			while 0 in counter:
				counter.remove(0)
			counter = [x - 1 for x in counter]
		output.append(total)
	if output.count(max(output)) != 1:
		print('tie')
	else:
		index = output.index(max(output))
		if index == 0:
			print('chef')
		else:
			print(index + 1)


import heapq
t = int(input())
for _ in range(t):
	n = int(input())
	score = []
	for _ in range(n):
		dist_type = []
		l = input()
		l = list(map(int, l.split()))
		f = l.pop(0)
		c1 = l.count(1)
		dist_type.append(c1)
		c2 = l.count(2)
		dist_type.append(c2)
		c3 = l.count(3)
		dist_type.append(c3)
		c4 = l.count(4)
		dist_type.append(c4)
		c5 = l.count(5)
		dist_type.append(c5)
		c6 = l.count(6)
		dist_type.append(c6)
		max_types = len([x for x in dist_type if x > 0])
		while max_types > 3:
			zero_count = dist_type.count(0)
			if zero_count == 0:
				min_bags_having_all_type = min(dist_type)
				f += min_bags_having_all_type * 4
				dist_type = [x - min_bags_having_all_type for x in dist_type]
				max_types = len([x for x in dist_type if x > 0])
				continue
			elif zero_count == 1:
				min_bags_having_all_type = heapq.nsmallest(2, dist_type)[-1]
				f += min_bags_having_all_type * 2
			elif zero_count == 2:
				min_bags_having_all_type = heapq.nsmallest(3, dist_type)[-1]
				f += min_bags_having_all_type * 1
			for j in range(len(dist_type)):
				if dist_type[j] > 0:
					dist_type[j] = dist_type[j] - min_bags_having_all_type
			max_types = len([x for x in dist_type if x > 0])
		score.append(f)
	m = max(score)
	c = score.count(m)
	if c >= 2:
		print('tie')
	else:
		pos = score.index(m)
		if pos == 0:
			print('chef')
		else:
			print(pos + 1)


T = int(input())
while T > 0:
	N = int(input())
	points = []
	while N > 0:
		temp = input()
		p1 = temp.split()
		x = int(p1[0])
		p1.remove(p1[0])
		c1 = [p1.count('1'), p1.count('2'), p1.count('3'), p1.count('4'), p1.count('5'), p1.count('6')]
		c2 = [x for x in c1 if x > 0]
		l = len(c2)
		while l > 3:
			m = min(c2)
			if l == 6:
				x += m * 4
			elif l == 5:
				x += m * 2
			elif l == 4:
				x += m
			c2 = [x - m for x in c2 if x - m > 0]
			l = len(c2)
		points.append(x)
		N -= 1
	win_points = max(points)
	if points.count(win_points) > 1:
		print('tie')
	elif points[0] == win_points:
		print('chef')
	else:
		print(points.index(win_points) + 1)
	T -= 1


def method():
	t = int(input())
	k = 0
	while k < t:
		p = int(input())
		li = []
		n_l = []
		l = 0
		pnt = []
		while l < p:
			li1 = [int(x) for x in input().strip().split(' ')]
			n_l.append(li1[0])
			li1.remove(li1[0])
			li.append(li1)
			li2 = []
			li2 = list(set(li1))
			max_count = 0
			for i in range(len(li2)):
				cnt = li1.count(li2[i])
				if cnt > max_count:
					max_count = cnt
			li3 = []
			for i in range(max_count):
				li3.append([])
			for i in range(len(li2)):
				cnt = li1.count(li2[i])
				for j in range(cnt):
					li3[j].append(li2[i])
			pt = len(li1)
			for i in range(len(li3)):
				if len(li3[i]) == 4:
					pt += 1
				elif len(li3[i]) == 5:
					pt += 2
				elif len(li3[i]) == 6:
					pt += 4
			pnt.append(pt)
			l += 1
		Max = max(pnt)
		if pnt.count(Max) == 1:
			index = pnt.index(Max)
			if index == 0:
				print('chef')
			else:
				print(str(index + 1))
		else:
			print('tie')
		k += 1
method()


t = int(input())
for i in range(t):
	n = int(input())
	score = []
	for j in range(n):
		li = [int(x) for x in input().strip().split(' ')]
		st = li[1:len(li)]
		coc = []
		temp = li[0]
		coc.append(st.count(1))
		coc.append(st.count(2))
		coc.append(st.count(3))
		coc.append(st.count(4))
		coc.append(st.count(5))
		coc.append(st.count(6))
		maxcount = max(coc)
		bag = [0] * maxcount
		for k in range(6):
			for m in range(coc[k]):
				bag[m] += 1
		for k in range(maxcount):
			if bag[k] == 4:
				temp += 1
			if bag[k] == 5:
				temp += 2
			if bag[k] == 6:
				temp += 4
		score.append(temp)
	m = max(score)
	if score.count(m) == 1:
		if m == score[0]:
			print('chef')
		else:
			print(score.index(m) + 1)
	else:
		print('tie')


import collections
from collections import Counter
k = int(input())
for i in range(k):
	n = int(input())
	q = []
	for j in range(n):
		count1 = 0
		l = []
		l1 = []
		nums = input().split()
		for w in nums:
			l.append(int(w))
		n1 = l[0]
		l = sorted(l[1:])
		c = Counter(l)
		od = collections.OrderedDict(sorted(c.items()))
		l1 = c.values()
		l1 = list(l1)
		x = 1
		while x:
			r = 0
			count = 0
			i1 = 0
			j1 = 0
			for i1 in range(len(l1)):
				if l1[i1] is not 0:
					l1[i1] = l1[i1] - 1
					count = count + 1
			if count is 4:
				count1 = count1 + 1
				count = 0
			elif count is 5:
				count1 = count1 + 2
				count = 0
			elif count is 6:
				count1 = count1 + 4
				count = 0
			for j1 in range(len(l1)):
				if l1[j1] > 0:
					r = r + 1
			if r < 4:
				x = 0
		count1 = count1 + n1
		q.append(count1)
	count3 = 0
	m = max(q)
	for i in range(len(q)):
		if q[i] is m:
			count3 = count3 + 1
			x = i
	if count3 > 1:
		print('tie')
	elif q[0] is m:
		print('chef')
	else:
		print(x + 1)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	max = -1
	winner_index = 0
	tie_flag = 0
	for j in range(n):
		ip = list(map(int, input().split(' ')))
		no_of_cookies = ip[0]
		cookie_type = ip[1:]
		points = no_of_cookies
		hit = [0 for k in range(6)]
		for x in cookie_type:
			hit[x - 1] += 1
		flag = 0
		while True:
			zero_flag = 0
			count = 0
			for k in range(6):
				if hit[k] > 0:
					hit[k] -= 1
					count += 1
				else:
					zero_flag += 1
			if zero_flag == 6:
				break
			if count == 4:
				points += 1
			elif count == 5:
				points += 2
			elif count == 6:
				points += 4
		if points == max:
			tie_flag = 1
		elif points > max:
			max = points
			tie_flag = 0
			winner_index = j + 1
	if tie_flag == 1:
		ans.append('tie')
	elif winner_index == 1:
		ans.append('chef')
	else:
		ans.append(winner_index)
for x in ans:
	print(x)


__author__ = 'Nikhil Erkimutt'
t = int(input())
while t:
	t -= 1
	n = int(input())
	max_score = 0
	winner = ''
	for i in range(n):
		l = list(map(int, input().split()))
		score = l[0]
		l = l[1:]
		s = len(set(l))
		cc = [0, 0, 0, 0, 0, 0]
		for j in l:
			cc[j - 1] += 1
		while s > 3:
			m = min((x for x in cc if x != 0))
			if s == 6:
				score += m * 4
			elif s == 5:
				score += m * 2
			else:
				score += m
			for j in range(6):
				if cc[j] != 0:
					cc[j] -= m
					if cc[j] == 0:
						s -= 1
		if score == max_score:
			winner = 'tie'
		elif score > max_score:
			winner = i + 1
			max_score = score
	if winner == 1:
		print('chef')
	else:
		print(winner)


t = int(input().strip())
for z in range(0, t):
	N = int(input().strip())
	gc = 0
	tc = 0
	ca = []
	for xy in range(0, N):
		c = [int(i) for i in input().strip().split(' ')]
		n = c[0]
		del c[0]
		freq = [0] * 7
		for i in c:
			freq[i] += 1
		freq = [i for i in freq if i > 0]
		x = len(freq)
		count = n
		while x > 3:
			if x == 4:
				count += min(freq)
				mini = min(freq)
				for i in range(0, len(freq)):
					freq[i] -= mini
				freq = [i for i in freq if i > 0]
				x = len(freq)
			if x == 5:
				count += min(freq) * 2
				mini = min(freq)
				for i in range(0, len(freq)):
					freq[i] -= mini
				freq = [i for i in freq if i > 0]
				x = len(freq)
			if x == 6:
				count += min(freq) * 4
				mini = min(freq)
				for i in range(0, len(freq)):
					freq[i] -= mini
				freq = [i for i in freq if i > 0]
				x = len(freq)
		ca.append(count)
		if gc < count:
			gc = count
			ind = xy + 1
	v = [i for i in ca if i == gc]
	if len(v) > 1:
		print('tie')
	elif ind == 1:
		print('chef')
	else:
		print(ind)


t = input()
t = int(t)
ans = []
for i in range(0, t):
	n = input()
	n = int(n)
	comp = []
	cal = []
	for k in range(0, 6):
		cal.append(0)
	for j in range(0, n):
		c = input()
		c = c.split(' ')
		for k in range(0, 6):
			cal[k] = 0
		for k in range(0, int(c[0])):
			g = int(c[k + 1])
			cal[g - 1] = cal[g - 1] + 1
		cal.sort()
		r = int(c[0]) + cal[0] * 4 + (cal[1] - cal[0]) * 2 + (cal[2] - cal[1])
		comp.append(r)
	m = max(comp)
	count = 0
	for j in range(0, n):
		if m == comp[j]:
			count = count + 1
			an = j
		if count == 2:
			an = -1
			break
	ans.append(an)
for i in range(0, t):
	if ans[i] == -1:
		print('tie')
	elif ans[i] == 0:
		print('chef')
	else:
		print(ans[i] + 1)


t = int(input())
for i in range(t):
	n = int(input())
	point = []
	(tie, maximum, winner) = (1, 0, 0)
	if n == 1:
		y = input()
		tie = 0
	else:
		for j in range(n):
			y = input()
			y = y.split(' ')
			point.append(int(y[0]))
			z = 6 * [0]
			count = 0
			for k in range(1, len(y)):
				z[int(y[k]) - 1] += 1
			for l in range(6):
				if z[l] > 0:
					count += 1
			while count > 3:
				if count == 6:
					point[j] += 4
					for m in range(len(z)):
						z[m] -= 1
					count = 0
					for l in range(6):
						if z[l] > 0:
							count += 1
				elif count == 5:
					point[j] += 2
					for m in range(len(z)):
						z[m] -= 1
					count = 0
					for l in range(6):
						if z[l] > 0:
							count += 1
				elif count == 4:
					point[j] += 1
					for m in range(len(z)):
						z[m] -= 1
					count = 0
					for l in range(6):
						if z[l] > 0:
							count += 1
				else:
					point[j] += 0
			if point[j] != maximum:
				if point[j] > maximum:
					tie = 0
					maximum = point[j]
					winner = j
			else:
				tie = 1
	if tie:
		print('tie')
	elif winner == 0:
		print('chef')
	else:
		print(str(winner + 1))


import sys
t = int(input())
for x in range(t):
	n = int(input())
	(total, c, comb) = ([], [], [])
	for i in range(n):
		inp = input().split()
		c.append(int(inp[0]))
		comb.append({})
		for j in range(1, c[i] + 1):
			comb[i][int(inp[j])] = comb[i].get(int(inp[j]), 0) + 1
	total = c[:]
	for i in range(n):
		while len(comb[i]) > 3:
			minimum = min(comb[i].values())
			if len(comb[i]) == 6:
				total[i] += minimum * 4
			elif len(comb[i]) == 5:
				total[i] += minimum * 2
			elif len(comb[i]) == 4:
				total[i] += minimum
			keys = list(comb[i].keys())
			for key in keys:
				if comb[i][key] == minimum:
					del comb[i][key]
				else:
					comb[i][key] -= minimum
	m = max(total)
	if total.count(m) > 1:
		print('tie')
	elif total.index(m) == 0:
		print('chef')
	else:
		print(total.index(m) + 1)


import collections
t = int(input())
s = []
cook = [1, 3]
count = 0
s1 = []

def remove_min(l, m):
	for j in range(0, len(l)):
		l[j] = l[j] - m
	for i in l:
		if i == 0:
			l.remove(0)
for i in range(t):
	n = int(input())
	del cook[:]
	cook = []
	for j in range(0, n):
		s = list(map(int, input().strip().split()))
		freq = collections.Counter(s[1:])
		for value in freq.values():
			s1.append(value)
		while len(s1) >= 4:
			mi = min(s1)
			if len(s1) == 4:
				s[0] = s[0] + mi * 1
				remove_min(s1, mi)
			elif len(s1) == 5:
				s[0] = s[0] + mi * 2
				remove_min(s1, mi)
			else:
				s[0] = s[0] + mi * 4
				remove_min(s1, mi)
		cook.append(s[0])
		del s1[:]
	m = max(cook)
	index = cook.index(max(cook))
	count = cook.count(m)
	if index == 0 and count == 1:
		print('chef')
	elif count == 1:
		print(index + 1)
	else:
		print('tie')


def func(hash):
	if not isinstance(hash, dict):
		return 0
	else:
		tmp = list(hash.keys())
		for i in tmp:
			if hash[i] < 1:
				del hash[i]
		return len(hash)
t = int(input())
while t:
	n = int(input())
	friends = []
	score = []
	for _ in range(n):
		(c, *b) = map(int, input().split())
		friends.append([b, {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}, c])
		score.append(c)
	for i in range(n):
		d = friends[i][1]
		for j in friends[i][0]:
			d[j] += 1
		le = func(d)
		while le > 3:
			m = min(d.values())
			if le == 6:
				score[i] += m * 4
			elif le == 5:
				score[i] += m * 2
			else:
				score[i] += m
			for k in d.keys():
				d[k] -= m
			le = func(d)
	tmp = max(score)
	if score.count(tmp) > 1:
		print('tie')
	elif score.index(tmp) == 0:
		print('chef')
	else:
		print(score.index(tmp) + 1)
	t -= 1


import sys
t = int(input())
for i in range(t):
	n = int(input())
	max = 0
	for j in range(n):
		a = [int(l) for l in input().split(' ')]
		num = a[0]
		a.remove(a[0])
		temp = 0
		b = [0, 0, 0, 0, 0, 0]
		for k in range(len(b)):
			b[k] = a.count(k + 1)
		while b != [0, 0, 0, 0, 0, 0]:
			inx = 0
			for k in range(len(b)):
				if b[k] > 0:
					inx += 1
					b[k] -= 1
			if inx >= 6:
				temp += 4
			elif inx >= 5:
				temp += 2
			elif inx >= 4:
				temp += 1
		num = len(a) + temp
		if max < num:
			max = num
			if j == 0:
				ans = 'chef'
			else:
				ans = j + 1
		elif max == num:
			ans = 'tie'
	print(ans)


def mapping(a):
	if a < 4:
		return 0
	if a == 4:
		return 1
	if a == 5:
		return 2
	if a == 6:
		return 4

def get_score(a):
	from collections import defaultdict
	score = int(a[0])
	b = [int(i) for i in a[1:]]
	count = [0] * 6
	for each in b:
		count[each - 1] += 1
	while len(count) > 3:
		if min(count) == 0:
			count.remove(0)
		else:
			score += min(count) * mapping(len(count))
			minn = min(count)
			for i in range(len(count)):
				count[i] -= minn
	return score
t = int(input())
while t > 0:
	n = int(input())
	count = []
	for i in range(n):
		a = input().split()
		count.append(get_score(a))
	indices = [i for (i, x) in enumerate(count) if x == max(count)]
	if len(indices) > 1:
		print('tie')
	elif len(indices) == 1:
		if indices[0] == 0:
			print('chef')
		else:
			print(indices[0] + 1)
	t -= 1


t = int(input())
while t:
	s = []
	t -= 1
	n = int(input())
	for i in range(n):
		x = list(map(int, input().split()))
		x.pop(0)
		f = [0] * 6
		for j in range(len(x)):
			f[x[j] - 1] += 1
		temp = []
		p = sum(f)
		for j in range(6):
			if f[j] != 0:
				temp.append(f[j])
		if len(temp) == 6:
			temp = sorted(temp)
			b = temp[0]
			for j in range(6):
				temp[j] -= b
			p += 4 * b
		temp2 = []
		for j in range(len(temp)):
			if temp[j] != 0:
				temp2.append(temp[j])
		if len(temp2) == 5:
			temp2 = sorted(temp2)
			b = temp2[0]
			for j in range(5):
				temp2[j] -= b
			p += 2 * b
		temp = []
		for j in range(len(temp2)):
			if temp2[j] != 0:
				temp.append(temp2[j])
		if len(temp) == 4:
			temp = sorted(temp)
			b = temp[0]
			for j in range(4):
				temp[j] -= b
			p += b
		s.append(p)
	mx = max(s)
	count = 0
	for i in range(len(s)):
		if s[i] == mx:
			count += 1
	if count > 1:
		print('tie')
	elif mx == s[0]:
		print('chef')
	else:
		for i in range(1, len(s)):
			if mx == s[i]:
				print(i + 1)
				break


import operator

def find(a):
	f = [0] * 6
	ans = 0
	for i in a:
		f[i - 1] += 1
	while True:
		cnt = 0
		for j in range(0, len(f)):
			if f[j] > 0:
				cnt += 1
				f[j] -= 1
		if cnt == 4:
			ans += 1
		elif cnt == 5:
			ans += 2
		elif cnt == 6:
			ans += 4
		else:
			break
	return ans
t = int(input())
for i in range(t):
	player = int(input())
	d = [0] * player
	for j in range(0, player):
		cookie = list(map(int, input().split()))
		total = cookie[0]
		cookie.remove(cookie[0])
		point = total
		d[j] = point + find(cookie)
	sec = -1
	cur = -1
	index = 0
	for k in range(0, player):
		if d[k] > cur:
			cur = d[k]
			index = k
		elif d[k] == cur:
			sec = d[k]
	if sec == cur:
		print('tie')
	elif index == 0:
		print('chef')
	else:
		print(str(index + 1))


t = int(input())
for i in range(t):
	n = int(input())
	flag = 0
	for j in range(n):
		temp = [0, 0, 0, 0, 0, 0]
		ls = list(map(int, input().split()))
		s = ls[0]
		for k in range(1, ls[0] + 1):
			y = ls[k]
			temp[y - 1] = temp[y - 1] + 1
		temp.sort()
		s = s + 2 * temp[0] + temp[1] + temp[2]
		if flag == 0:
			max = s
			index = j
			tie = -1
			flag = 1
		if s == max:
			tie = tie + 1
		elif s > max:
			max = s
			index = j
			tie = 0
	if tie > 0:
		print('tie')
	elif index == 0:
		print('chef')
	else:
		print(index + 1)


t = int(input())
while t > 0:
	n = int(input())
	m = []
	while n > 0:
		sum = 0
		q = []
		l = [int(x) for x in input().split()]
		sum = l[0]
		p = []
		s = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
		for i in range(1, len(l)):
			s[l[i]] += 1
		for i in s:
			p.append(s[i])
		p.sort()
		sum = sum + p[0] * 4 + (p[1] - p[0]) * 2 + (p[2] - p[0] - (p[1] - p[0])) * 1
		m.append(sum)
		n -= 1
	d = m.index(max(m))
	c = 0
	k = max(m)
	for i in range(len(m)):
		if m[i] == k:
			c += 1
	if c >= 2:
		print('tie')
	elif d == 0 or len(m) == 1:
		print('chef')
	else:
		print(d + 1)
	t -= 1


from collections import OrderedDict
from operator import itemgetter
for _ in range(int(input())):
	n = int(input())
	res = {}
	for i in range(n):
		l = [int(a) for a in input().split()]
		temp = l[0]
		t = []
		for j in range(6):
			c = l.count(j + 1)
			if j + 1 == temp:
				c -= 1
			t.append(c)
		t.sort()
		temp = temp + 4 * t[0] + 2 * (t[1] - t[0]) + t[2] - t[0] - (t[1] - t[0])
		res[i] = temp
	res = OrderedDict(sorted(res.items(), key=itemgetter(1)))
	val_l = list(res.values())
	key_l = list(res.keys())
	if len(val_l) == 1:
		print('chef')
	elif val_l[n - 1] == val_l[n - 2]:
		print('tie')
	elif key_l[n - 1] == 0:
		print('chef')
	else:
		print(key_l[n - 1] + 1)


def getMin(a, n):
	if len(a) < n:
		return 0
	ans = a[0]
	for i in range(n):
		ans = min(ans, a[i])
	return ans

def calc(a):
	ans = 0
	while getMin(a, 6) > 0:
		ans += 10
		for i in range(6):
			a[i] -= 1
	a.sort(reverse=True)
	while getMin(a, 5) > 0:
		ans += 7
		for i in range(5):
			a[i] -= 1
	a.sort(reverse=True)
	while getMin(a, 4) > 0:
		ans += 5
		for i in range(4):
			a[i] -= 1
	ans += sum(a)
	return ans
T = int(input())
while T > 0:
	T -= 1
	n = int(input())
	bestScore = 0
	bestCount = 0
	answer = 0
	for i in range(n):
		a = list(map(int, input().split()))
		c = []
		for j in range(1, len(a)):
			while len(c) < a[j]:
				c.append(0)
			c[a[j] - 1] += 1
		cur = calc(c)
		if bestScore < cur:
			bestScore = cur
			bestCount = 1
			answer = i + 1
		elif bestScore == cur:
			bestCount += 1
	if bestCount > 1:
		print('tie')
	elif answer == 1:
		print('chef')
	else:
		print(answer)


T = int(input())
for _ in range(T):
	n = int(input())
	score = []
	for i in range(n):
		t = list(map(int, input().split()))
		c = t.pop(0)
		num = [0] * 6
		for v in t:
			num[v - 1] += 1
		num.sort()
		score.append((num[0] * 4 + (num[1] - num[0]) * 2 + (num[2] - num[1]) + c, i))
	score.append((-1, -1))
	score.sort()
	score.reverse()
	if score[0][0] == score[1][0]:
		print('tie')
	elif score[0][1] == 0:
		print('chef')
	else:
		print(score[0][1] + 1)


lookupformultilier = [0, 0, 0, 0, 1, 2, 4]

def calc_score(s):
	a = list(map(int, s.split()))
	(n, cookietypes) = (a[0], a[1:])
	score = n
	cookiehash = [0, 0, 0, 0, 0, 0, 0]
	for i in cookietypes:
		cookiehash[i] += 1
	l = len([i for i in cookiehash if i > 0])
	mintype = min([i for i in cookiehash if i > 0])
	while l > 0:
		mintype = min([i for i in cookiehash if i > 0])
		noofcookies = len([i for i in cookiehash if i > 0])
		multiplier = lookupformultilier[noofcookies]
		score += mintype * multiplier
		for i in range(7):
			if cookiehash[i] is not 0:
				cookiehash[i] -= mintype
		l = len([i for i in cookiehash if i > 0])
	return score
t = int(input())
for i in range(t):
	n = int(input())
	scores = [0]
	for j in range(n):
		scores.append(calc_score(input()))
	max1 = max(scores)
	index = scores.index(max1)
	scores.remove(max1)
	max2 = max(scores)
	if max1 == max2:
		print('tie')
	elif index is 1:
		print('chef')
	else:
		print(index)


t = int(input())
b = '123456'
while t > 0:
	n = int(input())
	flag = 0
	count1 = 0
	index = 1
	sum = 0
	for i in range(1, n + 1):
		a = []
		a = input().split()
		c = []
		for k in b:
			count = 0
			for j in a[1:]:
				if k == j:
					count += 1
			if count > 0:
				c.append(count)
		if len(c) < 4:
			sum = int(a[0])
		else:
			bonus = 0
			c = sorted(c)
			d = len(c)
			if d == 4:
				bonus += c[0]
			elif d == 5:
				bonus += 2 * c[0]
				c[1] = c[1] - c[0]
				if c[1] > 0:
					bonus += c[1]
			else:
				bonus += 4 * c[0]
				c[1] = c[1] - c[0]
				c[2] = c[2] - c[0]
				if c[1] > 0:
					bonus += 2 * c[1]
					c[2] = c[2] - c[1]
				if c[2] > 0:
					bonus += c[2]
			sum = int(a[0]) + bonus
		if sum > count1:
			index = i
			count1 = sum
			flag = 0
		elif sum == count1:
			index = i
			flag = 1
	if index == 1 and flag != 1:
		print('chef')
	elif flag == 1:
		print('tie')
	else:
		print(index)
	t -= 1


from collections import Counter
bonus = {6: 4, 5: 2, 4: 1, 3: 0, 2: 0, 1: 0}

def reduceDict(dictionary):
	totalBonus = 0
	if bool(dictionary):
		minimum = min(dictionary.values())
		if minimum != 0:
			for i in dictionary.keys():
				dictionary[i] = dictionary[i] - minimum
			totalBonus = totalBonus + bonus[len(dictionary)] * minimum
			for i in list(dictionary):
				if dictionary[i] == 0:
					dictionary.pop(i, 0)
			if bool(dictionary):
				totalBonus = totalBonus + reduceDict(dictionary)
				return totalBonus
			else:
				return totalBonus
	else:
		return totalBonus
t = int(input())
while t:
	players = int(input())
	player = []
	for i in range(0, players):
		cookies = list(map(int, input().split(' ')))
		player.append(0)
		player[i] = player[i] + cookies.pop(0)
		initial = player[i]
		cookies = Counter(cookies)
		bonusPoints = reduceDict(cookies)
		player[i] = player[i] + bonusPoints
		playerNo = player.index(max(player))
		rankClash = player.count(max(player))
	if playerNo == 0 and rankClash == 1:
		print('chef')
	elif playerNo != 0 and rankClash == 1:
		print(playerNo + 1)
	elif rankClash > 1:
		print('tie')
	t = t - 1


t = int(input())
j = 1
while j <= t:
	maxx = 0
	n = int(input())
	ans = [0] * n
	for i in range(0, n):
		c = [int(z) for z in input().split()]
		arr = [0] * 6
		count = 0
		for m in range(1, len(c)):
			r = c[m] - 1
			if arr[r] == 0:
				count += 1
			arr[r] += 1
		arr.sort()
		if count == 4:
			ans[i] = c[0] + arr[2]
		elif count == 5:
			ans[i] = c[0] + arr[1] + arr[2]
		elif count == 6:
			ans[i] = c[0] + 2 * arr[0] + arr[1] + arr[2]
		else:
			ans[i] = c[0]
		if ans[i] > maxx:
			maxx = ans[i]
	count = 0
	for i in range(0, n):
		if ans[i] == maxx:
			count += 1
			k = i
	if count > 1:
		print('tie')
	elif k == 0:
		print('chef')
	else:
		print(k + 1)
	j += 1


a = int(input())
for b in range(0, a):
	c = int(input())
	lis = []
	points = 0
	for d in range(0, c):
		e = input().split()
		no = int(e[0])
		e = e[1:]
		points = points + no
		while len(set(e)) >= 4:
			if len(set(e)) == 4:
				points = points + 1
			elif len(set(e)) == 5:
				points = points + 2
			elif len(set(e)) == 6:
				points = points + 4
			for i in set(e):
				e.remove(i)
		lis.append(points)
		points = 0
	maxval = max(lis)
	winner = lis.index(max(lis)) + 1
	if maxval not in lis[winner:]:
		if winner == 1:
			print('chef')
		else:
			print(winner)
	elif maxval in lis[winner:]:
		print('tie')


result = []
for test_cases in range(int(input())):
	win = []
	counter = 0
	for player in range(int(input())):
		Sum = 0
		cookies = input()
		cookies = cookies.split()
		no_of_cookies = int(cookies[0])
		cookies = cookies[1:]
		count_of_cookies = [cookies.count('1'), cookies.count('2'), cookies.count('3'), cookies.count('4'), cookies.count('5'), cookies.count('6')]
		for i in count_of_cookies:
			List = []
			for j in count_of_cookies:
				if j > 0:
					List.append(j)
			x = len(List)
			if x < 4:
				break
			minimum = min(List)
			Sum += minimum * (4 * int(x / 6) + 2 * int(x % 6 / 5) + int(x % 6 % 5 / 4))
			for z in range(len(count_of_cookies)):
				count_of_cookies[z] = count_of_cookies[z] - minimum
		total_points = no_of_cookies + Sum
		win.append(total_points)
	max_value = max(win)
	for item in win:
		if max_value == item:
			counter += 1
			index = win.index(item)
	if counter > 1:
		print('tie')
	elif index == 0:
		print('chef')
	else:
		print(index + 1)


t = int(input())
while t:
	n = int(input())
	r = []
	s = []
	while n:
		a = list(map(int, input().split()))
		k = a[0]
		a = a[1:]
		z = len(a)
		l = [[] for i in range(z)]
		p = []
		m = []
		for i in range(k):
			for j in range(z):
				if a[i] not in l[j]:
					l[j].append(a[i])
					break
		for i in range(len(l)):
			if len(l[i]) < 4:
				m.append(len(l[i]))
			elif len(l[i]) == 4:
				m.append(5)
			elif len(l[i]) == 5:
				m.append(7)
			elif len(l[i]) == 6:
				m.append(10)
		s.append(sum(m))
		n -= 1
	if s.count(max(s)) > 1:
		print('tie')
	else:
		d = s.index(max(s))
		if d == 0:
			print('chef')
		else:
			print(d + 1)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	points = [0] * 10000
	for j in range(n):
		inp = list(map(int, input().split()))
		c = inp[0]
		val = inp[1:]
		fre = [0] * 10000
		points[j] = 0
		counter = 0
		for k in range(c):
			fre[val[k] - 1] = fre[val[k] - 1] + 1
		mf = 0
		for kk in range(c):
			if fre[kk] > mf:
				mf = fre[kk]
		for pp in range(mf):
			ponter = 0
			for mm in range(6):
				fre[mm] = fre[mm] - 1
				if fre[mm] >= 0:
					ponter = ponter + 1
			if ponter == 4:
				points[j] = points[j] + 1
			elif ponter == 5:
				points[j] = points[j] + 2
			elif ponter == 6:
				points[j] = points[j] + 4
			else:
				points[j] = points[j]
		points[j] = points[j] + c
	max = 0
	index = 0
	for ii in range(n):
		if points[ii] >= max:
			max = points[ii]
			index = ii
	count = 0
	for jj in range(n):
		if points[jj] == max:
			count = count + 1
	if count == 1:
		if index == 0:
			print('chef')
		else:
			print(index + 1)
	else:
		print('tie')


import sys
import collections
t = int(sys.stdin.readline())

def takeAwayCookies(storage):
	cookiesNotTaken = {1, 2, 3, 4, 5, 6}
	for (id, type) in enumerate(storage.most_common(6)):
		storage[type[0]] -= 1
		cookiesNotTaken.remove(type[0])
		storage += collections.Counter()
	if len(cookiesNotTaken) == 0:
		return 4
	elif len(cookiesNotTaken) == 1:
		return 2
	elif len(cookiesNotTaken) == 2:
		return 1
for c in range(t):
	numPlayers = int(sys.stdin.readline())
	cookies = [[] for i in range(numPlayers)]
	scores = [-1000 for i in range(numPlayers)]
	for i in range(numPlayers):
		cookies[i] = list(map(int, sys.stdin.readline().split()))
		scores[i] = cookies[i].pop(0)
		cookies[i] = collections.Counter(cookies[i])
		numTypes = len(set(cookies[i]))
		while numTypes > 3:
			scores[i] = scores[i] + takeAwayCookies(cookies[i])
			numTypes = len(set(cookies[i]))
	maxScore = -1
	maxPlayer = -1
	tied = False
	for (id, number) in enumerate(scores):
		if number > maxScore:
			maxScore = number
			maxPlayer = id + 1
			tied = False
		elif number == maxScore:
			tied = True
	if tied:
		print('tie')
	elif maxPlayer == 1:
		print('chef')
	else:
		print(maxPlayer)


for _ in range(int(input())):
	players = int(input())
	scores = []
	for p in range(players):
		score = list(map(int, input().split()))
		scores.append(score[0])
		del score[0]
		types = [None] * 6
		for i in range(6):
			types[i] = score.count(i + 1)
		types.sort()
		types[2] -= types[1]
		types[1] -= types[0]
		scores[p] += types[0] * 4 + types[1] * 2 + types[2] * 1
	highest = max(scores)
	if scores.count(highest) > 1:
		print('tie')
	else:
		pos = scores.index(highest)
		if pos == 0:
			print('chef')
		else:
			print(pos + 1)


test = int(input())
while test > 0:
	test = test - 1
	z = {}
	n = int(input())
	c = 0
	currSum = 0
	maxSum = 0
	hash1 = {}
	maxIndex = 0
	flag = 0
	for i in range(0, n):
		currSum = 0
		hash1.clear()
		z.clear()
		s = input()
		mynums = [int(zz) for zz in s.split()]
		c = int(mynums[0])
		count = 0
		for j in range(1, 7):
			hash1[j] = 0
		for j in range(0, c):
			z[j] = int(mynums[j + 1])
			if hash1[z[j]] == 0:
				count = count + 1
			hash1[z[j]] = hash1[z[j]] + 1
		currSum = c
		while count > 3:
			if count == 4:
				currSum = currSum + 1
			if count == 5:
				currSum = currSum + 2
			if count == 6:
				currSum = currSum + 4
			count = 0
			for j in range(1, 7):
				if hash1[j] > 0:
					hash1[j] = hash1[j] - 1
					if hash1[j] > 0:
						count = count + 1
		if currSum == maxSum:
			flag = 1
		if maxSum < currSum:
			maxSum = currSum
			maxIndex = i
			flag = 0
	if maxIndex == 0 and flag == 0:
		print('chef')
	elif flag == 1:
		print('tie')
	else:
		print(maxIndex + 1)


for i in range(int(input())):
	n = int(input())
	a = 'chef'
	b = 0
	c = 0
	for i in range(0, n):
		b = 0
		l = list(map(int, input().split()))
		b = b + l[0]
		v = set(l[1:])
		d = len(v)
		while d > 3:
			h = []
			if d >= 6:
				b = b + 4
				for k in range(1, len(l)):
					if l[k] not in h:
						h.append(l[k])
					if len(h) == 6:
						break
				for j in h:
					l.remove(j)
				v = set(l[1:])
				d = len(v)
			elif d >= 5:
				b = b + 2
				for k in range(1, len(l)):
					if l[k] not in h:
						h.append(l[k])
					if len(h) == 5:
						break
				for j in h:
					l.remove(j)
				v = set(l[1:])
				d = len(v)
			elif d >= 4:
				b = b + 1
				for k in range(1, len(l)):
					if l[k] not in h:
						h.append(l[k])
					if len(h) == 4:
						break
				for j in h:
					l.remove(j)
				v = set(l[1:])
				d = len(v)
		if b > c and c == 0 and (a != 'tie'):
			c = b
		elif b > c and c == 0:
			c = b
			a = str(i + 1)
		elif b > c and c != 0:
			c = b
			a = str(i + 1)
		elif b == c:
			c = b
			a = 'tie'
	print(a)


t = int(input())
li = []
pi = []
for i in range(0, t):
	p = int(input())
	pi = []
	ki = []
	hi = []
	for j in range(0, p):
		coun = 0
		li = []
		ji = []
		li = [int(x) for x in input().split()]
		s = li[0]
		ji = []
		coun = s
		li = li[1:]
		ji.append(li.count(1))
		ji.append(li.count(2))
		ji.append(li.count(3))
		ji.append(li.count(4))
		ji.append(li.count(5))
		ji.append(li.count(6))
		ji.sort()
		for h in range(1, 105):
			r = [x for x in ji if x >= h]
			co = len(r)
			if co == 4:
				coun = coun + 1
			elif co == 5:
				coun = coun + 2
			elif co >= 6:
				coun = coun + 4
			else:
				coun = coun
		ki.append(coun)
	hi = sorted(ki, reverse=True)
	hi.append(0)
	if hi[0] == hi[1]:
		print('tie')
	elif ki.index(max(ki)) == 0:
		print('chef')
	else:
		print(ki.index(max(ki)) + 1)


from collections import Counter
t = int(input())
for k in range(t):
	n = int(input())
	s = []
	score = []
	for j in range(n):
		s.append(input().strip().split(' '))
		sl = s[j][1:]
		d = [0] * 7
		for k in range(len(sl)):
			d[int(sl[k])] += 1
		d.sort()
		score.append(int(s[j][0]))
		freq = 0
		for k in range(1, 7):
			if d[k] != 0:
				freq += 1
		if freq == 4:
			score[j] += d[3]
		if freq == 5:
			score[j] += d[2] + d[3]
		if freq == 6:
			score[j] += 2 * d[1] + d[2] + d[3]
	maximum = max(score)
	count = 0
	for tt in range(n):
		if score[tt] == maximum:
			count += 1
	if count > 1:
		print('tie')
	else:
		ind = score.index(maximum)
		if ind == 0:
			print('chef')
		else:
			print(ind + 1)


t = int(input())
dict = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
for k in range(0, t):
	n = int(input())
	pts = 0
	maxpt = 0
	tie = False
	for i in range(0, n):
		diff = 0
		typ = input().split(' ', 1)
		typ = typ[1].split(' ')
		for ii in range(1, 7):
			dict[ii] = 0
		for ii in typ:
			dict[int(ii)] += 1
		ii = 0
		typ = list(dict.values())
		typ.sort()
		while typ[ii] == 0:
			ii += 1
		if ii == 0:
			pts = 4 * typ[0] + 2 * (typ[1] - typ[0])
			if typ[2] - (typ[1] - typ[0]) - typ[0] > 0:
				pts += typ[2] - typ[1]
			pts += typ[0] + typ[1] + typ[2] + typ[3] + typ[4] + typ[5]
		elif ii == 1:
			pts = 2 * typ[1] + typ[2] - typ[1]
			pts += typ[1] + typ[2] + typ[3] + typ[4] + typ[5]
		elif ii == 2:
			pts = typ[2]
			pts += typ[2] + typ[3] + typ[4] + typ[5]
		else:
			pts = typ[3] + typ[4] + typ[5]
		if pts > maxpt:
			winr = i + 1
			maxpt = pts
			tie = False
		elif pts == maxpt:
			tie = True
	if tie:
		print('tie')
	elif winr == 1:
		print('chef')
	else:
		print(winr)


def calculate(cookies):
	score = len(cookies)
	freqs = {}
	for cookie in cookies:
		if cookie in freqs:
			freqs[cookie] += 1
		else:
			freqs[cookie] = 1
	while True:
		for i in ['1', '2', '3', '4', '5', '6']:
			try:
				if freqs[i] == 0:
					del freqs[i]
			except KeyError:
				continue
		if len(freqs) == 6:
			score += 4
			freqs.update(((x, y - 1) for (x, y) in freqs.items()))
		elif len(freqs) == 5:
			score += 2
			freqs.update(((x, y - 1) for (x, y) in freqs.items()))
		elif len(freqs) == 4:
			score += 1
			freqs.update(((x, y - 1) for (x, y) in freqs.items()))
		else:
			break
	return score

def maxScore(scores):
	hScore = max(scores)
	count = scores.count(hScore)
	if count == 1:
		winner = scores.index(hScore) + 1
		if winner == 1:
			return 'chef'
		else:
			return winner
	else:
		return 'tie'

def main():
	t = int(input())
	games = []
	for i in range(t):
		players = []
		numPlayers = int(input())
		for i in range(numPlayers):
			player = []
			line = input()
			values = line.split()
			player.append(values.pop(0))
			player.append(values)
			players.append(player)
		games.append(players)
	for players in games:
		scores = []
		for player in players:
			scores.append(calculate(player[1]))
		print(maxScore(scores))
main()


def calc_score(d, i):
	score = i
	values = list(d.values())
	values.sort()
	score += values[0] * 4 + (values[1] - values[0]) * 2 + (values[2] - values[1])
	return score
T = int(input())
for i in range(T):
	N = int(input())
	scores = {}
	for j in range(1, N + 1):
		cookies = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
		x = list(map(int, input().split(' ')))
		for k in x[1:]:
			cookies[k] += 1
		scores[j] = calc_score(cookies, x[0])
	winner = max(scores, key=scores.get)
	s = sorted(list(scores.values()), reverse=True)
	if N > 1 and s[0] == s[1]:
		print('tie')
	elif winner == 1:
		print('chef')
	else:
		print(winner)


T = int(input())
for x in range(T):
	a = [-1]
	n = int(input())
	for j in range(1, n + 1):
		c = list(map(int, input().split()))
		a.append(c[0])
		zero = 0
		typ = [0 for x in range(7)]
		for k in range(1, c[0] + 1):
			typ[c[k]] += 1
		for k in range(1, 7):
			if typ[k] == 0:
				zero += 1
		if zero > 2:
			continue
		while zero >= 0 and zero <= 2:
			if zero == 0:
				a[j] += 4
			elif zero == 1:
				a[j] += 2
			elif zero == 2:
				a[j] += 1
			zero = 0
			for k in range(1, 7):
				if typ[k] > 0:
					typ[k] -= 1
				if typ[k] == 0:
					zero += 1
	max_1 = a[1]
	pos = 1
	p = 2
	while p <= n:
		if a[p] > max_1:
			max_1 = a[p]
			pos = p
		p += 1
	f = 0
	for k in range(1, n + 1):
		if k == pos:
			continue
		elif a[k] == max_1:
			f = 1
	if f:
		print('tie')
	elif pos > 1:
		print(pos)
	elif pos == 1:
		print('chef')


def countBoxes(cookies):
	bonus = 0
	m = min(cookies)
	r = cookies.index(m)
	if m != 0:
		bonus += 4 * m
	for i in range(len(cookies)):
		cookies[i] -= m
	cookies = cookies[:r] + cookies[r + 1:]
	m = min(cookies)
	r = cookies.index(m)
	if m != 0:
		bonus += 2 * m
	for i in range(len(cookies)):
		cookies[i] -= m
	cookies = cookies[:r] + cookies[r + 1:]
	m = min(cookies)
	r = cookies.index(m)
	if m != 0:
		bonus += 1 * m
	return bonus
cases = int(input())
for case in range(cases):
	ps = int(input())
	scores = []
	tie = False
	for p in range(ps):
		play = input().split()
		types = [0 for _ in range(6)]
		for t in range(1, len(play)):
			types[int(play[t]) - 1] += 1
		score = int(play[0]) + countBoxes(types)
		scores.append(score)
	sort = sorted(scores, reverse=True)
	if len(sort) == 1:
		print('chef')
	elif sort[0] == sort[1]:
		print('tie')
	elif sort[0] == scores[0]:
		print('chef')
	else:
		print(scores.index(sort[0], 1) + 1)


def score(ar):
	a = []
	for i in range(6):
		a.append(0)
	for i in ar[1:]:
		a[i - 1] += 1
	a.sort()
	return ar[0] + a[0] * 4 + (a[1] - a[0]) * 2 + (a[2] - a[1])

def winner(player):
	win = player.index(max(player))
	player.sort()
	if len(player) == 1:
		return 'chef'
	if player[-1] == player[-2]:
		return 'tie'
	if win == 0:
		return 'chef'
	return win + 1
T = int(input())
for i in range(T):
	players = int(input())
	player = []
	for j in range(players):
		ar = [int(i) for i in input().split()]
		player.append(score(ar))
	print(winner(player))


def main():
	from sys import stdin, stdout

	def getscore(dic):
		score = 0
		while True:
			l = []
			ncount = 0
			minim = 110
			for key in dic:
				if dic[key]:
					ncount += 1
					minim = min(minim, dic[key])
					l.append(key)
			if ncount < 4:
				break
			elif ncount == 4:
				score += minim * 1
				for i in l:
					dic[i] -= minim
			elif ncount == 5:
				score += minim * 2
				for i in l:
					dic[i] -= minim
			elif ncount == 6:
				score += minim * 4
				for i in l:
					dic[i] -= minim
		return score
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		scores = []
		for i in range(n):
			t = tuple(map(int, stdin.readline().split()))
			scores.append(t[0])
			t = t[1:]
			s = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
			for k in t:
				s[k] += 1
			scores[i] += getscore(s)
		maxim = max(scores)
		index = scores.index(maxim)
		if scores.count(maxim) > 1:
			stdout.write('tie\n')
		elif index == 0:
			stdout.write('chef\n')
		else:
			stdout.write(str(index + 1) + '\n')
main()


import sys
cases = int(input())
while cases > 0:
	tie = False
	maxpts = 0
	maxguy = -1
	cases -= 1
	N = int(input())
	for i in range(N):
		temp = list(map(int, input().split()))
		typelist = [0, 0, 0, 0, 0, 0]
		pts = temp[0]
		for j in range(temp[0]):
			typelist[temp[j + 1] - 1] += 1
		typelist.sort()
		pts += typelist[0] * 4
		typelist = [x - typelist[0] for x in typelist]
		pts += typelist[1] * 2
		typelist = [x - typelist[1] for x in typelist]
		pts += typelist[2] * 1
		typelist = [x - typelist[2] for x in typelist]
		if maxpts < pts:
			maxpts = pts
			maxguy = i
			tie = False
		elif maxpts == pts:
			tie = True
	if tie:
		print('tie')
	elif maxguy == 0:
		print('chef')
	else:
		print(maxguy + 1)


for t in range(int(input())):
	n = int(input())
	ans = 0
	ind = 0
	l = []
	for i in range(1, n + 1):
		pl = [int(j) for j in input().split()]
		sum = pl[0]
		arr = [0, 0, 0, 0, 0, 0, 0]
		for j in range(1, pl[0] + 1):
			arr[pl[j]] += 1
		no0 = 0
		f = 0
		for j in arr[1:]:
			if j == 0:
				f = 1
				break
		if f == 0:
			m = min(arr[1:])
			for j in range(1, 7):
				arr[j] -= m
			sum += 4 * m
		f = 0
		for j in arr[1:]:
			if j == 0:
				no0 += 1
			if no0 > 1:
				f = 1
				break
		if f == 0:
			for j in arr[1:]:
				if j != 0:
					m = j
					break
			for j in arr[1:]:
				if j < m and j != 0:
					m = j
			for j in range(1, 7):
				if arr[j] != 0:
					arr[j] -= m
			sum += 2 * m
		f = 0
		no0 = 0
		for j in arr[1:]:
			if j == 0:
				no0 += 1
			if no0 > 2:
				f = 1
				break
		if f == 0:
			for j in arr[1:]:
				if j != 0:
					m = j
					break
			for j in arr[1:]:
				if j < m and j != 0:
					m = j
			for j in range(1, 7):
				if arr[j] != 0:
					arr[j] -= m
			sum += 1 * m
		l.append(sum)
		if sum > ans:
			ans = sum
			ind = i
	c = 0
	for j in range(n):
		if l[j] == ans:
			c += 1
		if c == 2:
			print('tie')
			break
	if c < 2:
		print('chef' if ind == 1 else ind)


TC = int(input())
for t in range(0, TC):
	N = int(input())
	max_score = -1
	tie = False
	win = 0
	for n in range(0, N):
		T = [0] * 6
		C = list(map(int, input().split()))
		for c in range(1, len(C)):
			T[C[c] - 1] += 1
		T.sort()
		score = C[0]
		score += T[0] * 4
		T[1] -= T[0]
		T[2] -= T[0]
		score += T[1] * 2
		T[2] -= T[1]
		score += T[2]
		if score > max_score:
			tie = False
			max_score = score
			win = n
		elif score == max_score:
			tie = True
			max_score = score
			win = n
	if tie:
		print('tie')
	elif win == 0:
		print('chef')
	else:
		print(win + 1)


import collections

def solve(cookies):
	rv = len(cookies)
	counter = collections.Counter(cookies)
	cookies.sort(key=lambda x: (counter[x], x))
	last_cookie = cookies.pop()
	packages = [[last_cookie]]
	current = 0
	while cookies:
		cookie = cookies.pop()
		if cookie == last_cookie:
			current += 1
			try:
				packages[current].append(cookie)
			except IndexError:
				packages.append([cookie])
		else:
			current = 0
			while True:
				if len(packages[current]) < 6:
					packages[current].append(cookie)
					break
				else:
					current += 1
		last_cookie = cookie
	for package in packages:
		if len(package) == 6:
			rv += 4
		elif len(package) == 5:
			rv += 2
		elif len(package) == 4:
			rv += 1
	return rv
t = int(input())
for _ in range(0, t):
	nplayers = int(input())
	best = 0
	winner = -1
	tie = False
	for player in range(1, nplayers + 1):
		l = [int(x) for x in input().split(' ')]
		ncookies = l[0]
		cookies = l[1:]
		score = solve(cookies)
		if score == best:
			tie = True
			best = score
			winner = player
		elif score > best:
			tie = False
			best = score
			winner = player
	if tie:
		print('tie')
	else:
		print('chef' if winner == 1 else winner)


t = int(input())
cookies_types_count = 6
weight = [4, 2, 1, 0, 0, 0]
for id in range(t):
	n = int(input())
	winner_score = 0
	winners = []
	for p in range(1, n + 1):
		[m, *c_list] = [int(c) for c in input().split(' ')]
		cnt = [0 for i in range(cookies_types_count)]
		for c in c_list:
			c = c - 1
			cnt[c] = cnt[c] + 1
		cnt.sort()
		score = m
		used = 0
		for i in range(cookies_types_count):
			remaining = cnt[i] - used
			score = score + weight[i] * remaining
			used = cnt[i]
		if score > winner_score:
			winner_score = score
			winners = [p]
		elif score == winner_score:
			winners.append(p)
	if len(winners) > 1:
		print('tie')
	elif winners[0] == 1:
		print('chef')
	else:
		print(winners[0])


no_of_tests = int(input())
test_case = 0
while test_case < no_of_tests:
	no_of_players = int(input())
	score = [0] * no_of_players
	player_no = 0
	while player_no < no_of_players:
		cookie_type_count = [0] * 6
		cookies = input()
		count = 0
		for cookie in cookies.split():
			if count == 0:
				score[player_no] += int(cookie)
			else:
				cookie_type_count[int(cookie) - 1] += 1
			count += 1
		cookie_type_count.sort(reverse=True)
		first_minima = cookie_type_count.pop()
		score[player_no] += first_minima * 4
		second_minima = cookie_type_count.pop() - first_minima
		score[player_no] += second_minima * 2
		thrid_minima = cookie_type_count.pop() - second_minima - first_minima
		score[player_no] += thrid_minima * 1
		player_no += 1
	max_score = -1
	max_index = -1
	is_tie = 0
	index = 0
	for s in score:
		if s > max_score:
			max_score = s
			max_index = index
			is_tie = 0
		elif s == max_score:
			is_tie = 1
		index += 1
	if is_tie:
		print('tie')
	elif max_index == 0:
		print('chef')
	else:
		print(max_index + 1)
	test_case += 1


def getScore(types):
	bags = [0] * 6
	for i in types:
		bags[i - 1] += 1
	score = sum(bags)
	for i in range(3):
		extraScore = 0
		if len(bags) == 6:
			extraScore = 4
		elif len(bags) == 5:
			extraScore = 2
		elif len(bags) == 4:
			extraScore = 1
		else:
			break
		minNum = min(bags)
		score += minNum * extraScore
		bags = [i - minNum for i in bags if i - minNum > 0]
	return score
testCase = int(input())
while testCase != 0:
	testCase -= 1
	playerCount = int(input())
	scoreArray = []
	while playerCount != 0:
		playerCount -= 1
		data = [int(i) for i in input().strip().split(' ')]
		types = data[1:]
		scoreArray.append(getScore(types))
	maxScore = max(scoreArray)
	if len([1 for i in scoreArray if i == maxScore]) > 1:
		print('tie')
	elif scoreArray[0] == maxScore:
		print('chef')
	else:
		print([i for i in range(len(scoreArray)) if scoreArray[i] == maxScore][0] + 1)