All submissions for this problem are available.
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, ... ... ...
LBdenotes lower berth,
MBmiddle berth and
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?
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.
The output should contain exactly T lines each containing the berth of the neighbor of the corresponding seat.
Subtask #1 (50 points):
- 1 ≤ T ≤ 8
- 1 ≤ N ≤ 8
Subtask #2 (50 points):
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 500
Input: 3 1 5 3 Output: 4LB 2MB 6UB
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.