Roman Numeral to Integer

Easy

Given a roman numeral s, convert it to an integer.

Roman numerals are denoted by a combination of some symbols.

SymbolValue
I1
V5
X10
L50
C100
D500
M1000
Example 1

s: “X”

Result: 10

Example 2

s: “VI”

Result: 6

Example 3

s: “XII”

Result: 12

Read about Roman To Integer conversion here.

Testing

Input Format

The first line contains an integer ‘T’ denoting the number of test cases.

For each test case, the input contains a line with string ‘s’.

Output Format

For each test case, the output contains one line with an integer ‘val’ denoting the integer value.

Sample Input

3
XV
MMMDCX
XX

Expected Output

15
3610
20

Constraints

1 <= T <= 100
1 <= s.size <= 15

Editorial Link: Editorial