#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        string S,T;
        cin >> S >> T;
        int A=0,B=0;
        for(int i=0; i<S.size(); i++){
            if(S[i] == 'm'){
                if(i-1>=0 and '2' <= S[i-1] and S[i-1] <= '9'){
                    A += (S[i-1] - '0')*1000;
                }else{
                    A += 1000;
                }
            }
            if(S[i] == 'c'){
                if(i-1>=0 and '2' <= S[i-1] and S[i-1] <= '9'){
                    A += (S[i-1] - '0')*100;
                }else{
                    A += 100;
                }
            }
            if(S[i] == 'x'){
                if(i-1>=0 and '2'<=S[i-1] and S[i-1]<='9'){
                    A += (S[i-1] - '0')*10;
                }else{
                    A += 10;
                }
            }
            if(S[i] == 'i'){
                if(i-1>=0 and '2'<=S[i-1] and S[i-1] <= '9'){
                    A += (S[i-1] - '0');
                }else{
                    A++;
                }
            }
        }
        for(int i=0; i<T.size(); i++){
            if(T[i] == 'm'){
                if(i-1>=0 and '2' <= T[i-1] and T[i-1] <= '9'){
                    B += (T[i-1] - '0')*1000;
                }else{
                    B += 1000;
                }
            }
            if(T[i] == 'c'){
                if(i-1>=0 and '2' <= T[i-1] and T[i-1] <= '9'){
                    B += (T[i-1] - '0')*100;
                }else{
                    B += 100;
                }
            }
            if(T[i] == 'x'){
                if(i-1>=0 and '2'<=T[i-1] and T[i-1]<='9'){
                    B += (T[i-1] - '0')*10;
                }else{
                    B += 10;
                }
            }
            if(T[i] == 'i'){
                if(i-1>=0 and '2'<=T[i-1] and T[i-1] <= '9'){
                    B += (T[i-1] - '0');
                }else{
                    B++;
                }
            }
        }
        int sum = A + B;
        string str = "mcxi";
        string ans = "";
        while(sum){
            if(sum%10 != 0){
                ans += str.back();
            }
            str.pop_back();
            if(sum%10 >= 2){
                ans += sum%10 + '0';
            }
            sum /= 10;
        }
        reverse(ans.begin(),ans.end());
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3244