output_description: For each specification, your program should print an MCXI-string in a line.
  Its MCXI-value should be the sum of the two MCXI-values of the MCXI-strings in
  the specification. No other characters should appear in the output.
input_description: The input is as follows. The first line contains a positive integer _n_ (<=
  500) that indicates the number of the following lines. The _k_ +1 th line is
  the specification of the _k_ th computation (_k_ =1, ..., _n_).
  
  > _n_  
  >  _specification_ 1  
  >  _specification_ 2  
  >  ...  
  >  _specification_ _n_  
  >
  
  Each specification is described in a line:
  
  > _MCXI-string_ 1 _MCXI-string_ 2
  
  The two MCXI-strings are separated by a space.
  
  You may assume that the sum of the two MCXI-values of the two MCXI-strings in
  each specification is less than or equal to 9999.
attempt: def MCXI_integer(mcxi):
      n = 0
      buff = 1
      for c in mcxi:
          if c in "mcxi":
              buff *= 10 ** (3 - ["m", "c", "x", "i"].index(c))
              n += buff
              buff = 1
          else:
              buff = int(c)
      return n
  
  
  def integer_MCXI(n):
      mcxi = ""
      buff = 0
      for i in range(4):
          buff = n % (10 ** (4 - i)) // (10 ** (3 - i))
          if buff == 0:
              pass
          elif buff == 1:
              mcxi += "mcxi"[i]
          else:
              mcxi += str(buff) + "mcxi"[i]
      return mcxi
  
  
  def main():
      n = int(input())
      for _ in range(n):
          s = [x for x in input().split()]
          print(integer_MCXI(MCXI_integer(s[0]) + MCXI_integer(s[1])))
  
  
  if __name__ == "__main__":
      main()
  
problem_description: C: Numeral System
  
  Prof. Hachioji has devised a new numeral system of integral numbers with four
  lowercase letters "m", "c", "x", "i" and with eight digits "2", "3", "4", "5",
  "6", "7", "8", "9". He doesn't use digit "0" nor digit "1" 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 2, ..., 9,
  respectively. This system has nothing to do with the Roman numeral system.
  
  For example, character strings
  
  > "5m2c3x4i", "m2c4i" and "5m2c3x"
  
  correspond to the integral numbers 5234 (=5*1000+2*100+3*10+4*1), 1204
  (=1000+2*100+4*1), and 5230 (=5*1000+2*100+3*10), respectively. The parts of
  strings in the above example, "5m", "2c", "3x" and "4i" represent 5000
  (=5*1000), 200 (=2*100), 30 (=3*10) and 4 (=4*1), respectively.
  
  Each of the letters "m", "c", "x" and "i" may be prefixed by one of the digits
  "2", "3", ..., "9". In that case, the prefix digit and the letter are regarded
  as a pair. A pair that consists of a prefix digit and a letter corresponds to
  an integer that is equal to the original value of the letter multiplied by the
  value of the prefix digit.
  
  For each letter "m", "c", "x" and "i", the number of its occurrence in a
  string is at most one. When it has a prefix digit, it should appear together
  with the prefix digit. The letters "m", "c", "x" and "i" must appear in this
  order, from left to right. Moreover, when a digit exists in a string, it
  should appear as the prefix digit of the following letter. Each letter may be
  omitted in a string, but the whole string must not be empty. A string made in
  this manner is called an _MCXI-string_.
  
  An MCXI-string corresponds to a positive integer that is the sum of the values
  of the letters and those of the pairs contained in it as mentioned above. The
  positive integer corresponding to an MCXI-string is called its MCXI-value.
  Moreover, given an integer from 1 to 9999, there is a unique MCXI-string whose
  MCXI-value is equal to the given integer. For example, the MCXI-value of an
  MCXI-string "m2c4i" is 1204 that is equal to `1000 + 2*100 + 4*1`. There are
  no MCXI-strings but "m2c4i" that correspond to 1204. Note that strings
  "1m2c4i", "mcc4i", "m2c0x4i", and "2cm4i" are not valid MCXI-strings. The
  reasons are use of "1", multiple occurrences of "c", use of "0", and the wrong
  order of "c" and "m", respectively.
  
  Your job is to write a program for Prof. Hachioji that reads two MCXI-strings,
  computes the sum of their MCXI-values, and prints the MCXI-string
  corresponding to the result.
samples: [{"input": "xi x9i\n    i 9i\n    c2x2i 4c8x8i\n    m2ci 4m7c9x8i\n    9c9x9i i\n    i 9m9c9x8i\n    m i\n    i m\n    m9i i\n    9m8c7xi c2x8i", "output": "x\n    x\n    6cx\n    5m9c9x9i\n    m\n    9m9c9x9i\n    mi\n    mi\n    mx\n    9m9c9x9i"}]