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

Rahul and Rashi are off to the wedding of a close relative. This time they have to travel without their guardians. Rahul got very interested in the arrangement of seats inside the train coach.

The entire coach could be viewed as an arrangement of consecutive blocks of size 8.  

Berth Number   	Compartment

1 -  8               1  
9 - 16               2  
17 - 24               3  
... and so on

Each of these size-8 blocks are further arranged as:

1LB,  2MB,  3UB,  4LB,  5MB,  6UB,  7SL,  8SU  
9LB, 10MB, ...
...   
...

Here LB denotes lower berth, MB middle berth and UB upper berth.

The following berths are called Train-Partners:

3UB   |  6UB  
2MB   |  5MB  
1LB   |  4LB  
7SL   |  8SU  

and the pattern is repeated for every set of 8 berths.

Rahul and Rashi are playing this game of finding the train partner of each berth. Can you write a program to do the same?

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

The first line of input contains a single integer T, denoting the number of test cases to follow.
Each of the next T lines contain a single integer N, the berth number whose neighbor is to be found out.

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

The output should contain exactly T lines each containing the berth of the neighbor of the corresponding seat.

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

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

Subtask #1 (50 points):
$1 ≤ T ≤ 8$
$1 ≤ N ≤ 8$

Subtask #2 (50 points):
$1 ≤ T ≤ 100$
$1 ≤ N ≤ 500$

----- Sample Input 1 ------ 
3
1
5
3
----- Sample Output 1 ------ 
4LB
2MB
6UB

Difficulty: EASY

