Basically Speaking

Time limit1sMemory limit128 MB

Problem

You are building the base-conversion feature of a pocket calculator. The calculator has the following properties:

  • It has a 7-digit display.
  • Its buttons include the digits 0-9 and the capital letters A-F.
  • It supports bases 2 through 16.

Write a program that converts a number from one base to another and prints how the result would appear on the calculator's display.

Input

Each line of input describes one conversion and contains three values separated by one or more spaces:

  1. the number to convert, written in the source base;
  2. the source base (an integer from 2 to 16);
  3. the target base (an integer from 2 to 16).

Extra spaces may appear before, between, or after the values. Keep reading and processing conversions until the end of the input.

Output

For each conversion, print the converted number exactly as it would appear on the 7-digit display: right-justified within a field of width 7 (padded with leading spaces). Digits greater than 9 are shown as the capital letters A-F.

If the converted number needs more than 7 digits it cannot fit on the display; in that case print ERROR instead, also right-justified within the width-7 field.