class Integer
    def to_mcxi
        r = self
        arr = []
        arr[0], r = r.divmod(1000)
        arr[1], r = r.divmod(100)
        arr[2], arr[3] = r.divmod(10)
        mcxi = arr[0] > 1 ? arr[0].to_s + "m" : arr[0] == 1 ? "m" : ""
        mcxi += arr[1] > 1 ? arr[1].to_s + "c" : arr[1] == 1 ? "c" : ""
        mcxi += arr[2] > 1 ? arr[2].to_s + "x" : arr[2] == 1 ? "x" : ""
        mcxi += arr[3] > 1 ? arr[3].to_s + "i" : arr[3] == 1 ? "i" : ""
        mcxi
    end
end

class MCXI
    @str = nil

    def initialize(str)
        @str = str
    end

    def to_i
        x, k = 0, 1
        @str.each_char{|c|
            d = c.to_i
            case d
            when 0
                case c
                when 'm' then x += k * 1000
                when 'c' then x += k * 100
                when 'x' then x += k * 10
                when 'i' then x += k
                end
                k = 1
            else
                k = d
            end
        }
        x
    end
end

gets.to_i.times{
    a, b = gets.chomp.split
    puts (MCXI.new(a).to_i + MCXI.new(b).to_i).to_mcxi
}

