Time limit
2s
Memory limit
128 MB
Roman numerals use the following seven symbols.
| Symbol | I | V | X | L | C | D | M |
|---|---|---|---|---|---|---|---|
| Value | 1 | 5 | 10 | 50 | 100 | 500 | 1000 |
A Roman numeral must satisfy all of these rules.
By these rules, 235 is CCXXXV, 1940 is MCMXL, and 5493 is MMMMMCDXCIII.
Some people hid Roman numerals inside English sentences by inserting other letters or spaces before, after, or between the Roman numeral symbols. If the letters m, d, c, l, x, v, i that correspond to a Roman numeral can be selected from a sentence in order, the sentence can be regarded as expressing that numeral. For example, matt is the best school in korea can express 1051 by selecting M, L, I in order. The order of letters cannot be changed, so mind control cannot express M, L, I.
A sentence may express more than one number. For example, matt is the best school in korea can also express 1151 by selecting M, C, L, I in order.
Given English sentences, write a program that finds the largest number each sentence can express. If a sentence cannot express any positive integer, output 0.
The first line contains the number of sentences N. (1 ≤ N ≤ 10)
Each of the next N lines contains one English sentence. Every sentence consists only of lowercase English letters and spaces, and its length is at most 10,000.
For each sentence, output the largest number it can express on its own line. If a sentence cannot be interpreted as any number, output 0.