시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 0 0 0 0.000%

문제

Roman numerals are numeral system of ancient Rome based on letters of the alphabet, which are combined to signify the sum (or in some cases, the difference) of their values. This system is decimal but not directly positional, since same digits standing at different positions in usual decimal system are represented by different Roman digits, and one decimal digit could be represented by few Roman.

There are seven Roman numerals associated to the decimal I = 1V = 5X = 1010L = 5010C = 10010D = 50010M = 100010. Generally, Roman numerals are written in descending order from left to right, and are added sequentially, for example MMX (2010) is interpreted as 1000 + 1000 + 10. Certain combinations employ a subtractive principle, which specifies that where a symbol of smaller value precedes a symbol of larger value, the smaller value is subtracted from the larger value, and the result is added to the total. For example, MCMXLIV equals 1944I may precede V and XX may precede L or C. The numerals VL, and D may not be followed by a numeral of greater or equal value.

Subtractive principle has been introduced at medevail adges. Originally it allowes only one symbol of smaller value to preced a symbol of larger value. Nowadays this limitation could be skipped to allow shorter notation for some numbers. Also modern computers are much better in hexadecimal numbers and probably it makes sence to introduce "hexadedimal" Roman notation.

Let hexadecimal Roman notation be a notation in which Roman numerals are equivalent to the following numbers: I = 1V = 8X = 1016L = 8016C10016D = 80016M = 100016. Is some hexadecima digit can be represented using addition and subtraction, notation with less symbols is used. If both notations produce same number of symbols addition is used. For example number F16 is written as IX165C816 becomes CCCDLXXXXV16.

You need to write a program which can perform computation in hexadecimal Roman notation, namely the following operations: addition, subtraction, and multiplication. All source numbers and results will be integers within [14FFF16].

입력

The first line at input contains one integer N (0 < N ≤ 100), the number of test lines. Each line contains test data in format "<A><O><B>" whitout any spaces. <A> and <B> are numbers in hexadecimal Roman notation, <O> designates operation: +, -, *.

출력

Every line at output should contain hexadecimal Roman notation of calculation result for corresponding test line at the input.

예제 입력

3
XIIV+XXXXII
XXIIII*XXXIII
XXIV*IV

예제 출력

XXXLV
CDXXVIIII
CXI

힌트