#20131027
#15:15
#MCXI
ansi=["m","c","x","i"]
gets.to_i.times{
	n=gets.split(" ")
	2.times{|t|
		n[t] = ((n[t].gsub("m","*1000+").gsub("c","*100+").gsub("x","*10+").gsub("i","*1+").gsub("+*","+1*"))+"0")
		n[t][0]="" if n[t][0]==42
	}
	 
	ansv= eval "#{n[0]}+#{n[1]}"

	ansa=[]
	ansa.push ansv/1000
	ansv%=1000
	ansa.push ansv/100
	ansv%=100
	ansa.push ansv/10
	ansa.push ansv%10

	ans = ""
	4.times{|t|
		ans+="#{ansa[t]}#{ansi[t]}" if ansa[t] > 1
		ans+="#{ansi[t]}" if ansa[t] == 1
	}
	puts ans
}