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

 Chef likes to play football with his friends. They played a number of matches and surprisingly, every match was a tie, so they decided to declare the winner with penalty shoot-out. As they didn't know the penalty shoot-out rules, they just decided to take 20 shots alternatively (each team takes 10 shots).

One day, Chef's friend Shivam heard about the matches and got confused. Later Shivam went to Chef and his friends and explained the shoot-out rules. Then, they all decided to calculate and once again declare the winner of each match as per the standard football penalty shoot-out rules.

The standard rules are:

The teams will take shots alternatively.
At first, each team will take five penalty shots.
If one team does not have more goals than the other after these five shots, the shoot-out will proceed to sudden death.
In between of first 10 kicks, If one team has an advantage over other which can't be compensated, then the team with the advantage will be declared winner at that instant i.e. before the completion of 10 kicks.
In sudden death, each team will take at most five more shots. Everytime after both teams take a shot, the following rule is used: if one team has scored more goals than the other, that team is the winner.
If each team has taken 10 shots and the winner still cannot be decided, the result will be a tie.

The result of the shoot-out for each game is given as a binary string where '1' represents GOAL and '0' represents MISS. Chef's team always starts first. Keep in mind that the teams alternate when taking the shots — the first character corresponds to the first shot of Chef's team, the second character to the first shot of the opposing team, the third character to the second shot of Chef's team etc.

As there are many matches to evaluate, Chef and his friends are unable to do so and they require your help. You have to tell them the winner of each match.

If a match ended in a tie, print "TIE". If Chef's team won, print "TEAM-A", otherwise print "TEAM-B". Also, if the match didn't end in a tie, print the minimum number of kicks required to decide the result, so that they can also know how much times they shot in vain.

Note: Input/Output files are large, use fast reading/writing methods

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

The input consists of several lines.
Each line contains the record of the shoot-out for a single match in the form of a binary string where '1' represents GOAL and '0' represents MISS, starting from Chef's team alternatively.

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

On each line, print the winner of the corresponding match ("TEAM-A" or "TEAM-B") and the number of shots required to decide the result, separated by a space. If there is no winner, print "TIE" instead.

------ Constraints ------ 

$each line contains a 20-bit binary string$
$number of matches ≤ 10^{6}$

------ Subtasks ------ 

Subtask 1 (20 points):

$the first 10 kicks always result in a tie, i.e. the shoot-out will always go to sudden death$
$number of matches ≤ 10^{3}$

Subtask 2 (80 points): original constraints

----- Sample Input 1 ------ 
10100101111011111111

00000000000000000000

01011101110110101111
----- Sample Output 1 ------ 
TEAM-A 12

TIE

TEAM-B 7
----- explanation 1 ------ 
Example case 1: After 5 turns, the result was a tie and after the 6th turn, the score was 4:3, so Chef's team was the winner and the number of shots required to decide the result was 12.
Example case 2: Both teams didn't score any goal, so the match resulted in a tie after 10 turns (20 shots). 
Example case 3: After 7 shots i.e. 0101110, the score was 1:3. Now, regardless of the following shots, we can say that the winner will always be TEAM-B, so only 7 shots are needed to say that TEAM-B is the winner.

Difficulty: MEDIUM_HARD
Tags: String algorithms

Data structures

Implementation
Skill types: Data structures

Starter code:

Solutions:
def soln():
	s = input()
	temp = 0
	A = 0
	B = 0
	for i in range(0, 10):
		if i % 2 == 0 and s[i] == '1':
			A = A + 1
		if i % 2 == 1 and s[i] == '1':
			B = B + 1
		if A - B > 5 - (i + 1) // 2:
			print('TEAM-A', i + 1)
			break
		if B - A > 4 - i // 2:
			print('TEAM-B', i + 1)
			break
	if B == A:
		flag = 0
		for i in range(10, 20, 2):
			if s[i:i + 2] == '10':
				print('TEAM-A', i + 2)
				flag = 1
				break
			if s[i:i + 2] == '01':
				print('TEAM-B', i + 2)
				flag = 1
				break
		if flag == 0:
			print('TIE')
try:
	while True:
		soln()
except:
	pass


while True:
	try:
		s = input()
		if s == '':
			break
		(c0, c1) = (0, 0)
		ans = 0
		for i in range(20):
			if i % 2:
				c1 += 1 if s[i] == '1' else 0
			else:
				c0 += 1 if s[i] == '1' else 0
			ans += 1
			if i < 9:
				cb = ans // 2
				ca = cb + ans % 2
				if c0 > c1 and 5 - cb + c1 < c0:
					break
				if c1 > c0 and 5 - ca + c0 < c1:
					break
			elif i == 9 and c0 != c1:
				break
			elif i % 2:
				if c0 != c1:
					break
		if c0 == c1:
			print('TIE')
		elif c0 > c1:
			print('TEAM-A', ans)
		else:
			print('TEAM-B', ans)
	except:
		break


def soln():
	s = list(map(int, list(input())))
	a_score = b_score = 0
	a_rem = b_rem = 5
	for i in range(10):
		if i & 1:
			b_score += s[i]
			b_rem -= 1
		else:
			a_score += s[i]
			a_rem -= 1
		if a_score - b_score > b_rem:
			return f'TEAM-A {i + 1}'
		if b_score - a_score > a_rem:
			return f'TEAM-B {i + 1}'
	if a_score > b_score:
		return f'TEAM-A {10}'
	elif b_score > a_score:
		return f'TEAM-B {10}'
	for i in range(10, 20, 2):
		a_score += s[i]
		b_score += s[i + 1]
		if a_score > b_score:
			return f'TEAM-A {i + 2}'
		if a_score < b_score:
			return f'TEAM-B {i + 2}'
	return 'TIE'
try:
	while True:
		print(soln())
except:
	pass


s = input()
while len(s) > 0:
	A = [0]
	B = [0]
	for i in range(10):
		A.append(A[-1] + int(s[i * 2]))
		B.append(B[-1] + int(s[i * 2 + 1]))
	if A[5] == B[5]:
		tie = True
		for i in range(6, len(A)):
			if A[i] > B[i]:
				tie = False
				print('TEAM-A', 2 * i)
				break
			elif A[i] < B[i]:
				tie = False
				print('TEAM-B', 2 * i)
				break
		if tie:
			print('TIE')
	elif A[5] > B[5]:
		at = 0
		bt = 0
		i = 0
		chance = 5
		while i < 10:
			if i & 1 == 0:
				at += int(s[i])
				if bt + chance < at:
					print('TEAM-A', i + 1)
					break
			else:
				bt += int(s[i])
				chance -= 1
				if bt + chance < at:
					print('TEAM-A', i + 1)
					break
			i += 1
	elif A[5] < B[5]:
		at = 0
		bt = 0
		i = 0
		chance = 5
		while i < 10:
			if i & 1 == 0:
				at += int(s[i])
				chance -= 1
				if at + chance < bt:
					print('TEAM-B', i + 1)
					break
			else:
				bt += int(s[i])
				if at + chance < bt:
					print('TEAM-B', i + 1)
					break
			i += 1
	try:
		s = input()
	except:
		s = ''


