r=".IVXLCDM",require("fs").readFileSync("/dev/stdin","utf8").split('\n').map(function(i){i?(n=s=p=0,i.split('').map(function(c){n=Math.pow(10,~~((n=r.indexOf(c))/2))/(2-(n%2)),n>p?p*=-1:0,s+=p,p=n}),console.log(s+=p)):0})