Under construction

Still being built. Things may change

Number Base Conversion

Interview

Time limit1sMemory limit128 MB

Summary
Convert a number given in one base to another base, where digits run 0-9, A-Z, a-z, and print a blank line after each conversion.
Level

Medium4 of 10

Topics
Math, String, Implementation, Simulation
Solved
No attempts yet

Problem

Write a program that converts a number written in one base into the same number written in another base. There are 62 possible digits:

{ 0-9, A-Z, a-z }

Hint: if you chain base conversions, feeding the output of one conversion in as the input to the next, then when you return to the original base you should recover the original number.

Input

The first line contains a single positive integer: the number of lines that follow.

Each following line contains a (decimal) input base, a (decimal) output base, and a number written in the input base, separated by spaces. Both the input base and the output base are in the range from 2 to 62.

The digit values are: 0–9 have their usual meanings 0 through 9, and A = 10, B = 11, …, Z = 35, a = 36, b = 37, …, z = 61.

Output

For each base conversion, print three lines.

  1. The first line is the input base (in decimal), a space, then the input number exactly as it was given.
  2. The second line is the output base (in decimal), a space, then the same number expressed in the output base.
  3. The third line is blank.

Examples1

  1. Example 1

    Input
    8
    62 2 abcdefghiz
    10 16 1234567890123456789012345678901234567890
    16 35 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2
    35 23 333YMHOUE8JPLT7OX6K9FYCQ8A
    23 49 946B9AA02MI37E3D3MMJ4G7BL2F05
    49 61 1VbDkSIMJL3JjRgAdlUfcaWj
    61 5 dl9MDSWqwHjDnToKcsWE1S
    5 10 42104444441001414401221302402201233340311104212022133030
    
    Expected output
    62 abcdefghiz
    2 11011100000100010111110010010110011111001001100011010010001
    
    10 1234567890123456789012345678901234567890
    16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2
    
    16 3A0C92075C0DBF3B8ACBC5F96CE3F0AD2
    35 333YMHOUE8JPLT7OX6K9FYCQ8A
    
    35 333YMHOUE8JPLT7OX6K9FYCQ8A
    23 946B9AA02MI37E3D3MMJ4G7BL2F05
    
    23 946B9AA02MI37E3D3MMJ4G7BL2F05
    49 1VbDkSIMJL3JjRgAdlUfcaWj
    
    49 1VbDkSIMJL3JjRgAdlUfcaWj
    61 dl9MDSWqwHjDnToKcsWE1S
    
    61 dl9MDSWqwHjDnToKcsWE1S
    5 42104444441001414401221302402201233340311104212022133030
    
    5 42104444441001414401221302402201233340311104212022133030
    10 1234567890123456789012345678901234567890