/*
AizuOnline A1137
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int N;
char num1[20];
char num2[20];
char kigou[4]="mcxi";
int value[4]={1000,100,10,1};
char outbuf[20];
//
int mcxi2num(char * s)
{
  int sum=0,v,i;
  char *p;

  for(i=0;i<strlen(s);i++)
    if(p=strchr(kigou,s[i]))
      {
	v=value[p-kigou];
      if(i>0 && isdigit(s[i-1]))
	sum +=(v*(s[i-1]-'0'));
      else	
	sum += v;
      }
  return(sum);
}
void num2mcxi(int num,char *s)
{
  int v,i;

  if(num == 0)
    {
      *s='\0';
      return;
    }

  for(i=0;i<4;i++)
    {
      if((v=num / value[i]) > 0)
	{
	  if(v > 1)
	    *s++='0'+v;
	  *s++=kigou[i];
	  num2mcxi(num % value[i],s++);
	  return;
	}
    }
    
}
main()
{
  int sum;

  while(EOF != scanf("%d",&N) && N)
    {
      scanf("%s %s",num1,num2);
      sum = mcxi2num(num1) + mcxi2num(num2);
      num2mcxi(sum,outbuf);
      printf("%s\n",outbuf);
    }
return(0);
}