import sys
for line in sys.stdin:
	line = line.strip()
	score_1 = score_2 = 0
	left_1 = left_2 = 5
	shoot_count = 0
	for (i, b) in enumerate(line[:10]):
		if i % 2 == 0:
			left_1 -= 1
			score_1 += int(b)
		else:
			left_2 -= 1
			score_2 += int(b)
		shoot_count += 1
		if score_1 - score_2 > left_2 or score_2 - score_1 > left_1:
			break
	if score_1 == score_2:
		for (i, b) in enumerate(line[10:]):
			if i % 2 == 0:
				score_1 += int(b)
			else:
				score_2 += int(b)
			shoot_count += 1
			if i % 2 == 1 and score_1 != score_2:
				break
	print(score_1, score_2, file=sys.stderr)
	if score_1 > score_2:
		print('TEAM-A', shoot_count)
	elif score_2 > score_1:
		print('TEAM-B', shoot_count)
	else:
		print('TIE')


try:
	while True:
		s = input()
		(a, b) = (0, 0)
		for i in range(10):
			n = int(s[i])
			a += (i % 2 == 0) * n
			b += (i % 2 == 1) * n
			if a > b + 5 - (i + 1) // 2:
				print(f'TEAM-A {i + 1}')
				break
			elif b > a + 4 - i // 2:
				print(f'TEAM-B {i + 1}')
				break
		else:
			for i in range(10, 20):
				n = int(s[i])
				a += (i % 2 == 0) * n
				b += (i % 2 == 1) * n
				if i % 2 == 1:
					if a > b:
						print(f'TEAM-A {i + 1}')
						break
					elif b > a:
						print(f'TEAM-B {i + 1}')
						break
			else:
				print('TIE')
except EOFError:
	pass


while True:
	try:
		n = input()
		(l1, l2) = ([], [])
		(o1, oo) = (0, 0)
		temp = False
		for i in range(len(n)):
			if i < 10:
				l1.append(n[i])
			else:
				l2.append(n[i])
			if n[i] == '1':
				o1 += 1
			else:
				oo += 1
		if oo == 0 or o1 == 0:
			print('TIE')
			temp = True
		(p_a, p_b) = (0, 0)
		(ka, kb) = (5, 5)
		k11 = 0
		if temp != True:
			for i in range(10):
				if i % 2 == 0:
					if l1[i] == '1':
						p_a += 1
					ka -= 1
				else:
					if l1[i] == '1':
						p_b += 1
					kb -= 1
				if p_b > ka + p_a:
					print('TEAM-B', i + 1)
					temp = True
					k11 = 1
					break
				elif p_a > kb + p_b:
					print('TEAM-A', i + 1)
					temp = True
					k11 = 1
					break
		(s_a, s_b) = (0, 0)
		if temp != True and k11 == 0:
			for i in range(0, 10, 2):
				if l2[i] == '1' and l2[i + 1] == '0':
					print('TEAM-A', i + 10 + 2)
					k11 = 1
					temp = True
					break
				elif l2[i] == '0' and l2[i + 1] == '1':
					print('TEAM-B', i + 10 + 2)
					k11 = 1
					temp = True
					break
			else:
				print('TIE')
	except EOFError:
		break


while True:
	try:
		x = input()
		score1 = score2 = 0
		remaining1 = 5
		remaining2 = 5
		for i in range(10):
			if i % 2 == 0:
				score1 += int(x[i])
				remaining1 -= 1
			else:
				score2 += int(x[i])
				remaining2 -= 1
			if score2 > score1 and score2 - score1 > remaining1:
				print('TEAM-B', i + 1)
				break
			if score1 > score2 and score1 - score2 > remaining2:
				print('TEAM-A', i + 1)
				break
		else:
			score1 = score2 = 0
			for j in range(10, 20, 2):
				y = x[j:j + 2]
				if y[0] != y[1]:
					if y[0] == '1':
						print('TEAM-A', j + 2)
						break
					else:
						print('TEAM-B', j + 2)
						break
			else:
				print('TIE')
	except EOFError:
		break


while True:
	try:
		scoresheet = input()
		sudden_death = True
		tie = True
		team_A = 0
		team_B = 0
		kicks_remaining_A = 5
		kicks_remaining_B = 5
		for i in range(10):
			score = scoresheet[i]
			if i % 2 == 0:
				if score == '1':
					team_A += 1
				kicks_remaining_A -= 1
			else:
				if score == '1':
					team_B += 1
				kicks_remaining_B -= 1
			if team_A > team_B + kicks_remaining_B:
				print('TEAM-A', i + 1)
				sudden_death = False
				break
			if team_B > team_A + kicks_remaining_A:
				print('TEAM-B', i + 1)
				sudden_death = False
				break
		if sudden_death:
			for i in range(10, 20, 2):
				A = scoresheet[i]
				B = scoresheet[i + 1]
				if A == '1' and B == '0':
					print('TEAM-A', i + 2)
					tie = False
					break
				if B == '1' and A == '0':
					print('TEAM-B', i + 2)
					tie = False
					break
			if tie:
				print('TIE')
	except EOFError:
		break


try:
	while True:
		goals = input()
		team_a = 0
		team_b = 0
		for (i, goal) in enumerate(goals):
			if i < 10:
				if i % 2 == 0:
					team_a += int(goal)
				else:
					team_b += int(goal)
				if team_b - team_a > 5 - (i + 2) // 2:
					print('TEAM-B', i + 1)
					break
				elif team_a - team_b > 5 - (i + 1) // 2:
					print('TEAM-A', i + 1)
					break
			elif i % 2 == 0:
				last = int(goal)
			else:
				current = int(goal)
				if last == current:
					pass
				elif last > current:
					print('TEAM-A', i + 1)
					break
				else:
					print('TEAM-B', i + 1)
					break
		else:
			print('TIE')
except:
	pass


def solver(line):
	score_A = 0
	score_B = 0
	penalties_taken_by_A = 0
	penalties_taken_by_B = 0
	string_to_print = 'TIE'
	for i in range(len(line)):
		if i % 2 == 0:
			score_A += int(line[i])
			penalties_taken_by_A += 1
		else:
			score_B += int(line[i])
			penalties_taken_by_B += 1
		if i <= 9:
			if score_A > score_B + (5 - penalties_taken_by_B):
				string_to_print = 'TEAM-A ' + str(i + 1)
				break
			elif score_B > score_A + (5 - penalties_taken_by_A):
				string_to_print = 'TEAM-B ' + str(i + 1)
				break
		elif penalties_taken_by_A == penalties_taken_by_B:
			if score_A > score_B:
				string_to_print = 'TEAM-A ' + str(i + 1)
				break
			elif score_B > score_A:
				string_to_print = 'TEAM-B ' + str(i + 1)
				break
	print(string_to_print)
	return
try:
	s = input()
	while len(s) > 0:
		solver(s)
		s = input()
except:
	pass


while True:
	try:
		a = input()
		ps = a[:10]
		s = a[10:]
		win = ''
		p1 = 0
		p2 = 0
		t = 0
		c1 = 0
		c2 = 0
		for i in range(10):
			t += 1
			if i & 1:
				c2 += 1
				if ps[i] == '1':
					p2 += 1
			else:
				c1 += 1
				if ps[i] == '1':
					p1 += 1
			if p1 > p2:
				d = p1 - p2
				if d > 5 - c2:
					break
			elif p2 > p1:
				d = p2 - p1
				if d > 5 - c1:
					break
		if p1 > p2:
			print('TEAM-A', t)
		elif p2 > p1:
			print('TEAM-B', t)
		else:
			sp1 = 0
			sp2 = 0
			t1 = 0
			for i in range(10):
				t1 += 1
				if i & 1:
					if s[i] == '1':
						sp2 += 1
					if sp1 != sp2:
						break
				elif s[i] == '1':
					sp1 += 1
			if sp1 > sp2:
				print('TEAM-A', 10 + t1)
			elif sp2 > sp1:
				print('TEAM-B', 10 + t1)
			else:
				print('TIE')
	except EOFError:
		exit()


