{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eRoman numerals are numeral system of ancient Rome based on letters of the alphabet, which are combined to signify the sum (or in some cases, the difference) of their values. This system is decimal but not directly positional, since same digits standing at different positions in usual decimal system are represented by different Roman digits, and one decimal digit could be represented by few Roman.\u003c/p\u003e\n\n\u003cp\u003eThere are seven Roman numerals associated to the decimal \u003cstrong\u003eI\u003c/strong\u003e \u003d \u003cstrong\u003e1\u003c/strong\u003e, \u003cstrong\u003eV\u003c/strong\u003e \u003d \u003cstrong\u003e5\u003c/strong\u003e, \u003cstrong\u003eX\u003c/strong\u003e \u003d \u003cstrong\u003e10_10\u003c/strong\u003e, \u003cstrong\u003eL\u003c/strong\u003e \u003d \u003cstrong\u003e50_10\u003c/strong\u003e, \u003cstrong\u003eC\u003c/strong\u003e \u003d \u003cstrong\u003e100_10\u003c/strong\u003e, \u003cstrong\u003eD\u003c/strong\u003e \u003d \u003cstrong\u003e500_10\u003c/strong\u003e, \u003cstrong\u003eM\u003c/strong\u003e \u003d \u003cstrong\u003e1000_10\u003c/strong\u003e. Generally, Roman numerals are written in descending order from left to right, and are added sequentially, for example \u003cstrong\u003eMMX\u003c/strong\u003e (\u003cstrong\u003e2010\u003c/strong\u003e) is interpreted as \u003cstrong\u003e1000\u003c/strong\u003e + \u003cstrong\u003e1000\u003c/strong\u003e + \u003cstrong\u003e10\u003c/strong\u003e. Certain combinations employ a subtractive principle, which specifies that where a symbol of smaller value precedes a symbol of larger value, the smaller value is subtracted from the larger value, and the result is added to the total. For example, \u003cstrong\u003eMCMXLIV\u003c/strong\u003e equals \u003cstrong\u003e1944\u003c/strong\u003e. \u003cstrong\u003eI\u003c/strong\u003e may precede \u003cstrong\u003eV\u003c/strong\u003e and \u003cstrong\u003eX\u003c/strong\u003e, \u003cstrong\u003eX\u003c/strong\u003e may precede \u003cstrong\u003eL\u003c/strong\u003e or \u003cstrong\u003eC\u003c/strong\u003e. The numerals \u003cstrong\u003eV\u003c/strong\u003e, \u003cstrong\u003eL\u003c/strong\u003e, and \u003cstrong\u003eD\u003c/strong\u003e may not be followed by a numeral of greater or equal value.\u003c/p\u003e\n\n\u003cp\u003eSubtractive principle has been introduced at medevail adges. Originally it allowes only one symbol of smaller value to preced a symbol of larger value. Nowadays this limitation could be skipped to allow shorter notation for some numbers. Also modern computers are much better in hexadecimal numbers and probably it makes sence to introduce \"hexadedimal\" Roman notation.\u003c/p\u003e\n\n\u003cp\u003eLet hexadecimal Roman notation be a notation in which Roman numerals are equivalent to the following numbers: \u003cstrong\u003eI\u003c/strong\u003e \u003d \u003cstrong\u003e1\u003c/strong\u003e, \u003cstrong\u003eV\u003c/strong\u003e \u003d \u003cstrong\u003e8\u003c/strong\u003e, \u003cstrong\u003eX\u003c/strong\u003e \u003d \u003cstrong\u003e10_16\u003c/strong\u003e, \u003cstrong\u003eL\u003c/strong\u003e \u003d \u003cstrong\u003e80_16\u003c/strong\u003e, \u003cstrong\u003eC\u003c/strong\u003e \u003d \u003cstrong\u003e100_16\u003c/strong\u003e, \u003cstrong\u003eD\u003c/strong\u003e \u003d \u003cstrong\u003e800_16\u003c/strong\u003e, \u003cstrong\u003eM\u003c/strong\u003e \u003d \u003cstrong\u003e1000_16\u003c/strong\u003e. Is some hexadecima digit can be represented using addition and subtraction, notation with less symbols is used. If both notations produce same number of symbols addition is used. For example number \u003cstrong\u003eF_16\u003c/strong\u003e is written as \u003cstrong\u003eIX_16\u003c/strong\u003e, \u003cstrong\u003e5C8_16\u003c/strong\u003e becomes \u003cstrong\u003eCCCDLXXXXV_16\u003c/strong\u003e.\u003c/p\u003e\n\n\u003cp\u003eYou need to write a program which can perform computation in hexadecimal Roman notation, namely the following operations: addition, subtraction, and multiplication. All source numbers and results will be integers within \\[\u003cstrong\u003e1\u003c/strong\u003e, \u003cstrong\u003e4FFF_16\u003c/strong\u003e\\].\u003c/p\u003e\n\n\u003cp\u003e\u003ch2\u003eInput\u003c/h2\u003e\u003c/p\u003e\n\n\u003cp\u003eThe first line at input contains one integer \u003cstrong\u003eN\u003c/strong\u003e (\u003cstrong\u003e0\u003c/strong\u003e \u003c \u003cstrong\u003eN\u003c/strong\u003e ≤ \u003cstrong\u003e100\u003c/strong\u003e), the number of test lines. Each line contains test data in format \"\u003c\u003cstrong\u003eA\u003c/strong\u003e\u003e\u003c\u003cstrong\u003eO\u003c/strong\u003e\u003e\u003c\u003cstrong\u003eB\u003c/strong\u003e\u003e\" whitout any spaces. \u003c\u003cstrong\u003eA\u003c/strong\u003e\u003e and \u003c\u003cstrong\u003eB\u003c/strong\u003e\u003e are numbers in hexadecimal Roman notation, \u003c\u003cstrong\u003eO\u003c/strong\u003e\u003e designates operation: +, -, *.\u003c/p\u003e\n\n\u003cp\u003e\u003ch2\u003eOutput\u003c/h2\u003e\u003c/p\u003e\n\n\u003cp\u003eEvery line at output should contain hexadecimal Roman notation of calculation result for corresponding test line at the input.\u003c/p\u003e\n\n"}},{"title":"Example","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e1\nXIIV+XXXXII\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eXXXLV\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}