Solutions:
for t in range(int(input())):
	n = int(input())
	m = int(n // 8)
	l = n - m * 8
	if l == 7:
		print(str(n + 1) + 'SU')
	elif l == 0:
		print(str(n - 1) + 'SL')
	elif l == 6:
		print(str(n - 3) + 'UB')
	elif l == 3:
		print(str(n + 3) + 'UB')
	elif l == 5:
		print(str(n - 3) + 'MB')
	elif l == 2:
		print(str(n + 3) + 'MB')
	elif l == 4:
		print(str(n - 3) + 'LB')
	else:
		print(str(n + 3) + 'LB')


T = int(input())
for t in range(T):
	a = int(input())
	remain = a % 8
	if remain == 7:
		print(f'{a + 1}SU')
	elif remain == 0:
		print(f'{a - 1}SL')
	elif remain == 3 or remain == 6:
		if remain == 3:
			print(f'{a + 3}UB')
		else:
			print(f'{a - 3}UB')
	elif remain == 2 or remain == 5:
		if remain == 2:
			print(f'{a + 3}MB')
		else:
			print(f'{a - 3}MB')
	elif remain == 1 or remain == 4:
		if remain == 1:
			print(f'{a + 3}LB')
		else:
			print(f'{a - 3}LB')


t = int(input())
for _ in range(t):
	n = int(input())
	if n % 8 == 0:
		print(f'{n - 1}SL')
	elif n % 8 == 7:
		print(f'{n + 1}SU')
	elif n % 8 == 1 or n % 8 == 4:
		print(f'{n + 3 * (-1) ** (n % 8 - 1)}LB')
	elif n % 8 == 2 or n % 8 == 5:
		print(f'{n + 3 * (-1) ** (n % 8)}MB')
	else:
		print(f'{n + 3 * (-1) ** (n % 8 - 1)}UB')


tp = [('3UB', '6UB'), ('2MB', '5MB'), ('1LB', '4LB'), ('7SL', '8SU')]
tpr = [(y, x) for (x, y) in tp]
tp = tp + tpr
tpd = dict()
tpd = {int(x[0][0]): (int(x[1][0]), x[1][1:]) for x in tp}
for n in range(int(input())):
	s = int(input())
	wagon = (s - 1) // 8
	seat = s % 8 if s % 8 else 8
	(s, co) = tpd[seat]
	print(wagon * 8 + s, co, sep='')


for _ in range(int(input())):
	n = int(input())
	r = n % 8
	q = n // 8
	if r == 0:
		r = 8
		q -= 1
	iteration = q * 8
	d = {1: [4, 'LB'], 2: [5, 'MB'], 3: [6, 'UB'], 4: [1, 'LB'], 5: [2, 'MB'], 6: [3, 'UB'], 7: [8, 'SU'], 8: [7, 'SL']}
	res = dict(((k, d[k]) for k in [r] if k in d))
	print(str(res[r][0] + iteration) + res[r][1])


tpd = {3: (6, 'UB'), 2: (5, 'MB'), 1: (4, 'LB'), 7: (8, 'SU'), 6: (3, 'UB'), 5: (2, 'MB'), 4: (1, 'LB'), 8: (7, 'SL')}
for n in range(int(input())):
	s = int(input())
	wg = (s - 1) // 8
	st = s % 8 if s % 8 else 8
	(s, co) = tpd[st]
	print(wg * 8 + s, co, sep='')


for i in range(int(input())):
	x = int(input())
	v = {1: '4LB', 2: '5MB', 3: '6UB', 4: '1LB', 5: '2MB', 6: '3UB', 7: '8SU', 0: '7SL'}
	q = x // 8
	r = v[x % 8]
	if x % 8 == 0:
		q = x // 8 - 1
	s = 8 * q + int(r[0])
	print(str(s) + r[1:])


t = int(input())
while t:
	N = int(input())
	n = N % 8
	if n == 0:
		print(N - 1, 'SL', sep='')
	elif n == 7:
		print(N + 1, 'SU', sep='')
	elif n == 1:
		print(N + 3, 'LB', sep='')
	elif n == 4:
		print(N - 3, 'LB', sep='')
	elif n == 2:
		print(N + 3, 'MB', sep='')
	elif n == 5:
		print(N - 3, 'MB', sep='')
	elif n == 3:
		print(N + 3, 'UB', sep='')
	elif n == 6:
		print(N - 3, 'UB', sep='')
	t = t - 1


for i in range(int(input())):
	n = int(input())
	r = n % 8
	if r == 0:
		print(str(n - 1) + 'SL')
	if r == 7:
		print(str(n + 1) + 'SU')
	if r == 1:
		print(str(n + 3) + 'LB')
	if r == 4:
		print(str(n - 3) + 'LB')
	if r == 2:
		print(str(n + 3) + 'MB')
	if r == 5:
		print(str(n - 3) + 'MB')
	if r == 3:
		print(str(n + 3) + 'UB')
	if r == 6:
		print(str(n - 3) + 'UB')


T = int(input())
for i in range(T):
	n = int(input())
	if n == 1 or n % 8 == 1:
		print(str(n + 3) + 'LB')
	elif n == 2 or n % 8 == 2:
		print(str(n + 3) + 'MB')
	elif n == 3 or n % 8 == 3:
		print(str(n + 3) + 'UB')
	elif n == 4 or n % 8 == 4:
		print(str(n - 3) + 'LB')
	elif n == 5 or n % 8 == 5:
		print(str(n - 3) + 'MB')
	elif n == 6 or n % 8 == 6:
		print(str(n - 3) + 'UB')
	elif n == 7 or n % 8 == 7:
		print(str(n + 1) + 'SU')
	else:
		print(str(n - 1) + 'SL')


t = int(input())
for i in range(t):
	n = int(input())
	b = n % 8
	if b == 7:
		print('{}SU'.format(n + 1))
	elif b == 0:
		print('{}SL'.format(n - 1))
	else:
		if b % 3 == 0:
			c = 'UB'
		elif b % 3 == 2:
			c = 'MB'
		else:
			c = 'LB'
		if b == 1 or b == 2 or b == 3:
			print('{}{}'.format(n + 3, c))
		else:
			print('{}{}'.format(n - 3, c))


T = int(input())
for _ in range(T):
	N = int(input())
	R = N % 8
	if R == 0:
		print(str(N - 1) + 'SL')
	elif R == 1:
		print(str(N + 3) + 'LB')
	elif R == 2:
		print(str(N + 3) + 'MB')
	elif R == 3:
		print(str(N + 3) + 'UB')
	elif R == 4:
		print(str(N - 3) + 'LB')
	elif R == 5:
		print(str(N - 3) + 'MB')
	elif R == 6:
		print(str(N - 3) + 'UB')
	else:
		print(str(N + 1) + 'SU')


dicti = {1: 'LB', 4: 'LB', 2: 'MB', 5: 'MB', 3: 'UB', 6: 'UB', 7: 'SL', 8: 'SU'}
for _ in range(int(input())):
	n = int(input())
	fake = n % 8
	if fake == 0:
		fake = 8
	if fake < 4:
		part = fake + 3
		n += 3
	elif 7 > fake > 3:
		part = fake - 3
		n -= 3
	elif fake == 7:
		part = 8
		n += 1
	else:
		part = 7
		n -= 1
	berth = dicti[part]
	print(str(n) + berth)


try:
	for _ in range(int(input())):
		N = int(input())
		seat = N % 8 if N % 8 else 8
		if not seat % 8:
			print(str(N - 1) + 'SL')
		elif not seat % 7:
			print(str(N + 1) + 'SU')
		elif not seat % 6:
			print(str(N - 3) + 'UB')
		elif not seat % 5:
			print(str(N - 3) + 'MB')
		elif not seat % 4:
			print(str(N - 3) + 'LB')
		elif not seat % 3:
			print(str(N + 3) + 'UB')
		elif not seat % 2:
			print(str(N + 3) + 'MB')
		else:
			print(str(N + 3) + 'LB')
except:
	pass


for _ in range(int(input())):
	a = int(input())
	n = a
	n = n % 8
	if n == 0:
		print(str(a - 1) + 'SL')
	elif n == 7:
		print(str(a + 1) + 'SU')
	elif n == 1:
		print(str(a + 3) + 'LB')
	elif n == 4:
		print(str(a - 3) + 'LB')
	elif n == 2:
		print(str(a + 3) + 'MB')
	elif n == 5:
		print(str(a - 3) + 'MB')
	elif n == 3:
		print(str(a + 3) + 'UB')
	elif n == 6:
		print(str(a - 3) + 'UB')


for x in range(int(input())):
	n = int(input())
	p = n
	n = n % 8
	if n == 0:
		print(str(p - 1) + 'SL')
	elif n == 7:
		print(str(p + 1) + 'SU')
	elif n == 1:
		print(str(p + 3) + 'LB')
	elif n == 4:
		print(str(p - 3) + 'LB')
	elif n == 2:
		print(str(p + 3) + 'MB')
	elif n == 5:
		print(str(p - 3) + 'MB')
	elif n == 3:
		print(str(p + 3) + 'UB')
	else:
		print(str(p - 3) + 'UB')


t = int(input())
for i in range(t):
	n = int(input())
	n1 = n % 8
	d = {1: 'LB', 2: 'MB', 3: 'UB', 4: 'LB', 5: 'MB', 6: 'UB', 7: 'SU', 0: 'SL'}
	if n1 >= 1 and n1 <= 3:
		n = n + 3
	elif n1 >= 4 and n1 <= 6:
		n = n - 3
	elif n1 == 7:
		n = n + 1
	elif n1 == 0:
		n = n - 1
	print(f'{n}{d[n1]}')


for _ in range(int(input())):
	x = int(input())
	if x % 8 == 1:
		x += 3
		print(f'{x}LB')
	elif x % 8 == 2:
		x += 3
		print(f'{x}MB')
	elif x % 8 == 3:
		x += 3
		print(f'{x}UB')
	elif x % 8 == 4:
		x -= 3
		print(f'{x}LB')
	elif x % 8 == 5:
		x -= 3
		print(f'{x}MB')
	elif x % 8 == 6:
		x -= 3
		print(f'{x}UB')
	elif x % 8 == 7:
		x += 1
		print(f'{x}SU')
	elif x % 8 == 0:
		x -= 1
		print(f'{x}SL')


for _ in range(int(input())):
	n = int(input())
	if n % 8 == 1:
		print('%dLB' % (n + 3))
	elif n % 8 == 2:
		print('%dMB' % (n + 3))
	elif n % 8 == 3:
		print('%dUB' % (n + 3))
	elif n % 8 == 4:
		print('%dLB' % (n - 3))
	elif n % 8 == 5:
		print('%dMB' % (n - 3))
	elif n % 8 == 6:
		print('%dUB' % (n - 3))
	elif n % 8 == 7:
		print('%dSU' % (n + 1))
	elif n % 8 == 0:
		print('%dSL' % (n - 1))


t = int(input())
for i in range(t):
	n = int(input())
	if n % 8 == 0:
		a = n - 1
		print(str(a) + 'SL')
	if n % 8 == 1:
		b = n + 3
		print(str(b) + 'LB')
	if n % 8 == 2:
		c = n + 3
		print(str(c) + 'MB')
	if n % 8 == 3:
		d = n + 3
		print(str(d) + 'UB')
	if n % 8 == 4:
		e = n - 3
		print(str(e) + 'LB')
	if n % 8 == 5:
		f = n - 3
		print(str(f) + 'MB')
	if n % 8 == 6:
		g = n - 3
		print(str(g) + 'UB')
	if n % 8 == 7:
		h = n + 1
		print(str(h) + 'SU')


for _ in range(int(input())):
	sig = ['SU', 'LB', 'MB', 'UB', 'LB', 'MB', 'UB', 'SL']
	n = int(input())
	if not n % 8:
		n -= 1
	elif n % 8 == 7:
		n += 1
	elif n % 8 < 4:
		n += 3
	else:
		n -= 3
	print(str(n) + sig[n % 8])


T = int(input())
for i in range(T):
	N = int(input())
	s = N % 8
	if s == 1:
		print(str(N + 3) + 'LB')
	if s == 2:
		print(str(N + 3) + 'MB')
	if s == 3:
		print(str(N + 3) + 'UB')
	if s == 4:
		print(str(N - 3) + 'LB')
	if s == 5:
		print(str(N - 3) + 'MB')
	if s == 6:
		print(str(N - 3) + 'UB')
	if s == 7:
		print(str(N + 1) + 'SU')
	if s == 0:
		print(str(N - 1) + 'SL')


partner = {1: 4, 4: 1, 2: 5, 5: 2, 3: 6, 6: 3, 7: 8, 8: 7}
pos = ['LB', 'MB', 'UB', 'LB', 'MB', 'UB', 'SL', 'SU']
for _ in range(int(input())):
	N = int(input())
	B = N % 8
	M = N // 8
	if B == 0:
		B = 8
		M -= 1
	x = partner[B]
	print(M * 8 + x, pos[x - 1], sep='')


for i in range(int(input())):
	seats = ['LB', 'MB', 'UB', 'LB', 'MB', 'UB', 'SL', 'SU']
	n = int(input())
	position = n % 8
	if (position == 1) | (position == 2) | (position == 3):
		print(str(n + 3) + seats[position - 1])
	elif (position == 4) | (position == 5) | (position == 6):
		print(str(n - 3) + seats[position - 1])
	elif position == 0:
		print(str(n - 1) + seats[position + 6])
	else:
		print(str(n + 1) + seats[position])


t = int(input())
while t > 0:
	a = int(input())
	if a % 8 == 0:
		print(a - 1, 'SL', sep='')
	elif a % 8 == 1:
		print(a + 3, 'LB', sep='')
	elif a % 8 == 2:
		print(a + 3, 'MB', sep='')
	elif a % 8 == 3:
		print(a + 3, 'UB', sep='')
	elif a % 8 == 4:
		print(a - 3, 'LB', sep='')
	elif a % 8 == 5:
		print(a - 3, 'MB', sep='')
	elif a % 8 == 6:
		print(a - 3, 'UB', sep='')
	else:
		print(a + 1, 'SU', sep='')
	t = t - 1


for i in range(int(input())):
	a = int(input())
	if a % 8 == 0:
		print(a - 1, 'SL', sep='')
	elif a % 8 == 1:
		print(a + 3, 'LB', sep='')
	elif a % 8 == 2:
		print(a + 3, 'MB', sep='')
	elif a % 8 == 3:
		print(a + 3, 'UB', sep='')
	elif a % 8 == 4:
		print(a - 3, 'LB', sep='')
	elif a % 8 == 5:
		print(a - 3, 'MB', sep='')
	elif a % 8 == 6:
		print(a - 3, 'UB', sep='')
	else:
		print(a + 1, 'SU', sep='')


for _ in range(int(input())):
	n = int(input())
	b = n % 8
	if b == 1:
		print(f'{n + 3}LB')
	elif b == 2:
		print(f'{n + 3}MB')
	elif b == 3:
		print(f'{n + 3}UB')
	elif b == 4:
		print(f'{n - 3}LB')
	elif b == 5:
		print(f'{n - 3}MB')
	elif b == 6:
		print(f'{n - 3}UB')
	elif b == 7:
		print(f'{n + 1}SU')
	else:
		print(f'{n - 1}SL')


A = [-1, 3, 3, 3, -3, -3, -3, 1]
B = ['SL', 'LB', 'MB', 'UB', 'LB', 'MB', 'UB', 'SU']
for _ in range(int(input())):
	n = int(input())
	temp = n % 8
	print(n + A[temp], end='')
	print(B[temp])


for t in range(int(input())):
	n = int(input())
	berth = {1: 'LB', 2: 'MB', 3: 'UB', 4: 'LB', 5: 'MB', 6: 'UB'}
	c_s = n % 8
	if c_s == 0 or c_s == 7:
		if c_s == 0:
			print(str(n - 1) + 'SL')
		else:
			print(str(n + 1) + 'SU')
	elif c_s < 4:
		print(str(n + 3) + berth[c_s])
	else:
		print(str(n - 3) + berth[c_s])


T = int(input())
A = [-1, 3, 3, 3, -3, -3, -3, 1]
B = ['SL', 'LB', 'MB', 'UB', 'LB', 'MB', 'UB', 'SU']
for i in range(T):
	N = int(input())
	temp = N % 8
	print(N + A[temp], end='')
	print(B[temp])


t = int(input())
for ni in range(t):
	n = int(input())
	c = 0
	s = ''
	x = n % 8
	if x == 0:
		c = n - 1
	elif x <= 3:
		c = n + 3
	elif x == 7:
		c = n + 1
	else:
		c = n - 3
	if x == 3 or x == 6:
		s = s + str(c) + 'UB'
	elif x == 2 or x == 5:
		s = s + str(c) + 'MB'
	elif x == 1 or x == 4:
		s = s + str(c) + 'LB'
	elif x == 7:
		s = s + str(c) + 'SU'
	else:
		s = s + str(c) + 'SL'
	print(s)


berths_list_2 = [4, 'LB', 5, 'MB', 6, 'UB', 1, 'LB', 2, 'MB', 3, 'UB', 8, 'SU', 7, 'SL']
t = int(input())
for i in range(t):
	berth_num = int(input())
	times = berth_num // 8
	module = berth_num % 8
	if module == 0:
		berth_1_8_partner_2 = berths_list_2[(8 - 1) * 2]
		berth_final_partner_2 = berth_1_8_partner_2 + (times - 1) * 8
	else:
		berth_1_8_partner_2 = berths_list_2[(module - 1) * 2]
		berth_final_partner_2 = berth_1_8_partner_2 + times * 8
	print(f'{berth_final_partner_2}{berths_list_2[(module - 1) * 2 + 1]}')


berths = {1: '4LB', 2: '5MB', 3: '6UB', 4: '1LB', 5: '2MB', 6: '3UB', 7: '8SU', 8: '7SL'}
t = int(input())
for i in range(t):
	berth_num = int(input())
	times = berth_num // 8
	module = berth_num % 8
	if module == 0:
		berth_1_8_partner = berths[8]
		berth_final_partner = str(int(berth_1_8_partner[0]) + (times - 1) * 8)
	else:
		berth_1_8_partner = berths[module]
		berth_final_partner = str(int(berth_1_8_partner[0]) + times * 8)
	print(f'{berth_final_partner + berth_1_8_partner[1:]}')


for i in range(int(input())):
	n = int(input())
	if n % 8 == 0:
		print(n - 1, end='')
		print('SL')
	elif (n + 1) % 8 == 0:
		print(n + 1, end='')
		print('SU')
	else:
		rem = n % 8
		if rem == 1:
			print(n + 3, end='')
			print('LB')
		elif rem == 2:
			print(n + 3, end='')
			print('MB')
		elif rem == 3:
			print(n + 3, end='')
			print('UB')
		elif rem == 4:
			print(n - 3, end='')
			print('LB')
		elif rem == 5:
			print(n - 3, end='')
			print('MB')
		elif rem == 6:
			print(n - 3, end='')
			print('UB')


n = int(input())
while n:
	ber = int(input())
	x = ber % 8
	if x == 1:
		print(str(ber + 3) + 'LB')
	elif x == 2:
		print(str(ber + 3) + 'MB')
	elif x == 3:
		print(str(ber + 3) + 'UB')
	elif x == 4:
		print(str(ber - 3) + 'LB')
	elif x == 5:
		print(str(ber - 3) + 'MB')
	elif x == 6:
		print(str(ber - 3) + 'UB')
	elif x == 7:
		print(str(ber + 1) + 'SU')
	else:
		print(str(ber - 1) + 'SL')
	n -= 1


a = int(input())
for i in range(a):
	b = int(input())
	c = b % 8
	if c == 1:
		print(str(b + 3) + 'LB')
	elif c == 4:
		print(str(b - 3) + 'LB')
	elif c == 2:
		print(str(b + 3) + 'MB')
	elif c == 5:
		print(str(b - 3) + 'MB')
	elif c == 3:
		print(str(b + 3) + 'UB')
	elif c == 6:
		print(str(b - 3) + 'UB')
	elif c == 7:
		print(str(b + 1) + 'SU')
	else:
		print(str(b - 1) + 'SL')


t = int(input())
for i in range(t):
	ber = int(input())
	x = ber % 8
	if x == 1:
		print(str(ber + 3) + 'LB')
	elif x == 2:
		print(str(ber + 3) + 'MB')
	elif x == 3:
		print(str(ber + 3) + 'UB')
	elif x == 4:
		print(str(ber - 3) + 'LB')
	elif x == 5:
		print(str(ber - 3) + 'MB')
	elif x == 6:
		print(str(ber - 3) + 'UB')
	elif x == 7:
		print(str(ber + 1) + 'SU')
	else:
		print(str(ber - 1) + 'SL')