#include<stdio.h>
int main(){
  int n,i,j,m,s;
  char a[9],b[9];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",a,b);
    m=1;
    s=0;
    for(j=0;a[j]!=0;j++){
      if('0'<=a[j]&&a[j]<='9'){
	m=a[j++]-'0';
      }
      if(a[j]=='m')m*=1000;
      else if(a[j]=='c')m*=100;
      else if(a[j]=='x')m*=10;
      s+=m;
      m=1;
    }//printf("%d ",s);
    for(j=0;b[j]!=0;j++){
      if('0'<=b[j]&&b[j]<='9'){
	m=b[j++]-'0';
      }
      if(b[j]=='m')m*=1000;
      else if(b[j]=='c')m*=100;
      else if(b[j]=='x')m*=10;
      s+=m;
      m=1;
    }//printf("%d\n",s);
    if(s/1000>1)printf("%d",s/1000);
    if(s/1000)printf("m");
    s%=1000;
    if(s/100>1)printf("%d",s/100);
    if(s/100)printf("c");
    s%=100;
    if(s/10>1)printf("%d",s/10);
    if(s/10)printf("x");
    s%=10;
    if(s>1)printf("%d",s);
    if(s)printf("i");
    printf("\n");
  }
  return 0;
}