import sys def v(t): for i in range(7): if(k:=t.find("MDCLXVI"[i]))>=0:return[1000,500,100,50,10,5,1][i]+v(t[k+1:])-v(t[:k]) return 0 *map(print,map(v,sys.argv[1:])),