C = {'I': 1, 'II': 2, 'III': 3, 'IV': 4, 'V': 5, 'VI': 6, 'VII': 7, 'VIII': 8, 'IX': 9, 'X': 10, 'XX': 20, 'XXX': 30, 'XL': 40, 'L': 50, 'LX': 60, 'LXX': 70, 'LXXX': 80, 'XC': 90, 'C': 100, 'CC': 200, 'CCC': 300, 'CD': 400, 'D': 500, 'DC': 600, 'DCC': 700, 'DCCC': 800, 'CM': 900, 'M': 1000, 'MM': 2000, 'MMM': 3000} D = {1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI', 7: 'VII', 8: 'VIII', 9: 'IX', 10: 'X', 20: 'XX', 30: 'XXX', 40: 'XL', 50: 'L', 60: 'LX', 70: 'LXX', 80: 'LXXX', 90: 'XC', 100: 'C', 200: 'CC', 300: 'CCC', 400: 'CD', 500: 'D', 600: 'DC', 700: 'DCC', 800: 'DCCC', 900: 'CM', 1000: 'M', 2000: 'MM', 3000: 'MMM'} n = int(input()) R = list(input().split()) ans = 0 for i in range(n): r = R[i] l = len(r) idx = 0 while idx < l: for d in range(4, 0, -1): if idx + d <= l and r[idx:idx + d] in C: ans += C[r[idx:idx + d]] idx += d break if ans > 3999: print("ERROR") else: res = '' th, ans = divmod(ans, 1000) h, ans = divmod(ans, 100) te, o = divmod(ans, 10) if th > 0: res += D[th * 1000] if h > 0: res += D[h * 100] if te > 0: res += D[te * 10] if o > 0: res += D[o] print(res)