#include using namespace std; #define int long long signed main(){ int n; cin >> n; vector r(n); for(int i = 0; i < n; i++)cin >> r[i]; int ans = 0; for(int i = 0; i < n; i++){ int sum = 0; for(int j = 0; j < r[i].length(); j++){ if(r[i][j] == 'I'){ if(j < n - 1){ if(r[i][j + 1] == 'V'){ sum += 4; j++; }else if(r[i][j + 1] == 'X'){ sum += 9; j++; }else sum++; }else{ sum++; } }else if(r[i][j] == 'X'){ if(j < n - 1){ if(r[i][j + 1] == 'L'){ sum += 40; j++; }else if(r[i][j + 1] == 'C'){ sum += 90; j++; }else sum += 10; }else{ sum += 10; } }else if(r[i][j] == 'C'){ if(j < n - 1){ if(r[i][j + 1] == 'D'){ sum += 400; j++; }else if(r[i][j + 1] == 'M'){ sum += 900; j++; }else sum += 100; }else{ sum += 100; } }else if(r[i][j] == 'V')sum += 5; else if(r[i][j] == 'L')sum += 50; else if(r[i][j] == 'D')sum += 500; else sum += 1000; } ans += sum; cerr << sum << endl; } string hundred[] = {"C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; string ten[] = {"X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; string one[] = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "XI"}; if(ans >= 4000)cout << "ERROR" << endl; else{ int a = ans / 1000; if(a != 0)for(int i = 0; i < a; i++)cout << 'M'; ans %= 1000; a = ans / 100; if(a != 0)cout << hundred[a - 1]; ans %= 100; a = ans / 10; if(a != 0)cout << ten[a - 1]; a = ans % 10; if(a != 0)cout << one[a - 1] << endl; } }