#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
template<class T>inline T emod(T a, T p) { return (a%p + p) % p;}
//-------------------
map<char, int> mp = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};

vector<string> resi = {"CM", "CD", "XC", "XL", "IX", "IV"};
vector<int> vv = {900, 400, 90, 40, 9, 4};
vector<char> v = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
// vector<char> resi = {}
int rom2int() {
    string s; cin >> s;
    int sm = 0;
    rep(i, s.size()) {
        if(i < s.size()-1 and mp[s[i]] < mp[s[i+1]]) {
            sm -= mp[s[i]];
        } else {
            sm += mp[s[i]];
        }
    }
    return sm;
}

void int2rom(int k) {
    string s = ""; 
    rep(i, v.size()) {
        int cur = k / mp[v[i]];
        rep(_, cur) s += v[i];
        k -= cur * mp[v[i]];
        if(i < v.size()-1 and k >= vv[i]) {
            s += resi[i];
            k -= vv[i];                   
        }
    }
    cout << s << endl;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    int n; cin >> n;

    reverse(ALL(v));
    int sm = 0;    
    rep(i, n) {
        sm += rom2int();
    }
    // cout << sm << endl;
    // int sm = 4;
    if(sm >= 4000) cout << "ERROR" << endl;
    else {
        int2rom(sm);
    }
    return 0;
}