QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#251. Ancient Numerals

الإحصائيات

A recent archaeological discovery revealed an ancient numbering system similar in nature to Roman Numerals. These numbers were represented by the letters H, Z, Y, G, T, R, and I. Further research revealed their values:

H = 9261
Z = 1323
Y = 441
G = 63
T = 21
R = 3
I = 1

In addition, it was further discovered that these Ancient Numerals also contained fractions of twelve just like the Roman Numerals did:

1/12 = .
2/12 = ..
3/12 = ...
4/12 = ....
5/12 = .....
6/12 = S
7/12 = S.
8/12 = S..
9/12 = S...
10/12 = S....
11/12 = S.....

Characters representing the numbers are listed in order of highest to lowest signifying addition of the values of the characters, hence HZYGTRI = 11,113. If a lower valued character precedes a higher valued character, it is subtracted. No one character may be repeated in a sequence more than five times, with the exception being H. Only the next lower number may be subtracted and only if the sequence would otherwise result in six or more repeating characters, e.g. IR does not represent 2, because 2 can be expressed without subtraction and without repeating the I character 6 or more times with II. The higher valued character must be used in lieu of multiple repeating lower valued characters, e.g. TTT is invalid because G can be used instead.

You will receive a series of Ancient Numerals with an operation (addition, subtraction, multiplication, or division) to be performed on them. There will be exactly one operation per test case.

All Ancient Numerals in the input and output are less than 25 characters in length and are in the range $0 < V < 175\,000\,000$.

Fractions smaller than 1/12 should be discarded, i.e. round down to nearest 12th.

Input

The first line of input will contain the number of test cases, $T$ ($1 \leq T \leq 50$). Each test case will be a valid string of Ancient Numerals, followed directly by an operation (+,-,*,/), followed by another valid string of Ancient Numerals.

Output

Your output should show the result of the operation as a valid string of Ancient Numerals.

Sample Input

3
H-I
ZZZZTTRRRRI/RRRR
Y*R

Sample Output

ZHYYGYTTRTII
YRIS.
Z
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.