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

Winter has finally come to Chefland, so Chef bought a glove for herself. Chef has a hand with N fingers (for the sake of simplicity, let us consider the thumb a finger too) numbered 1 through N and the glove has N sheaths numbered 1 through N. Exactly one finger has to be inserted into each sheath. You are given the lengths of Chef's fingers, as seen from left to right. You are also given the lengths of the sheaths of the glove, from left to right, as seen from the front.

Chef can wear the glove normally (the front side of the glove matching the front of Chef's hand), or she can flip the glove and then insert her hand in it. In the first case, the first finger will go into the first sheath, the second finger into the second one, and so on. However, when she flips the glove, her first finger will go into the N-th sheath, the second finger into the (N-1)-th and so on — the i-th finger will go into the N+1-i-th sheath for each valid i. Of course, for her to wear the glove comfortably, each finger's length should be less than or equal to the length of the sheath it goes into.

Find out whether Chef can wear the glove by keeping its front side facing her, or if she can wear it by flipping it over and facing its back side. If she can only wear the glove in the former way, output "front"; if she can wear it only in the latter way, output "back". If both front and back orientations can be used, output "both", and if she can't wear it either way, output "none".

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

The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains a single integer N denoting the number of Chef's fingers.
The second line contains N space-separated integers L_{1}, L_{2}, ..., L_{N} denoting the lengths of Chef's fingers.
The third line contains N space-separated integers G_{1}, G_{2}, ..., G_{N}, denoting the lengths of sheaths of the glove.

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

For each test case, print a single line containing one of the strings "front", "back", "both", or "none".

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

$1 ≤ T ≤ 10$
$1 ≤ N ≤ 10^{5}$
$1 ≤ L_{i} ≤ 10^{9} for each valid i$
$1 ≤ G_{i} ≤ 10^{9} for each valid i$

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

Subtask #1 (30 points): 1 ≤ N ≤ 10^{2}

Subtask #2 (70 points): original constraints

----- Sample Input 1 ------ 
4
3
1 2 3
2 3 4
3
1 2 1
1 2 1
3
3 2 1
1 2 3
4
1 3 2 4
1 2 3 5
----- Sample Output 1 ------ 
front
both
back
none
----- explanation 1 ------ 
Example case 1: The glove can be worn normally, with its front side facing Chef. The lengths of the glove sheaths are 2, 3, 4. The lengths of the fingers are 1, 2, 3. Each of the fingers will fit in the corresponding glove sheath, that is, 1 ? 2, 2 ? 3 and 3 ? 4.

However, if Chef tries to wear the glove with its back facing her, then the lengths of the sheaths will be 4, 3, 2. The first two fingers, which have lengths 1 and 2, will fit into the corresponding sheaths, but the 3rd finger won't fit because its length is 3, and the length of the corresponding sheath is 2. Hence, this glove can be worn only in one way, and we output "front".

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
for i in range(int(input())):
	N = int(input())
	L = list(map(int, input().split(' ')))
	G = list(map(int, input().split(' ')))
	a = 0
	for j in range(N):
		if L[j] <= G[j]:
			a += 1
	b = 0
	for j in range(N):
		if L[j] <= G[N - 1 - j]:
			b += 1
	if a == N and b == N:
		print('both')
	elif a == N and b != N:
		print('front')
	elif b == N and a != N:
		print('back')
	else:
		print('none')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = Counter({i: x for (i, x) in enumerate(list(map(int, input().split())))})
	glist = list(map(int, input().split()))
	g = Counter({i: x for (i, x) in enumerate(glist)})
	gr = Counter({i: x for (i, x) in enumerate(reversed(glist))})
	g.subtract(l)
	gr.subtract(l)
	(f, fl) = g.most_common()[:-2:-1][0]
	(b, bl) = gr.most_common()[:-2:-1][0]
	print('front' if fl >= 0 and bl < 0 else 'back' if bl >= 0 and fl < 0 else 'both' if bl >= 0 and fl >= 0 else 'none')


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	i = n - 1
	j = 0
	f = 0
	f1 = 0
	while i >= 0:
		if l[i] > g[i] and f == 0:
			f = 1
		if l[i] > g[j] and f1 == 0:
			f1 = 1
		j += 1
		i -= 1
	if f == 0 and f1 == 0:
		print('both')
	elif f == 0:
		print('front')
	elif f1 == 0:
		print('back')
	else:
		print('none')
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	f = list(map(int, input().split()))
	g = list(map(int, input().split()))
	fr = 0
	ba = 0
	for j in range(0, n):
		if f[j] <= g[j]:
			fr = fr + 1
		if f[j] <= g[n - 1 - j]:
			ba = ba + 1
	if fr == n and ba == n:
		print('both')
	elif ba == n:
		print('back')
	elif fr == n:
		print('front')
	else:
		print('none')


for i in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	G = list(map(int, input().split()))
	c = 0
	d = 0
	for j in range(N):
		if L[j] <= G[j]:
			c = 1
		else:
			c = 0
			break
	for j in range(N):
		if L[j] <= G[-(j + 1)]:
			d = 1
		else:
			d = 0
			break
	if c == 1 and d == 1:
		print('both')
	elif c == 1:
		print('front')
	elif d == 1:
		print('back')
	else:
		print('none')


s = int(input())
for i in range(s):
	a = int(input())
	n = list(map(int, input().split(' ')))
	m = list(map(int, input().split(' ')))
	count_front = 0
	count_back = 0
	for j in range(a):
		if n[j] <= m[j]:
			count_front += 1
		if n[j] <= m[a - j - 1]:
			count_back += 1
	if count_front == a and count_back == a:
		print('both')
	elif count_front == a:
		print('front')
	elif count_back == a:
		print('back')
	else:
		print('none')


for i in range(int(input())):
	N = int(input())
	fingers = list(map(int, input().split()))
	gloves = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	for j in range(N):
		if fingers[j] <= gloves[j]:
			count1 += 1
		else:
			break
	gloves.reverse()
	for j in range(N):
		if fingers[j] <= gloves[j]:
			count2 += 1
		else:
			break
	if count1 + count2 == 2 * N:
		print('both')
	elif count1 == N:
		print('front')
	elif count2 == N:
		print('back')
	else:
		print('none')


for i in range(int(input())):
	n = int(input())
	h = list(map(int, input().split()))
	g = list(map(int, input().split()))
	fr = 0
	ba = 0
	k = g[::-1]
	for i in range(0, n):
		if h[i] <= g[i]:
			fr = 1
		else:
			fr = 0
			break
	for j in range(0, n):
		if h[j] <= k[j]:
			ba = 1
		else:
			ba = 0
			break
	if ba == 1 and fr == 1:
		print('both')
		continue
	if ba == 1 and fr != 1:
		print('back')
		continue
	if ba != 1 and fr == 1:
		print('front')
		continue
	else:
		print('none')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	f = 0
	b = 0
	for i in range(n):
		if l[i] <= g[i]:
			f = 1
		else:
			f = 0
			break
	for i in range(n):
		if l[i] <= g[n - i - 1]:
			b = 1
		else:
			b = 0
			break
	if f == 1 and b == 1:
		print('both')
	elif f == 1 and b == 0:
		print('front')
	elif f == 0 and b == 1:
		print('back')
	elif f == 0 and b == 0:
		print('none')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	for i in range(n):
		if l[i] <= g[i]:
			c1 += 1
		if l[i] <= g[n - i - 1]:
			c2 += 1
	if c1 == n and c2 == n:
		print('both')
	elif c2 == n:
		print('back')
	elif c1 == n:
		print('front')
	elif c1 != n and c2 != n:
		print('none')


for i in range(int(input())):
	n = int(input())
	h = list(map(int, input().split()))
	g = list(map(int, input().split()))
	c = 0
	d = 0
	for i in range(n):
		if h[i] <= g[i]:
			c = c + 1
	for i in range(n):
		if h[i] <= g[n - i - 1]:
			d = d + 1
	if c == n and d == n:
		print('both')
	elif c != n and d != n:
		print('none')
	elif c == n and d != n:
		print('front')
	elif c != n and d == n:
		print('back')


for i in range(int(input())):
	noOfFing = int(input())
	leOfFing = list(map(int, input().split()))
	leOfSheath = list(map(int, input().split()))
	flagF = 1
	flagB = 1
	for i in range(noOfFing):
		if leOfFing[i] > leOfSheath[i]:
			flagF = 0
		if leOfFing[i] > leOfSheath[noOfFing - 1 - i]:
			flagB = 0
	if flagF == 1 and flagB == 1:
		print('both')
	elif flagF == 1:
		print('front')
	elif flagB == 1:
		print('back')
	else:
		print('none')


for t in range(int(input())):
	n = int(input())
	lf = list(map(int, input().split()))
	lg = list(map(int, input().split()))
	f1 = True
	f2 = True
	for i in range(n):
		if lf[i] > lg[i]:
			f1 = False
		if lf[i] > lg[n - 1 - i]:
			f2 = False
		if f1 or f2:
			continue
			break
	if f1 and f2:
		print('both')
	elif f1:
		print('front')
	elif f2:
		print('back')
	else:
		print('none')


def calculate(f, s, a):
	for i in range(n):
		d = s[i] - f[i]
		if d >= 0:
			a.append(d)
		else:
			pass
	return a
for _ in range(int(input())):
	n = int(input())
	f = list(map(int, input().split()))
	s = list(map(int, input().split()))
	flag = 0
	a = []
	calculate(f, s, a)
	if len(a) == n:
		s.reverse()
		b = []
		calculate(f, s, b)
		if len(b) == n:
			print('both')
		else:
			print('front')
	else:
		s.reverse()
		c = []
		calculate(f, s, c)
		if len(c) == n:
			print('back')
		else:
			print('none')


for i in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	f = False
	k = False
	h = 0
	e = 0
	for i in range(n):
		if b[i] <= c[i]:
			h += 1
	if h == n:
		f = True
	c.reverse()
	for i in range(n):
		if b[i] <= c[i]:
			e += 1
	if e == n:
		k = True
	if f and k:
		print('both')
	elif f and (not k):
		print('front')
	elif not f and k:
		print('back')
	else:
		print('none')


t = int(input())
for _ in range(t):
	n = int(input())
	fingers = list(map(int, input().split()))
	sheaths = list(map(int, input().split()))
	ans_direct = True
	ans_flip = True
	for i in range(n):
		if fingers[i] > sheaths[i]:
			ans_direct = False
		if fingers[i] > sheaths[n - i - 1]:
			ans_flip = False
	if ans_direct and ans_flip:
		print('both')
	elif ans_flip:
		print('back')
	elif ans_direct:
		print('front')
	else:
		print('none')


for _ in range(int(input())):
	n = int(input())
	F = list(map(int, input().split()))
	G = list(map(int, input().split()))
	(f, b) = (1, 1)
	for i in range(n):
		if not F[i] <= G[i]:
			f = 0
			break
	for i in range(n):
		if not F[i] <= G[n - i - 1]:
			b = 0
			break
	if f == 0 and b == 0:
		print('none')
	elif f == 1 and b == 0:
		print('front')
	elif f == 0 and b == 1:
		print('back')
	else:
		print('both')


for t in range(int(input())):
	n_fing = int(input())
	fing_len = list(map(int, input().split()))
	sh_len = list(map(int, input().split()))
	fing_len_rev = fing_len[::-1]
	count1 = 0
	count2 = 0
	for i in range(n_fing):
		if fing_len[i] <= sh_len[i]:
			count1 += 1
		if fing_len_rev[i] <= sh_len[i]:
			count2 += 1
	if count1 == n_fing and count2 != n_fing:
		print('front')
	if count2 == n_fing and count1 != n_fing:
		print('back')
	if count1 == n_fing and count2 == n_fing:
		print('both')
	if count1 != n_fing and count2 != n_fing:
		print('none')


t = int(input())
while t:
	t = t - 1
	n = int(input())
	n1 = list(map(int, input().split()))
	n2 = list(map(int, input().split()))
	r = n2[::-1]
	a = 1
	b = 1
	for j in range(n):
		if n1[j] > n2[j]:
			a = 0
	for j in range(n):
		if n1[j] > r[j]:
			b = 0
	if a == 0 and b == 0:
		print('none')
	elif a == 0 and b == 1:
		print('back')
	elif a == 1 and b == 0:
		print('front')
	elif a == 1 and b == 1:
		print('both')


t = int(input())
for tc in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	c = g[::-1]
	(a, b) = (1, 1)
	for j in range(n):
		if l[j] > g[j]:
			a = 0
			break
	for k in range(n):
		if l[k] > c[k]:
			b = 0
			break
	if a == 1 and b == 1:
		print('both')
	elif b == 1:
		print('back')
	elif a == 1:
		print('front')
	else:
		print('none')


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	x = 0
	for i in range(a):
		if b[i] <= c[i]:
			x = x + 1
	b = [b[i] for i in range(len(b) - 1, -1, -1)]
	y = 0
	for i in range(a):
		if b[i] <= c[i]:
			y = y + 1
	if x == y == a:
		print('both')
	elif x == a:
		print('front')
	elif y == a:
		print('back')
	else:
		print('none')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	r = list(map(int, input().split()))
	o = r[::-1]
	(a, b) = (1, 1)
	for i in range(n):
		if l[i] > r[i]:
			a = 0
			break
	for j in range(n):
		if l[j] > o[j]:
			b = 0
			break
	if a == 1 and b == 1:
		print('both')
	elif b == 1:
		print('back')
	elif a == 1:
		print('front')
	else:
		print('none')


for _ in range(int(input())):
	fingers = int(input())
	fingerlist = [int(x) for x in input().split()]
	glovelist = [int(y) for y in input().split()]
	back = 1
	front = 1
	for i in range(fingers):
		if fingerlist[i] > glovelist[i]:
			front = 0
			break
	for i in range(fingers):
		if fingerlist[i] > glovelist[fingers - 1 - i]:
			back = 0
			break
	if front == 1 and back == 1:
		print('both')
	elif front == 1:
		print('front')
	elif back == 1:
		print('back')
	else:
		print('none')


def glove(n, l, g):
	front = all((l[i] <= g[i] for i in range(n)))
	back = all((l[i] <= g[n - i - 1] for i in range(n)))
	if front and back:
		return 'both'
	elif front:
		return 'front'
	elif back:
		return 'back'
	else:
		return 'none'
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	l = list(map(int, input().strip().split()))
	g = list(map(int, input().strip().split()))
	print(glove(n, l, g))


for t in range(int(input())):
	n = int(input())
	finger = [int(x) for x in input().split()]
	sheaths = [int(x) for x in input().split()]
	Front = True
	Back = True
	for i in range(n):
		if finger[i] > sheaths[i]:
			Front = False
		if finger[i] > sheaths[n - i - 1]:
			Back = False
		if Front == False and Back == False:
			break
	if Front and Back:
		print('both')
	elif Front:
		print('front')
	elif Back:
		print('back')
	else:
		print('none')


for _ in range(int(input())):
	n = int(input())
	f = list(map(int, input().split()))
	g = list(map(int, input().split()))
	fd = f[::-1]
	s = True
	b = True
	for x in range(n):
		if not s and (not b):
			break
		if g[x] - f[x] < 0 and s:
			s = False
		if g[x] - fd[x] < 0 and b:
			b = False
	if s and b:
		print('both')
	elif s:
		print('front')
	elif b:
		print('back')
	else:
		print('none')


T = int(input())
while T > 0:
	N = int(input())
	L = list(map(int, input().split()))
	G = list(map(int, input().split()))
	rev_L = L[::-1]
	front = True
	back = True
	for i in range(N):
		if L[i] > G[i]:
			front = False
			break
	for x in range(N):
		if rev_L[x] > G[x]:
			back = False
			break
	if front == True and back == True:
		print('both')
	elif front == True and back == False:
		print('front')
	elif front == False and back == True:
		print('back')
	else:
		print('none')
	T -= 1


cases = int(input())

def gloveFit(fn, gl):
	j = 0
	fit = 'yes'
	while j < len(fn):
		if fn[j] > gl[j]:
			fit = 'no'
			break
		else:
			j += 1
	return fit
for i in range(cases):
	fingers = int(input())
	fingerLengths = list(map(int, input().split()))
	gloveLengths = list(map(int, input().split()))
	revGloveLengths = list(reversed(gloveLengths))
	if fingers == len(gloveLengths):
		if gloveFit(fingerLengths, gloveLengths) == 'yes' and gloveFit(fingerLengths, revGloveLengths) == 'yes':
			print('both')
		elif gloveFit(fingerLengths, gloveLengths) == 'yes':
			print('front')
		elif gloveFit(fingerLengths, revGloveLengths) == 'yes':
			print('back')
		else:
			print('none')
	else:
		print('none')


for i in range(0, int(input())):
	n = int(input())
	list_size = list(map(int, input().split()))
	list_glove = list(map(int, input().split()))
	flag = 0
	flag1 = 0
	for j in range(0, n):
		if list_size[j] > list_glove[j]:
			flag = 0
			break
		else:
			flag = 1
	list_glove.reverse()
	for j in range(0, n):
		if list_size[j] > list_glove[j]:
			flag1 = 0
			break
		else:
			flag1 = 1
	if flag == 1 and flag1 == 1:
		print('both')
	elif flag == 1 and flag1 == 0:
		print('front')
	elif flag1 == 1 and flag == 0:
		print('back')
	else:
		print('none')


T = int(input())
for _ in range(T):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	front = back = True
	for i in range(n):
		if l[i] > g[i]:
			front = False
			break
	for i in range(n):
		if l[i] > g[n - i - 1]:
			back = False
			break
	if front and back:
		print('both')
	elif back:
		print('back')
	elif front:
		print('front')
	else:
		print('none')


for _ in range(int(input())):
	(N, L, G) = (int(input()), list(map(int, input().split())), list(map(int, input().split())))
	flag_front = flag_back = True
	for i in range(N):
		flag_front = flag_front and G[i] >= L[i]
		flag_back = flag_back and G[i] >= L[N - i - 1]
	if flag_front and flag_back:
		print('both')
	elif flag_front:
		print('front')
	elif flag_back:
		print('back')
	else:
		print('none')


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(fr, bc) = (0, 0)
	for i in range(n):
		if a[i] <= b[i]:
			fr += 1
		if a[i] <= b[n - i - 1]:
			bc += 1
	if fr == bc and fr == n:
		print('both')
	elif fr == n:
		print('front')
	elif bc == n:
		print('back')
	else:
		print('none')


for _ in range(int(input())):
	N = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	(f, b, both) = (0, 0, 0)
	for i in range(N):
		if l[i] <= g[i]:
			f += 1
			pass
		if l[i] <= g[N - 1 - i]:
			b += 1
			pass
	if f == N and b == N:
		print('both')
	elif f == N:
		print('front')
	elif b == N:
		print('back')
	else:
		print('none')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	f = 0
	for i in range(n):
		if a[i] > b[i]:
			break
		else:
			d += 1
	if d == n:
		f = 1
	d = 0
	b = b[::-1]
	for k in range(n):
		if a[k] > b[k]:
			break
		else:
			d += 1
	if d == n:
		f += 2
	if f == 3:
		print('both')
	elif f == 2:
		print('back')
	elif f == 1:
		print('front')
	else:
		print('none')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	c = 0
	f = 0
	for j in range(n):
		if l[j] > g[j]:
			break
		else:
			c += 1
	if c == n:
		f = 7
	c = 0
	g = g[::-1]
	for j in range(n):
		if l[j] > g[j]:
			break
		else:
			c += 1
	if c == n:
		f += 8
	if f == 15:
		print('both')
	elif f == 8:
		print('back')
	elif f == 7:
		print('front')
	else:
		print('none')


def chef_glove():
	global front, back
	front = True
	back = True
	for i in range(n):
		if l[i] > g[i]:
			front = False
		if l[i] > g[n - i - 1]:
			back = False
	if front and back:
		return 'both'
	elif back:
		return 'back'
	elif front:
		return 'front'
	else:
		return 'none'
for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	g = [int(y) for y in input().split()]
	print(chef_glove())


def seedha(f, g):
	for i in range(len(f)):
		if f[i] > g[i]:
			return False
	return True

def ulta(f, g):
	g = list(reversed(g))
	for i in range(len(f)):
		if f[i] > g[i]:
			return False
	return True
for t in range(int(input())):
	n = int(input())
	f = [int(x) for x in input().split()]
	g = [int(y) for y in input().split()]
	if seedha(f, g) and ulta(f, g):
		print('both')
	elif seedha(f, g) and (not ulta(f, g)):
		print('front')
	elif ulta(f, g) and (not seedha(f, g)):
		print('back')
	else:
		print('none')


for _ in range(int(input())):
	n = int(input())
	listf = list(map(int, input().split()))
	listg = list(map(int, input().split()))
	list1 = listg[::-1]
	for i in range(n):
		if listf[i] <= listg[i]:
			c1 = 1
		else:
			c1 = 0
			break
	for i in range(n):
		if listf[i] <= list1[i]:
			c2 = 1
		else:
			c2 = 0
			break
	if c1 == 1 and c2 == 1:
		print('both')
	elif c1 == 0 and c2 == 1:
		print('back')
	elif c1 == 1 and c2 == 0:
		print('front')
	else:
		print('none')


t = int(input())
while t:
	t -= 1
	n = int(input())
	f = list(map(int, input().split()))
	s = list(map(int, input().split()))
	fro = 1
	back = 1
	for i in range(n):
		if f[i] > s[i]:
			fro = 0
		if f[n - i - 1] > s[i]:
			back = 0
	if fro == 1 and back == 1:
		print('both')
	elif fro == 1 and back == 0:
		print('front')
	elif fro == 0 and back == 1:
		print('back')
	else:
		print('none')


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = l1[::-1]
	(front, back) = (0, 0)
	for (x, y) in zip(l1, l2):
		if x > y:
			front = 1
	for (x, y) in zip(l3, l2):
		if x > y:
			back = 1
	if front == 0 and back == 0:
		print('both')
	elif front == 0 and back == 1:
		print('front')
	elif front == 1 and back == 0:
		print('back')
	else:
		print('none')


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	c1 = 1
	c2 = 1
	for i in range(N):
		if A[i] > B[i]:
			c1 = 0
		if A[N - i - 1] > B[i]:
			c2 = 0
	if c1 == 1 and c2 == 1:
		print('both')
	elif c1 == 1 and c2 == 0:
		print('front')
	elif c1 == 0 and c2 == 1:
		print('back')
	else:
		print('none')


T = int(input())
for _ in range(T):
	n = int(input())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	front = True
	back = True
	for i in range(n):
		if l1[i] > l2[i]:
			front = False
	for j in range(n):
		if l1[j] > l2[n - j - 1]:
			back = False
	if front == True and back == True:
		print('both')
	elif front == True:
		print('front')
	elif back == True:
		print('back')
	else:
		print('none')


def sol():
	ans = ''
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	rv = True
	fr = True
	for i in range(n):
		if g[i] < l[i]:
			fr = False
		if g[i] < l[n - i - 1]:
			rv = False
	if rv and fr:
		return 'both'
	if rv:
		return 'back'
	if fr:
		return 'front'
	return 'none'
for _ in range(int(input())):
	print(sol())


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	flag_1 = 0
	flag_2 = 0
	for i in range(n):
		flag_1 += l[i] <= g[i]
		flag_2 += l[i] <= g[-(i + 1)]
	if flag_1 == n and flag_2 == n:
		print('both')
	elif flag_1 == n and flag_2 != n:
		print('front')
	elif flag_2 == n and flag_1 != n:
		print('back')
	elif flag_1 != n and flag_2 != n:
		print('none')


for _ in range(int(input())):
	n = int(input())
	fl = list(map(int, input().split(' ')))
	sl = list(map(int, input().split(' ')))
	front = True
	back = True
	for g in range(n):
		if fl[g] > sl[g]:
			front = False
			break
	for j in range(n):
		if fl[j] > sl[n - j - 1]:
			back = False
			break
	if front == True and back == True:
		print('both')
	elif back == True:
		print('back')
	elif front == True:
		print('front')
	else:
		print('none')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	fr = 0
	bc = 0
	c = []
	d = []
	for m in range(n):
		k = b[m] - a[m]
		c.append(k)
	b.reverse()
	for mm in range(n):
		kk = b[mm] - a[mm]
		d.append(kk)
	for l in c:
		if l < 0:
			fr = 1
	for ll in d:
		if ll < 0:
			bc = 1
	if fr == 0 and bc == 0:
		print('both')
	elif fr == 0:
		print('front')
	elif bc == 0:
		print('back')
	else:
		print('none')


for _ in range(int(input())):
	N = int(input())
	fingers = list(map(int, input().split()))
	gloves = list(map(int, input().split()))
	(F, B) = (True, True)
	for i in range(N):
		if F:
			if fingers[i] > gloves[i]:
				F = False
		if B:
			if fingers[i] > gloves[N - i - 1]:
				B = False
	if F and B:
		print('both')
	elif F:
		print('front')
	elif B:
		print('back')
	else:
		print('none')


for j in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	(d, e, f) = (0, 0, 0)
	for i in range(n):
		if a[i] > b[i]:
			d = 1
	if d == 0:
		e = 1
	d = 0
	b = b[::-1]
	for i in range(n):
		if a[i] > b[i]:
			d = 1
			break
	if d == 0:
		f += 1
	if e + f > 0:
		if f == 1 and e == 1:
			print('both')
		elif f == 1:
			print('back')
		else:
			print('front')
	else:
		print('none')


import copy
for t in range(int(input())):
	n = int(input())
	length = list(map(int, input().split(' ')))
	glove = list(map(int, input().split(' ')))
	gr = copy.deepcopy(glove)
	gr.reverse()
	countboth = 0
	countforward = 0
	countback = 0
	for i in range(n):
		if gr[i] >= length[i] and glove[i] >= length[i]:
			countboth += 1
		if glove[i] >= length[i]:
			countforward += 1
		if gr[i] >= length[i]:
			countback += 1
	if countboth == n:
		print('both')
	elif countforward == n:
		print('front')
	elif countback == n:
		print('back')
	else:
		print('none')


t = int(input())
for _ in range(t):
	l = int(input())
	n = list(map(int, input().split()))
	g = list(map(int, input().split()))
	front = back = 1
	for i in range(l):
		if n[i] <= g[i]:
			pass
		else:
			front = 0
	n = n[::-1]
	for i in range(l):
		if n[i] <= g[i]:
			pass
		else:
			back = 0
	if front == 0 and back == 0:
		print('none')
	elif front and (not back):
		print('front')
	elif back and (not front):
		print('back')
	else:
		print('both')


for i in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	x = list(map(int, input().split()))
	l = list(reversed(x))
	a = 0
	b = 0
	for i in range(n):
		if m[i] <= x[i]:
			a = a + 1
		if m[i] <= l[i]:
			b = b + 1
	if a == n and b == n:
		print('both')
	elif a == n and b != n:
		print('front')
	elif a != n and b == n:
		print('back')
	else:
		print('none')


T = int(input())
for _ in range(T):
	n = int(input())
	f = list(map(int, input().split()))
	g = list(map(int, input().split()))
	l = list(reversed(g))
	front = 0
	reverse = 0
	for i in range(n):
		if f[i] <= g[i]:
			front += 1
		if f[i] <= l[i]:
			reverse += 1
	if front == n and reverse == n:
		print('both')
	elif front != n and reverse == n:
		print('back')
	elif front == n and reverse != n:
		print('front')
	else:
		print('none')


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	g = list(map(int, input().split()))
	front = False
	back = False
	for i in range(len(l)):
		if l[i] <= g[i]:
			front = True
		else:
			front = False
			break
	j = 0
	for i in range(len(l) - 1, -1, -1):
		if l[i] <= g[j]:
			back = True
		else:
			back = False
			break
		j += 1
	if front and back:
		print('both')
	elif front:
		print('front')
	elif back:
		print('back')
	else:
		print('none')


tc = int(input())
for i in range(tc):
	N = int(input())
	H = list(map(int, input().split()))
	G = list(map(int, input().split()))
	for a in range(N):
		if H[a] > G[a]:
			n1 = 0
			break
		else:
			n1 = 1
	G.reverse()
	for b in range(N):
		if H[b] > G[b]:
			n2 = 0
			break
		else:
			n2 = 1
	if n1 == 1 and n2 == 0:
		print('front')
	elif n2 == 1 and n1 == 0:
		print('back')
	elif n1 == 1 and n2 == 1:
		print('both')
	else:
		print('none')