#include <stdio.h>
#include <ctype.h>

static int
readMCXI (
  const char  * s
  )
{
  int prefix = 1;
  int res = 0;

  for ( ; *s != '\0'; ++s )
  {
    if ( isdigit ( *s ) )
    {
      prefix = *s - '0';
      continue ;
    }

    switch ( *s )
    {
      case 'm': res += prefix * 1000; break ;
      case 'c': res += prefix * 100;  break ;
      case 'x': res += prefix * 10;   break ;
      case 'i': res += prefix * 1;    break ;
    }
    prefix = 1;
  }

  return ( res );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );
  while ( n-- )
  {
    char s1[ 16 ], s2[ 16 ];
    int  res, m, c, x, i;

    scanf ( " %s %s", s1, s2 );
    res = readMCXI ( s1 ) + readMCXI ( s2 );
    i   = ( res        ) % 10;
    x   = ( res / 10   ) % 10;
    c   = ( res / 100  ) % 10;
    m   = ( res / 1000 ) % 10;

    if ( m ) printf ( m > 1 ? "%dm" : "m", m );
    if ( c ) printf ( c > 1 ? "%dc" : "c", c );
    if ( x ) printf ( x > 1 ? "%dx" : "x", x );
    if ( i ) printf ( i > 1 ? "%di" : "i", i );
    puts ( "" );
  }

  return ( 0 );
}