while True:
	try:
		a = input()
		t = []
		A = 0
		B = 0
		for i in range(0, 10):
			t.append(int(a[i]))
			if t[i] == 1:
				if i % 2 == 0:
					A = A + 1
				else:
					B = B + 1
			if i % 2 == 0:
				if A - B > int((9 - i) / 2) + 1:
					break
			elif A - B > int((9 - i) / 2):
				break
			if B - A > int((9 - i) / 2):
				break
		if A > B:
			print(f'TEAM-A {i + 1}')
		elif B > A:
			print(f'TEAM-B {i + 1}')
		else:
			j = 0
			while j < 5:
				t = a[10 + 2 * j:10 + 2 * j + 2]
				if t == '01':
					print(f'TEAM-B {12 + 2 * j}')
					break
				if t == '10':
					print(f'TEAM-A {12 + 2 * j}')
					break
				j = j + 1
			if j == 5:
				print('TIE')
	except EOFError:
		exit()


def solve(s):
	s1 = s[:10]
	s2 = s[10:]
	leftA = 5
	leftB = 5
	A = B = 0
	for i in range(10):
		if i % 2 == 0:
			if s[i] == '1':
				A += 1
			leftA -= 1
		if i % 2 == 1:
			if s[i] == '1':
				B += 1
			leftB -= 1
		if A > B and A - B > leftB:
			print('TEAM-A', i + 1)
			return
		if B > A and B - A > leftA:
			print('TEAM-B', i + 1)
			return
	if A > B:
		print('TEAM-A', i)
		return
	if B > A:
		print('TEAM-B', i)
		return
	for i in range(0, 9, 2):
		if s2[i] == '1' and s2[i + 1] == '0':
			print('TEAM-A', i + 12)
			return
		if s2[i] == '0' and s2[i + 1] == '1':
			print('TEAM-B', i + 12)
			return
	print('TIE')
	return
while True:
	try:
		s = str(input())
		solve(s)
	except:
		break


def solve(s):
	(curr_score_a, curr_score_b) = (0, 0)
	(shots_left_a, shots_left_b) = (5, 5)
	res = 0
	for i in range(10):
		res += 1
		if i & 1:
			curr_score_b += 1 if s[i] == '1' else 0
			shots_left_b -= 1
		else:
			curr_score_a += 1 if s[i] == '1' else 0
			shots_left_a -= 1
		if curr_score_b > curr_score_a + shots_left_a:
			print('TEAM-B', res)
			break
		if curr_score_a > curr_score_b + shots_left_b:
			print('TEAM-A', res)
			break
	if curr_score_a == curr_score_b:
		tie_flg = True
		for i in range(10, 20, 2):
			if s[i] == s[i + 1]:
				res += 2
			else:
				tie_flg = False
				res += 2
				if s[i] == '1':
					print('TEAM-A', res)
				else:
					print('TEAM-B', res)
				break
		if tie_flg:
			print('TIE')
try:
	s = input()
	while len(s) > 0:
		solve(s)
		s = input()
except:
	pass


n = 3
while 1:
	try:
		a = input()
	except EOFError:
		break
	x = 0
	y = 0
	z = 0
	alost = 5
	blost = 5
	count = 0
	for i in range(0, 10):
		if i % 2 == 0:
			if a[i] == '1':
				x = x + 1
			alost = alost - 1
		elif i % 2 == 1:
			if a[i] == '1':
				y = y + 1
			blost = blost - 1
		if x + alost < y:
			print('TEAM-B', i + 1)
			count = count + 1
			break
		elif y + blost < x:
			print('TEAM-A', i + 1)
			count = count + 1
			break
	if count == 0:
		found = 0
		for i in range(10, 20, 2):
			if a[i] != a[i + 1]:
				if a[i] == '0':
					print('TEAM-B', i + 2)
					found = found + 1
					break
				elif a[i + 1] == '0':
					print('TEAM-A', i + 2)
					found = found + 1
					break
		if found == 0:
			print('TIE')


import math
while True:
	try:
		string = input()
	except EOFError:
		break
	else:
		(teama, teamb) = (0, 0)
		winner = 'TIE'
		for i in range(len(string)):
			res = string[i]
			if i % 2 == 0:
				teama += int(res)
			elif i % 2 != 0:
				teamb += int(res)
			else:
				pass
			if i <= 9:
				remb = 5 - (i + 1) // 2
				rema = 5 - math.ceil((i + 1) / 2)
				if teama > teamb and remb < teama - teamb:
					winner = 'TEAM-A'
					break
				if teamb > teama and rema < teamb - teama:
					winner = 'TEAM-B'
					break
			if i > 9 and i % 2 != 0:
				if teama > teamb:
					winner = 'TEAM-A'
					break
				elif teama < teamb:
					winner = 'TEAM-B'
					break
				else:
					continue
		if winner != 'TIE':
			print(winner, i + 1)
		else:
			print(winner)


while True:
	try:
		scor = str(input())
		usual = scor[:10]
		sdn = scor[10:]
		(a, b) = (0, 0)
		(lefta, leftb) = (5, 5)
		win = 'none'
		match = 0
		for i in range(10):
			if i % 2 == 0:
				if usual[i] == '1':
					a += 1
				lefta -= 1
			else:
				if usual[i] == '1':
					b += 1
				leftb -= 1
			if a > b and a - b > leftb:
				win = 'TEAM-A'
				match = i + 1
				break
			if b > a and b - a > lefta:
				win = 'TEAM-B'
				match = i + 1
				break
		if win == 'none':
			for i in range(0, 9, 2):
				if sdn[i:i + 2] == '01':
					win = 'TEAM-B'
					match = i + 12
					break
				elif sdn[i:i + 2] == '10':
					win = 'TEAM-A'
					match = i + 12
					break
				else:
					continue
		if win != 'none':
			print(win, match)
		else:
			print('TIE')
	except:
		break


while 1:
	try:
		string = input()
		if string[:6] == '101010':
			print('TEAM-A 6')
		elif string[:6] == '010101':
			print('TEAM-B 6')
		else:
			score_a = string[0:7:2].count('1')
			score_b = string[1:7:2].count('1')
			if score_a - score_b == 3:
				print('TEAM-A 7')
			elif score_b - score_a == 2:
				print('TEAM-B 7')
			else:
				score_b += int(string[7])
				if score_a - score_b == 2:
					print('TEAM-A 8')
				elif score_b - score_a == 2:
					print('TEAM-B 8')
				else:
					score_a += int(string[8])
					if score_a - score_b == 2:
						print('TEAM-A 9')
					elif score_b - score_a == 1:
						print('TEAM-B 9')
					else:
						score_b += int(string[9])
						if score_a - score_b == 1:
							print('TEAM-A 10')
						elif score_b - score_a == 1:
							print('TEAM-B 10')
						else:
							for i in range(10, 20, 2):
								score_a += int(string[i])
								score_b += int(string[i + 1])
								if score_a - score_b == 1:
									print(f'TEAM-A {i + 2}')
									break
								elif score_b - score_a == 1:
									print(f'TEAM-B {i + 2}')
									break
								if i == 18:
									print('TIE')
	except:
		break


