#include using namespace std; #define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++) template bool chkmin(T &a, T b) { return a > b ? (a = b, true) : false; } template bool chkmax(T &a, T b) { return a < b ? (a = b, true) : false; } typedef long long ll; int nextInt() { int x; scanf("%d", &x); return x; } int f(string s_org) { int res = 0; for (int i = 0; i < (int)s_org.size(); ) { string s = s_org.substr(i, 2); if (s == "IV") { res += 4; i += 2; continue; } if (s == "IX") { res += 9; i += 2; continue; } if (s == "XL") { res += 40; i += 2; continue; } if (s == "XC") { res += 90; i += 2; continue; } if (s == "CD") { res += 400; i += 2; continue; } if (s == "CM") { res += 900; i += 2; continue; } s = s_org.substr(i, 1); if (s == "I") { res += 1; i += 1; continue; } if (s == "V") { res += 5; i += 1; continue; } if (s == "X") { res += 10; i += 1; continue; } if (s == "L") { res += 50; i += 1; continue; } if (s == "C") { res += 100; i += 1; continue; } if (s == "D") { res += 500; i += 1; continue; } if (s == "M") { res += 1000; i += 1; continue; } } return res; } string g(int n) { string s = ""; while (n >= 1000) { s += "M"; n -= 1000; } if (n >= 500) { s += "D"; n -= 500; } if (n >= 400) { s += "CD"; n -= 400; } while (n >= 100) { s += "C"; n -= 100; } if (n >= 50) { s += "L"; n -= 50; } if (n >= 40) { s += "XL"; n -= 40; } while (n >= 10) { s += "X"; n -= 10; } if (n >= 5) { s += "V"; n -= 5; } if (n >= 4) { s += "IV"; n -= 4; } while (n >= 1) { s += "I"; n -= 1; } return s; } int main2() { int N = nextInt(); int ans = 0; REP(nnn, N) { string s; cin >> s; ans += f(s); } if (ans > 3999) cout << "ERROR" << endl; else cout << g(ans) << endl; return 0; } int main() { for (;!cin.eof();cin>>ws) main2(); return 0; }