(function (input) {
    var decodeMCXI = function() {
        var cache = {},
            table = {
                "m": 1000,
                "c": 100,
                "x": 10,
                "i": 1
            };
        return function(str) {
            // 文字列はこの順番で来ると仮定
            var keyword = ["m", "c", "x", "i"],
                sum = 0;
            keyword.forEach(function(k) {
                var index = str.indexOf(k),
                    s;
                if ( index >= 0 ) {
                    // 先頭から一致したキーワードまで取り出す
                    // 前置数に関係なくまとまりが取れる
                    s = str.slice(0, index + 1);
                    // キャッシュがあれば利用
                    if ( !cache[s] ) {
                        // 前置詞付きなら
                        if ( s.length == 2 ) {
                            var placeholder = parseInt(s[0]),
                                n = table[s[1]];
                        } else {
                            var placeholder = 1,
                                n = table[s[0]];
                        }
                        cache[s] = placeholder * n;
                    }
                    sum += cache[s];
                    str = str.replace(s, '');   // 取得した文を削除
                }
            });
            return sum;
        };
    }();
    function encodeMCXI(num) {
        var placeholder, n, result = '';
        if ( num >= 1000 ) {
            placeholder = ~~(num / 1000);
            result += ( placeholder > 1 ? placeholder : '' ) + 'm';
            num %= 1000;
        }
        if ( num >= 100 ) {
            placeholder = ~~(num / 100);
            result += ( placeholder > 1 ? placeholder : '' ) + 'c';
            num %= 100;
        }
        if ( num >= 10 ) {
            placeholder = ~~(num / 10);
            result += ( placeholder > 1 ? placeholder : '' ) + 'x';
            num %= 10;
        }
        if ( num > 0 ) {
            result += ( num > 1 ? num : '' ) + 'i';
        }
        return result;
    }

    var inputs = input.replace(/\r/g, '').split("\n"),
        n;

    n = parseInt(inputs.shift());

    for ( var i = 0; i < n; i++ ) {
        var line = inputs.shift().split(' '),
            a = decodeMCXI(line[0]),
            b = decodeMCXI(line[1]);
        console.log(encodeMCXI(a+b));
    }
})(require("fs").readFileSync("/dev/stdin", "utf8"));