def penalties(s):
	s1 = s[:10:2]
	s2 = s[1:10:2]
	x = 0
	y = 0
	for i in range(10):
		i = int(i)
		if i % 2 == 0:
			if s1[i // 2] == '1':
				x += 1
			if y > x + (9 - i) // 2:
				return 'TEAM-B ' + str(i + 1)
			elif x > y + (9 - i) // 2 + 1:
				return 'TEAM-A ' + str(i + 1)
		else:
			if s2[i // 2] == '1':
				y += 1
			if x > y + (9 - i) // 2:
				return 'TEAM-A ' + str(i + 1)
			elif y > x + (9 - i) // 2:
				return 'TEAM-B ' + str(i + 1)
	if x > y:
		return 'TEAM-A ' + 10
	elif y > x:
		return 'TEAM-B ' + 10
	else:
		s1 = s[10::2]
		s2 = s[11::2]
		for i in range(5):
			if s1[i] == '1' and s2[i] == '0':
				return 'TEAM-A ' + str(i * 2 + 12)
			elif s1[i] == '0' and s2[i] == '1':
				return 'TEAM-B ' + str(i * 2 + 12)
	return 'TIE'
while True:
	try:
		s = str(input())
		print(penalties(s))
	except:
		break


def xyz(a, b, x):
	if 5 - x < b - a:
		return 1
	else:
		return 0

def king(st):
	a = st[:10]
	b = st[10:]
	a1 = 0
	b1 = 0
	c = 1
	res = 'None'
	(a2, b2) = (0, 0)
	for i in a:
		if c % 2 == 1:
			a1 = a1 + int(i)
			a2 += 1
		else:
			b1 = b1 + int(i)
			b2 += 1
		if xyz(a1, b1, a2) and a1 != b1:
			res = 'TEAM-B '
			return res + str(c)
			break
		if xyz(b1, a1, b2) and a1 != b1:
			res = 'TEAM-A '
			return res + str(c)
			break
		c += 1
	c = 11
	if a1 == b1 and res == 'None':
		for i in b:
			if c % 2 == 1:
				a1 = a1 + int(i)
			else:
				b1 = b1 + int(i)
			if a1 > b1 and c % 2 == 0:
				res = 'TEAM-A '
				return res + str(c)
				break
			elif b1 > a1 and c % 2 == 0:
				res = 'TEAM-B '
				return res + str(c)
				break
			c += 1
	return 'TIE'
while True:
	try:
		st = str(input())
		print(king(st))
	except Exception as e:
		break


def solve(L):
	A = []
	B = []
	for i in range(20):
		if i % 2 == 0:
			A.append(L[i])
		else:
			B.append(L[i])
	s1 = 0
	s2 = 0
	for i in range(5):
		if A[i] == '1':
			s1 += 1
		else:
			pass
		if s1 - s2 > 5 - i:
			return 'TEAM-A ' + str(2 * i + 1)
		elif s2 - s1 > 5 - i - 1:
			return 'TEAM-B ' + str(2 * i + 1)
		else:
			pass
		if B[i] == '1':
			s2 += 1
		else:
			pass
		if s2 - s1 > 5 - i - 1:
			return 'TEAM-B ' + str(2 * i + 2)
		elif s1 - s2 > 5 - i - 1:
			return 'TEAM-A ' + str(2 * i + 2)
	for i in range(5, 10):
		if A[i] == '1':
			s1 += 1
		if B[i] == '1':
			s2 += 1
		if s1 > s2:
			return 'TEAM-A ' + str(2 * i + 2)
		elif s2 > s1:
			return 'TEAM-B ' + str(2 * i + 2)
	return 'TIE'
while True:
	try:
		L = list(input())
		print(solve(L))
	except Exception as e:
		break


from sys import stdin, stdout
import math
from collections import Counter
import functools
import time

def tr():
	return range(int(line()))

def sm():
	return map(int, line().split())

def ln():
	return list(sm())

def nl():
	return int(line())

def ssm():
	return map(str, line().split())

def line():
	return stdin.readline().rstrip()

def b(x):
	return bin(x).replace('0b', '')

def o(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + '\n')

def osp(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + ' ')

def ol(x):
	stdout.write(' '.join(map(str, x)))

def wline():
	return stdin.read().split()

def main():
	for m in wline():
		team_a = m[::2]
		team_b = m[1::2]
		score_a = 0
		score_b = 0
		n = 20
		index = 0
		result = 'TIE'
		for i in range(5):
			if team_a[i] == '1':
				score_a += 1
			if score_b - score_a > 4 - i or score_a - score_b > 5 - i:
				index = i * 2 + 1
				break
			if team_b[i] == '1':
				score_b += 1
			if score_b - score_a > 4 - i or score_a - score_b > 4 - i:
				index = i * 2 + 2
				break
		if score_b == score_a:
			for i in range(5):
				if team_a[5 + i] == '1':
					score_a += 1
				if team_b[5 + i] == '1':
					score_b += 1
				if abs(score_b - score_a):
					index = i * 2 + 12
					break
		if not index:
			print('TIE')
		elif score_a > score_b:
			print('TEAM-A', index)
		else:
			print('TEAM-B', index)
main()


try:
	from debug import debug, timer
except ImportError:
	pass
from sys import stdin

def solve(s):
	(a, b) = (s[0::2], s[1::2])
	(score_a, score_b) = (0, 0)
	for i in range(5):
		score_a += int(a[i])
		if score_b - score_a > 5 - i - 1:
			return 'TEAM-B ' + str(2 * i + 1)
		if score_a - score_b > 5 - i:
			return 'TEAM-A ' + str(2 * i + 1)
		score_b += int(b[i])
		if score_b - score_a > 5 - i - 1:
			return 'TEAM-B ' + str(2 * i + 2)
		if score_a - score_b > 5 - i - 1:
			return 'TEAM-A ' + str(2 * i + 2)
	for i in range(5):
		score_a += int(a[5 + i])
		score_b += int(b[5 + i])
		if score_b > score_a:
			return 'TEAM-B ' + str(2 * i + 12)
		if score_a > score_b:
			return 'TEAM-A ' + str(2 * i + 12)
	return 'TIE'

def do_codechef():
	all_inputs = stdin.read()
	for s in all_inputs.split():
		print(solve(s))
do_codechef()
exit()


while True:
	try:
		n = input()
	except:
		exit()
	if n.count('1') == 20 or n.count('0') == 20:
		print('TIE')
	else:
		gc = 0
		go = 0
		c = 0
		a = False
		b = True
		fnal = 0
		for i in range(20):
			if c < 10:
				c += 1
				if i % 2 == 0:
					if n[i] == '1':
						gc += 1
				elif n[i] == '1':
					go += 1
				if i % 2 == 0:
					if gc > go:
						if go + (10 - c) // 2 + 1 < gc:
							a = True
							fnal = c
							break
					elif gc + (10 - c) // 2 < go:
						fnal = c
						break
				elif gc > go:
					if go + (10 - c) // 2 < gc:
						a = True
						fnal = c
						break
				elif gc + (10 - c) // 2 < go:
					fnal = c
					break
			else:
				c += 1
				if i % 2 == 0:
					if n[i] == '1':
						gc += 1
				elif n[i] == '1':
					go += 1
				if c % 2 == 0:
					if gc > go:
						fnal = c
						a = True
						break
					elif go > gc:
						fnal = c
						break
		if c != 20:
			if a:
				print('TEAM-A', +fnal)
			else:
				print('TEAM-B', +fnal)
		elif c == 20:
			if gc == go:
				print('TIE')
			elif gc > go:
				print('TEAM-A', +fnal)
			else:
				print('TEAM-B', +fnal)


def rondas(tiros, goles_a, goles_b):
	rondas_a = 5
	rondas_b = 5
	for i in range(10):
		if i % 2:
			goles_b += int(tiros[i])
			rondas_b -= 1
		else:
			goles_a += int(tiros[i])
			rondas_a -= 1
		if goles_a - goles_b > rondas_b:
			return 'TEAM-A ' + str(i + 1)
		if goles_b - goles_a > rondas_a:
			return 'TEAM-B ' + str(i + 1)
	return ''

def muerte_subita(tiros, goles_a, goles_b):
	for i in range(10, 20):
		if i % 2:
			goles_b += int(tiros[i])
			if goles_a > goles_b:
				return 'TEAM-A ' + str(i + 1)
			if goles_b > goles_a:
				return 'TEAM-B ' + str(i + 1)
		else:
			goles_a += int(tiros[i])
	return 'TIE'
try:
	tiros = input()
except:
	tiros = ''
while len(tiros) != 0:
	ga = 0
	gb = 0
	resultado = rondas(tiros, ga, gb)
	if resultado == '':
		resultado = muerte_subita(tiros, ga, gb)
	print(resultado)
	try:
		tiros = input()
	except:
		tiros = ''


while True:
	try:
		s = input()
	except:
		exit()
	ga = 0
	gb = 0
	for i in range(10):
		if i % 2 == 0:
			if ga + 5 - i // 2 < gb:
				print('TEAM-B', i)
				break
			elif gb + 4 - (i - 1) // 2 < ga:
				print('TEAM-A', i)
				break
			ga += int(s[i])
		elif i % 2 == 1:
			if gb + 5 - (i - 1) // 2 < ga:
				print('TEAM-A', i)
				break
			elif ga + 4 - i // 2 < gb:
				print('TEAM-B', i)
				break
			gb += int(s[i])
	else:
		for i in range(10, 20):
			if i == 10:
				if ga > gb:
					print('TEAM-A', i)
					break
				elif gb > ga:
					print('TEAM-B', i)
					break
			if i % 2 == 0:
				ga += int(s[i])
			else:
				gb += int(s[i])
			if i % 2 == 1:
				if ga > gb:
					print('TEAM-A', 1 + i)
					break
				elif gb > ga:
					print('TEAM-B', 1 + i)
					break
		else:
			print('TIE')


while True:
	try:
		g = input()
	except:
		break
	team_a = g[0::2]
	team_b = g[1::2]
	first_a = team_a[0:5].count('1')
	first_b = team_b[0:5].count('1')
	count = 0
	if first_a > first_b:
		a = 0
		b = 0
		for i in range(5):
			if team_a[i] == '1':
				a += 1
			if a - b > 5 - i:
				count += 1
				break
			if team_b[i] == '1':
				b += 1
			count += 2
			if a - b > 4 - i:
				break
		print('TEAM-A', count)
	elif first_b > first_a:
		a = 0
		b = 0
		for i in range(5):
			if team_a[i] == '1':
				a += 1
			if b - a > 4 - i:
				count += 1
				break
			if team_b[i] == '1':
				b += 1
			count += 2
			if b - a > 4 - i:
				break
		print('TEAM-B', count)
	else:
		count = 10
		for i in range(5):
			if team_a[5 + i] == '1' and team_b[5 + i] == '0':
				count += 2
				print('TEAM-A', count)
				break
			elif team_a[5 + i] == '0' and team_b[5 + i] == '1':
				count += 2
				print('TEAM-B', count)
				break
			else:
				count += 2
		else:
			print('TIE')


while True:
	try:
		s = input()
		(a, b) = (0, 0)
		ans = 0
		win = 'TIE'
		(c, d) = (5, 5)
		for i in range(10):
			if i % 2 == 0:
				a += int(s[i])
				c -= 1
			else:
				b += int(s[i])
				d -= 1
			if a > b + d:
				ans = i + 1
				win = 'TEAM-A'
				print(win, ans)
				break
			if b > a + c:
				ans = i + 1
				win = 'TEAM-B'
				print(win, ans)
				break
		if win == 'TIE':
			for i in range(10, 20, 2):
				a += int(s[i])
				b += int(s[i + 1])
				if a > b:
					win = 'TEAM-A'
					ans = i + 2
					print(win, ans)
					break
				elif b > a:
					win = 'TEAM-B'
					ans = i + 2
					print(win, ans)
					break
			if win == 'TIE':
				print(win)
	except:
		break


while True:
	try:
		data = input()
		(scoreA, scoreB) = (0, 0)
		(chA, chB) = (5, 5)
		cond = 0
		for i in range(10):
			if i % 2 == 0:
				scoreA += int(data[i])
				chA = chA - 1
			else:
				scoreB += int(data[i])
				chB -= 1
			if scoreA > scoreB + chB:
				cond = 1
				print('TEAM-A ' + str(i + 1))
				break
			if scoreB > scoreA + chA:
				cond = 1
				print('TEAM-B ' + str(i + 1))
				break
		if cond == 0:
			for i in range(10, 20, 2):
				scoreA += int(data[i])
				scoreB += int(data[i + 1])
				if scoreA > scoreB:
					cond = 1
					print('TEAM-A ' + str(i + 2))
					break
				elif scoreB > scoreA:
					cond = 1
					print('TEAM-B ' + str(i + 2))
					break
		if cond == 0:
			print('TIE')
	except:
		break


import sys
for line in sys.stdin:
	score = {'A': 0, 'B': 0}
	shots = {'A': 0, 'B': 0}
	current_team = 'A'
	total_shots = 0
	for ch in line:
		if ch == '1':
			score[current_team] += 1
		total_shots += 1
		shots[current_team] += 1
		current_team = 'B' if current_team == 'A' else 'A'
		if total_shots < 10:
			remaining = {'A': 5 - shots['A'], 'B': 5 - shots['B']}
			if score['A'] > score['B'] + remaining['B']:
				print('TEAM-A', total_shots)
				break
			if score['B'] > score['A'] + remaining['A']:
				print('TEAM-B', total_shots)
				break
		if total_shots == 10:
			if score['A'] > score['B']:
				print('TEAM-A', total_shots)
				break
			if score['B'] > score['A']:
				print('TEAM-B', total_shots)
				break
		if total_shots > 10 and total_shots % 2 == 0:
			if score['A'] > score['B']:
				print('TEAM-A', total_shots)
				break
			if score['B'] > score['A']:
				print('TEAM-B', total_shots)
				break
	else:
		print('TIE')


import fileinput as fp

def solve(inp):
	(a1, b1, n, m) = (0, 0, 0, 0)
	li = list(inp)
	for j in range(10):
		if j % 2 == 0:
			a1 = a1 + int(li[j])
			m = m + 1
		else:
			b1 = b1 + int(li[j])
			n = n + 1
		if a1 > b1 and 5 - n + b1 < a1:
			return 'TEAM-A ' + str(j + 1)
		elif b1 > a1 and 5 - m + a1 < b1:
			return 'TEAM-B ' + str(j + 1)
	for j in range(2, 11, 2):
		a1 = a1 + int(li[8 + j])
		b1 = b1 + int(li[9 + j])
		if a1 > b1:
			return 'TEAM-A ' + str(10 + j)
		elif b1 > a1:
			return 'TEAM-B ' + str(10 + j)
		if j == 10:
			return 'TIE'
for inp in fp.input():
	print(solve(inp))


while True:
	try:
		x = input()
		flag = 9
		a = 0
		b = 0
		A = [int(x[2 * j]) for j in range(len(x) // 2)]
		B = [int(x[2 * j + 1]) for j in range(len(x) // 2)]
		for i in range(10):
			if i <= 4:
				a = a + A[i]
				if a - b > 5 - i:
					print('TEAM-A', 2 * i + 1)
					flag = 0
					break
				elif b - a > 4 - i:
					print('TEAM-B', 2 * i + 1)
					flag = 0
					break
				b = b + B[i]
				if a - b > 4 - i:
					print('TEAM-A', 2 * i + 2)
					flag = 0
					break
				elif b - a > 4 - i:
					print('TEAM-B', 2 * i + 2)
					flag = 0
					break
			if i >= 5:
				if A[i] == 1 and B[i] == 0:
					print('TEAM-A', 2 * i + 2)
					flag = 1
					break
				elif A[i] == 0 and B[i] == 1:
					print('TEAM-B', 2 * i + 2)
					flag = 1
					break
		if flag == 9:
			print('TIE')
	except:
		break


while True:
	try:
		dataset = input()
		goalsA = 0
		goalsB = 0
		chlA = 5
		chlB = 5
		flag = 0
		for i in range(10):
			if i % 2 == 0:
				goalsA += int(dataset[i])
				chlA -= 1
			else:
				goalsB += int(dataset[i])
				chlB -= 1
			if goalsA > goalsB + chlB:
				flag = 1
				print('TEAM-A ' + str(i + 1))
				break
			elif goalsB > goalsA + chlA:
				flag = 1
				print('TEAM-B ' + str(i + 1))
				break
		if flag == 0:
			if goalsA > goalsB:
				flag = 1
				print('TEAM-A 10')
			elif goalsB > goalsA:
				flag = 1
				print('TEAM-B 10')
			else:
				for i in range(11, 20, 2):
					goalsA += int(dataset[i - 1])
					goalsB += int(dataset[i])
					if goalsA > goalsB:
						flag = 1
						print('TEAM-A ' + str(i + 1))
						break
					elif goalsB > goalsA:
						flag = 1
						print('TEAM-B ' + str(i + 1))
						break
		if flag == 0:
			print('TIE')
	except:
		break


while True:
	try:
		a = input()
	except EOFError:
		break
	chgoal = 0
	opgoal = 0
	chmiss = 0
	opmiss = 0
	numshot = 0
	flag = 0
	i = 0
	while i < 10:
		numshot += 1
		if i % 2 == 0:
			if a[i] == '1':
				chgoal += 1
			else:
				chmiss += 1
		if i % 2 != 0:
			if a[i] == '1':
				opgoal += 1
			else:
				opmiss += 1
		if chgoal + opmiss > 5:
			flag = 1
			break
		if opgoal + chmiss > 5:
			flag = 2
			break
		i += 1
	if flag != 0:
		if flag == 1:
			print('TEAM-A', numshot)
		elif flag == 2:
			print('TEAM-B', numshot)
	else:
		j = 10
		while j < 20:
			numshot += 1
			if j % 2 == 0:
				if a[j] == '1':
					chgoal += 1
			if j % 2 != 0:
				if a[j] == '1':
					opgoal += 1
			if j % 2 == 1:
				if chgoal > opgoal:
					print('TEAM-A', numshot)
					flag = 1
					break
				if opgoal > chgoal:
					print('TEAM-B', numshot)
					flag = 1
					break
			j += 1
	if flag == 0:
		print('TIE')


while 1:
	try:
		x = input()
	except EOFError:
		break
	a = 0
	b = 0
	ra = 5
	rb = 5
	for i in range(0, 10):
		if i % 2 == 0:
			a += int(x[i])
			ra -= 1
			if a - b > rb or b - a > ra:
				break
		else:
			b += int(x[i])
			rb -= 1
			if a - b > rb or b - a > ra:
				break
	if a - b > rb:
		print('TEAM-A', i + 1)
	elif b - a > ra:
		print('TEAM-B', i + 1)
	else:
		a = 0
		b = 0
		for i in range(10, 20):
			if i % 2 == 0:
				a += int(x[i])
			else:
				b += int(x[i])
				if a > b:
					print('TEAM-A', i + 1)
					break
				elif b > a:
					print('TEAM-B', i + 1)
					break
		if a == b:
			print('TIE')


x = '111'
while 1:
	try:
		x = input()
	except EOFError:
		break
	a = 0
	b = 0
	for i in range(20):
		if i % 2 == 0 and x[i] == '1':
			a += 1
		if i % 2 == 1 and x[i] == '1':
			b += 1
		if i < 10:
			if i % 2 == 0:
				if b > a + (9 - i) / 2:
					break
				if a > b + (10 - i) / 2:
					break
			if i % 2 == 1:
				if a > b + (10 - i) / 2:
					break
				if b > a + (10 - i) / 2:
					break
		if i > 10 and i % 2 == 1:
			if a > b:
				break
			if a < b:
				break
	if a > b:
		print('TEAM-A', i + 1)
	elif b > a:
		print('TEAM-B', i + 1)
	elif a == b:
		print('TIE')


import sys

def football(s):
	n = len(s)
	A = 0
	B = 0
	a = 0
	b = 0
	for i in range(1, len(s) + 1):
		if i % 2 != 0:
			a += 1
		else:
			b += 1
		if s[i - 1] == '1' and i % 2 != 0:
			A += 1
		elif s[i - 1] == '1' and i % 2 == 0:
			B += 1
		if i <= 10:
			if A - B >= 1:
				shots_leftb = 5 - b
				if shots_leftb < A - B:
					print('TEAM-A', i)
					break
			elif B - A >= 1:
				shots_lefta = 5 - a
				if shots_lefta < B - A:
					print('TEAM-B', i)
					break
		elif i % 2 == 0:
			if A > B:
				print('TEAM-A', i)
				break
			elif B > A:
				print('TEAM-B', i)
				break
	else:
		print('TIE')
ans = []
while True:
	try:
		b = input()
		football(b)
	except EOFError:
		break


while True:
	try:
		s = input()
		A = 0
		B = 0
		At = 5
		Bt = 5
		for i in range(0, 10):
			if i % 2 == 0:
				if s[i] == '1':
					A += 1
					At -= 1
				else:
					At -= 1
			elif s[i] == '1':
				B += 1
				Bt -= 1
			else:
				Bt -= 1
			if A > B + Bt:
				print('TEAM-A', i + 1)
				break
			elif B > A + At:
				print('TEAM-B', i + 1)
				break
		if A == B:
			for i in range(0, 5):
				if s[10 + 2 * i] == '1':
					A += 1
				if s[11 + 2 * i] == '1':
					B += 1
				if A > B:
					print('TEAM-A', 12 + 2 * i)
					break
				elif B > A:
					print('TEAM-B', 12 + 2 * i)
					break
		if A == B:
			print('TIE')
	except:
		break


while 101 > 100:
	try:
		inp = input()
		(count, a, b) = (4, [], [])
		for i in range(len(inp)):
			if (1 + i) % 2 == 1:
				a.append(int(inp[i]))
			else:
				b.append(int(inp[i]))
		pa = a[0] + a[1]
		pb = b[0] + b[1]
		ans = False
		for i in range(2, 5):
			if pa - pb > 5 - i:
				print('TEAM-A ' + str(count))
				ans = True
				break
			if pb - pa > 5 - i:
				print('TEAM-B ' + str(count))
				ans = True
				break
			pa = pa + a[i]
			count = count + 1
			if pb - pa > 5 - i - 1:
				print('TEAM-B ' + str(count))
				ans = True
				break
			if pa - pb > 5 - i:
				print('TEAM-A ' + str(count))
				ans = True
				break
			pb = pb + b[i]
			count = count + 1
		if ans != True:
			if pa < pb:
				print('TEAM-B ' + str(count))
				ans = True
			if pb < pa:
				print('TEAM-A ' + str(count))
				ans = True
		if ans != True:
			for i in range(5, 10):
				count = count + 2
				if a[i] > b[i]:
					print('TEAM-A ' + str(count))
					break
				if a[i] < b[i]:
					print('TEAM-B ' + str(count))
					break
			else:
				print('TIE')
	except:
		break


import sys
while True:
	try:
		s = input()
	except:
		break
	if not s:
		sys.exit()
	a = b = i = 0
	while i < 10:
		if s[i] == '1':
			a += 1
		if a - b > int((10 - i) / 2):
			print('TEAM-A ' + str(i + 1))
			i = 25
			continue
		elif b - a > int((10 - i - 1) / 2):
			print('TEAM-B ' + str(i + 1))
			i = 25
			continue
		i += 1
		if s[i] == '1':
			b += 1
		if abs(a - b) > 4 - int(i / 2):
			if a > b:
				print('TEAM-A ' + str(i + 1))
			else:
				print('TEAM-B ' + str(i + 1))
			i = 25
		i += 1
	while i < 20:
		if s[i] == '0' and s[i + 1] == '1':
			print('TEAM-B ' + str(i + 2))
			i = 25
		elif s[i + 1] == '0' and s[i] == '1':
			print('TEAM-A ' + str(i + 2))
			i = 25
		i += 2
	if i < 24:
		print('TIE')


while True:
	try:
		s = input()
		ca = 0
		b = 0
		i = 0
		while i < 10:
			ca += int(s[i])
			l = (10 - i - 1) // 2
			m = (10 - i) // 2
			if b - ca > l:
				print('TEAM-B ' + str(i + 1))
				break
			elif ca - b > m:
				print('TEAM-A ' + str(i + 1))
				break
			b += int(s[i + 1])
			if ca - b > l:
				print('TEAM-A ' + str(i + 2))
				break
			elif b - ca > l:
				print('TEAM-B ' + str(i + 2))
				break
			i += 2
		if ca == b:
			while i < 20:
				ca += int(s[i])
				b += int(s[i + 1])
				i += 2
				if ca > b:
					print('TEAM-A ' + str(i))
					break
				elif ca < b:
					print('TEAM-B ' + str(i))
					break
				elif i == 20:
					print('TIE')
					break
	except EOFError:
		break


a = []
out = []
from sys import stdin
for line in stdin:
	a.append(line)
for i in range(len(a)):
	TA = []
	TB = []
	for j in range(10):
		TA.append(a[i][2 * j])
		TB.append(a[i][2 * j + 1])
	wa = 0
	wb = 0
	c = 0
	win = ''
	for j in range(5):
		if TA[j] == '1':
			wa += 1
		c += 1
		if wa != wb:
			if wa > wb + 4 - j + 1:
				win = 'A'
				break
			elif wa + 4 - j < wb:
				win = 'B'
				break
		if TB[j] == '1':
			wb += 1
		c += 1
		if wa != wb:
			if wa > wb + 4 - j:
				win = 'A'
				break
			elif wa + 4 - j < wb:
				win = 'B'
				break
	if bool(win):
		result = 'TEAM-' + win + ' ' + str(c)
		out.append(result)
	elif wa == wb:
		j = 5
		while j < 10:
			if TA[j] == '1':
				wa += 1
			if TB[j] == '1':
				wb += 1
			c += 2
			if wa > wb:
				win = 'A'
				break
			elif wa < wb:
				win = 'B'
				break
			j += 1
		if bool(win):
			result = 'TEAM-' + win + ' ' + str(c)
			out.append(result)
		elif wa == wb:
			out.append('TIE')
for i in range(len(a)):
	print(out[i])


while True:
	try:
		s = input()
		f = True
		(a, b) = (0, 0)
		for (i, x) in enumerate(s[:10]):
			a = a + 1 if x is '1' and i % 2 == 0 else a
			b = b + 1 if x is '1' and i % 2 == 1 else b
			if a - b > (10 - (i + 1)) // 2 + 1:
				print('TEAM-A', i + 1)
				f = False
				break
			if b - a > (10 - (i + 1)) // 2:
				print('TEAM-B', i + 1)
				f = False
				break
			if i == 5 or i == 7 or i == 9:
				if (10 - (i + 1)) // 2 < a - b:
					print('TEAM-A', i + 1)
					f = False
					break
		if f:
			for i in range(10, 20, 2):
				a = a + 1 if s[i] == '1' else a
				b = b + 1 if s[i + 1] == '1' else b
				if a > b:
					print('TEAM-A', i + 2)
					f = False
					break
				if a < b:
					print('TEAM-B', i + 2)
					f = False
					break
		if f:
			print('TIE')
	except EOFError:
		break


def function(line) -> None:
	teamA = 0
	teamB = 0
	shot_a = 5
	shot_b = 5
	tie = True
	for i in range(20):
		if i % 2 == 0:
			shot_a -= 1
			if line[i] == '1':
				teamA = teamA + 1
		else:
			shot_b -= 1
			if line[i] == '1':
				teamB = teamB + 1
		if i < 10:
			if teamA == teamB:
				continue
			elif teamB < teamA:
				if shot_b < teamA - teamB:
					print('TEAM-A', i + 1)
					tie = False
					break
			elif shot_a < teamB - teamA:
				print('TEAM-B', i + 1)
				tie = False
				break
		elif (i + 1) % 2 == 0:
			if abs(teamB - teamA) != 0:
				if teamB < teamA:
					print('TEAM-A', i + 1)
					tie = False
					break
				else:
					print('TEAM-B', i + 1)
					tie = False
					break
	if tie:
		print('TIE')
data = []
inp = input()
while inp:
	try:
		data.append(inp)
		inp = input()
	except:
		break
for i in data:
	function(i)


try:
	while True:
		s = input()
		if s == '':
			break
		(a, b) = (0, 0)
		(az, bz) = (0, 0)
		(i, c) = (0, 0)
		while i < 10 and c == 0:
			if i % 2 == 0:
				if s[i] == '1':
					a += 1
				else:
					az += 1
			if i % 2 == 1:
				if s[i] == '1':
					b += 1
				else:
					bz += 1
			if bz > 5 - a:
				print('TEAM-A ', i + 1)
				c = 1
			elif az > 5 - b:
				print('TEAM-B ', i + 1)
				c = 1
			i += 1
		if c == 0 and a == b:
			i = 10
			while i < 20 and c == 0:
				if i % 2 == 0:
					if s[i] == '1':
						a += 1
				if i % 2 == 1:
					if s[i] == '1':
						b += 1
					if a > b:
						print('TEAM-A ', i + 1)
						c = 1
					elif b > a:
						print('TEAM-B ', i + 1)
						c = 1
				i += 1
		if c == 0 and i == 20 and (a == b):
			print('TIE')
except EOFError:
	pass


import sys

def Checkon(S):
	count1 = 0
	count2 = 0
	for i in range(len(S)):
		if i % 2 == 0 and S[i] == '1':
			count1 += 1
		elif i % 2 == 1 and S[i] == '1':
			count2 += 1
	if count1 == count2:
		return 'TIE'
	elif count1 > count2:
		return 1
	else:
		return 0
for S in sys.stdin:
	if Checkon(S[:10]) == 'TIE':
		sum1 = 0
		sum2 = 0
		j = 0
		while sum1 == sum2 and j < 8:
			if S[10 + j] == '1':
				sum1 += 1
			if S[10 + j + 1] == '1':
				sum2 += 1
			j += 2
		else:
			if sum1 > sum2:
				print('TEAM-A', 10 + j)
			elif sum2 > sum1:
				print('TEAM-B', 10 + j)
			elif j >= 8:
				if S[18] == '1' and S[19] == '0':
					print('TEAM-A', 20)
				elif S[18] == '0' and S[19] == '1':
					print('TEAM-B', 20)
				else:
					print('TIE')
	else:
		s1 = 0
		s2 = 0
		i = 0
		t1 = 0
		t2 = 0
		while s1 <= 5 + s2 - t2 and s2 <= 5 + s1 - t1:
			if i % 2 == 0:
				if S[i] == '1':
					s1 += 1
				i += 1
				t1 += 1
			elif i % 2 == 1:
				if S[i] == '1':
					s2 += 1
				i += 1
				t2 += 1
		else:
			if s1 > 5 + s2 - t2:
				print('TEAM-A', i)
			elif s2 > 5 + s1 - t1:
				print('TEAM-B', i)


import sys
import math
l = sys.stdin.read()
x = 0
k = 0
ta = 0
t = 0
n = math.ceil(len(l) / 21)
for i in range(0, n):
	d = 21 * i
	x = 0
	p = 0
	p1 = 0
	p2 = 0
	ta = 0
	t = 0
	k = 0
	for j in range(d, d + 10):
		p += 1
		if j % 2 == 0:
			ta += int(l[j])
			p1 += 1
		else:
			t += int(l[j])
			p2 += 1
		if ta > t:
			if 5 - p2 + t < ta:
				if i % 2 == 0:
					print('TEAM-A', p, end='')
				else:
					print('TEAM-B', p, end='')
				x = 1
				k = 1
				break
		elif t > ta:
			if 5 - p1 + ta < t:
				if i % 2 == 0:
					print('TEAM-B', p, end='')
				else:
					print('TEAM-A', p, end='')
				k = 1
				x = 1
				break
	if x == 0:
		if ta > t:
			print('TEAM-A', p, end='')
			k = 1
		elif t > ta:
			print('TEAM-B', p, end='')
			k = 1
		else:
			p = 10
			for j in range(d + 10, d + 20):
				p += 1
				if j % 2 == 0:
					ta += int(l[j])
				else:
					t += int(l[j])
				if i % 2 == 0:
					if j % 2 != 0:
						if ta > t:
							print('TEAM-A', p, end='')
							k = 1
							break
						elif t > ta:
							print('TEAM-B', p, end='')
							k = 1
							break
				elif j % 2 == 0:
					if ta > t:
						print('TEAM-B', p, end='')
						k = 1
						break
					elif t > ta:
						print('TEAM-A', p, end='')
						k = 1
						break
	if k == 0:
		print('TIE', end='')
	if not i == n - 1:
		print()


while True:
	try:
		n = tuple(map(int, input()))
		x = 0
		if sum(n[0:10:2]) == sum(n[1:10:2]):
			for i in range(10, 20, 2):
				if n[i] > n[i + 1]:
					print('TEAM-A', i + 2)
					break
				elif n[i] < n[i + 1]:
					print('TEAM-B', i + 2)
					break
				elif i == 18:
					print('TIE')
		else:
			for i in range(10):
				if n[i] == 1 and i % 2 == 0:
					x += 1
				elif n[i] == 1 and i % 2 == 1:
					x -= 1
				if x < 0:
					if x + (9 - i) // 2 < 0:
						print('TEAM-B', i + 1)
						break
				elif x > 0:
					if x - ((9 - i) // 2 + 1 - i % 2) > 0:
						print('TEAM-A', i + 1)
						break
	except:
		break


import re
lines = []
while True:
	try:
		ip = input()
		if re.search('[^0-1]', ip):
			raise ValueError
		else:
			line = [int(x) for x in ip]
	except EOFError:
		break
	except ValueError:
		print('You can only provide a string of 0s and 1s')
		break
	lines.append(line)

def analyzeResult(l):
	score_A = 0
	score_B = 0
	for i in range(6, 21):
		score_A = sum(l[:i:2])
		score_B = sum(l[1:i:2])
		if i == 6 and abs(score_A - score_B) > 2:
			break
		elif i == 7 and (score_B + 2 < score_A or score_A + 1 < score_B):
			break
		elif i == 8 and (score_A + 1 < score_B or score_B + 1 < score_A):
			break
		elif i == 9 and (score_B > score_A or score_B + 1 < score_A):
			break
		elif i == 10 and score_B != score_A:
			break
		elif i > 10 and i % 2 == 0 and (score_B != score_A):
			break
		else:
			continue
	if score_A > score_B:
		return ['TEAM-A', i]
	elif score_B > score_A:
		return ['TEAM-B', i]
	else:
		return ['TIE']
for line in lines:
	result = analyzeResult(line)
	if result[0] == 'TIE':
		print('TIE')
	else:
		print(result[0] + ' ' + str(result[1]))


from sys import stdin
lines = stdin.readlines()
for line in lines:
	c = 0
	l = len(line)
	one = line.count('1')
	f = 0
	if one == l or one == 0:
		print('TIE')
		f = 1
	else:
		one = ze = c = 0
		for i in range(10):
			if line[i] == '1' and i % 2 == 0:
				one += 1
			elif line[i] == '1' and i % 2 != 0:
				ze += 1
			else:
				c += 1
		if one == ze:
			for i in range(10, 20):
				if line[i] == '1' and i % 2 == 0:
					one += 1
				elif line[i] == '1' and i % 2 != 0:
					ze += 1
				else:
					c += 1
				if one > ze and i % 2 != 0:
					print('TEAM-A', i + 1)
					f = 1
					break
				if ze > one and i % 2 != 0:
					print('TEAM-B', i + 1)
					f = 1
					break
			if f == 0:
				print('TIE')
		else:
			one = ze = c = 0
			for i in range(10):
				if line[i] == '1' and i % 2 == 0:
					one += 1
				elif line[i] == '1' and i % 2 != 0:
					ze += 1
				else:
					c += 1
				if i % 2 == 0:
					if ze > one + (4 - int(i / 2)):
						print('TEAM-B', i + 1)
						f = 1
						break
					elif one > ze + (5 - int(i / 2)):
						print('TEAM-A', i + 1)
						f = 1
						break
					else:
						c += 1
				elif one > ze + (4 - int(i / 2)):
					print('TEAM-A', i + 1)
					f = 1
					break
				elif ze > one + (4 - int(i / 2)):
					print('TEAM-B', i + 1)
					f = 1
					break
			if f == 0:
				print('TIE')