#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int INF=1e9;

int main(){
	int n; cin>>n;
	rep(i,n){
		int sum=0;
		rep(h,2){
			string s; cin>>s;
			int len=s.size();
			int tmp=1;
			rep(j,len){
				if(s[j]=='m') sum+=tmp*1000;
				if(s[j]=='c') sum+=tmp*100;
				if(s[j]=='x') sum+=tmp*10;
				if(s[j]=='i') sum+=tmp;
				tmp=1;
				if('1'<s[j] and s[j]<='9') tmp=s[j]-'0';
			}
		}
		//cout<<sum<<endl;
		string ans;
		int div=1000;
		char c[]={'m','c','x','i'};
		rep(j,4){
			int x=sum/div;
			if(x==1) ans+=c[j];
			if(x>1){
				ans+='0'+x; ans+=c[j];
			}
			sum=sum%div;
			div/=10;
		}
		cout<<ans<<endl;
	}
	return 0;
}

