n = gets.to_i
strs = []
n.times do
  a, b = gets.chomp.split

  na = 0
  prefix = 1
  a.chars.each do |ch|
    case ch
    when /[2-9]/
      prefix = ch.to_i
    when "m"
      na += prefix * 1000
      prefix = 1
    when "c"
      na += prefix * 100
      prefix = 1
    when "x"
      na += prefix * 10
      prefix = 1
    when "i"
      na += prefix
      prefix = 1
    end
  end

  nb = 0
  prefix = 1
  b.chars.each do |ch|
    case ch
    when /[2-9]/
      prefix = ch.to_i
    when "m"
      nb += prefix * 1000
      prefix = 1
    when "c"
      nb += prefix * 100
      prefix = 1
    when "x"
      nb += prefix * 10
      prefix = 1
    when "i"
      nb += prefix
      prefix = 1
    end
  end

  # p [na, nb]

  s = na + nb
  rm = s / 1000
  rc = (s - rm * 1000) / 100
  rx = (s - rm * 1000 - rc * 100) / 10
  ri = s % 10

  res = ""
  res += "m" if rm == 1
  res += rm.to_s + "m" if rm > 1
  res += "c" if rc == 1
  res += rc.to_s + "c" if rc > 1
  res += "x" if rx == 1
  res += rx.to_s + "x" if rx > 1
  res += "i" if ri == 1
  res += ri.to_s + "i" if ri > 1

  puts res
end