MCXI Numeral System

No attempts yetTime limit1sMemory limit128 MB

Problem

Prof. Hachioji has devised a new numeral system for integers using four lowercase letters "m", "c", "x", "i" and eight digits "2", "3", "4", "5", "6", "7", "8", "9". The digits "0" and "1" are never used in this system.

The letters "m", "c", "x", and "i" correspond to 1000, 100, 10, and 1 respectively, and the digits "2", ..., "9" correspond to their face values 2, ..., 9. This system has nothing to do with the Roman numeral system.

For example, the strings "5m2c3x4i", "m2c4i", and "5m2c3x" correspond to the integers $5234 = 5\times1000 + 2\times100 + 3\times10 + 4\times1$, $1204 = 1000 + 2\times100 + 4\times1$, and $5230 = 5\times1000 + 2\times100 + 3\times10$. The substrings "5m", "2c", "3x", and "4i" represent $5000$, $200$, $30$, and $4$.

Each of the letters "m", "c", "x", and "i" may be prefixed by one digit from "2" to "9". In that case the prefix digit and the letter form a pair whose value equals the letter's value multiplied by the prefix digit.

A string is a valid MCXI-string when all of the following hold:

  • Each of the letters "m", "c", "x", "i" occurs at most once.
  • A prefix digit, when present, appears immediately before its letter.
  • The letters appear in the order m, c, x, i from left to right.
  • Every digit is the prefix of the letter that follows it.
  • Any letter may be omitted, but the whole string must not be empty.

The MCXI-value of an MCXI-string is the sum of the values of its letters and pairs. For every integer from 1 to 9999 there is exactly one MCXI-string with that MCXI-value; for instance, the only MCXI-string whose value is 1204 is "m2c4i". The strings "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are invalid, because they use "1", repeat "c", use "0", and place "c" before "m" in the wrong order, respectively.

Read two MCXI-strings, compute the sum of their MCXI-values, and print the MCXI-string corresponding to that sum.

Input

The first line contains a positive integer $n$ ($n \le 500$), the number of the following lines. Each of the next $n$ lines describes one computation:

MCXI-string1 MCXI-string2

The two MCXI-strings are separated by a single space. For every line, the sum of the two MCXI-values is at most 9999.

Output

For each line of the input, print on its own line a single MCXI-string whose MCXI-value equals the sum of the two given MCXI-values. No other characters should appear in the output.