### constant

TBL = {'m' => 1000, 'c' => 100, 'x' => 10, 'i' => 1}

### subroutines

def mcxi2num(mcxi)
  pos = 0
  len = mcxi.length
  num = 0

  while pos < len
    ch0 = mcxi[pos]
    pos += 1
    if ch0 >= '0' && ch0 <= '9'
      ch1 = mcxi[pos]
      pos += 1
      num += ch0.to_i * TBL[ch1]
    else
      num += TBL[ch0]
    end
  end
  num
end

def num2mcxi(num)
  dm = num / 1000
  dc = (num % 1000) / 100
  dx = (num % 100) / 10
  di = num % 10

  mcxi = ''
  if dm > 0
    mcxi += dm.to_s if dm > 1
    mcxi += 'm'
  end
  if dc > 0
    mcxi += dc.to_s if dc > 1
    mcxi += 'c'
  end
  if dx > 0
    mcxi += dx.to_s if dx > 1
    mcxi += 'x'
  end
  if di > 0
    mcxi += di.to_s if di > 1
    mcxi += 'i'
  end

  mcxi
end

### main

n = gets.to_i

n.times do
  mcxi0, mcxi1 = gets.strip.split
  puts num2mcxi(mcxi2num(mcxi0) + mcxi2num(mcxi1))
end