A = list(map(int,input().split()))
B = list(map(int,input().split()))
n = 0
while A != [] or B != [] or n < 10**6:
if A[0] == 0 and B[0] == 9:
A.append(B[0])
B.pop(0)
elif B[0] == 0 and A[0] == 9:
B.append(A[0])
A.pop(0)
elif A[0] < B[0]:
A.append(B[0])
B.pop(0)
else:
B.append(A[0])
A.pop(0)
n += 1
if n == 10**6:
print('botva')
elif A == []:
print('second', n)
else:
print('first', n)