#include <iostream>
#include <fstream>
#include <string>
using namespace std;

ifstream fin("DATA4.txt");
ofstream fout("OUT4.txt");

int val(char c)
{
	char rom[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
	int v[7] = {1, 5, 10, 50, 100, 500, 1000};

	for (int x=0; x<7; x++)
		if (rom[x] == c)
			return v[x];

	return 0;	
}

int main()
{
	for (int t=5; t--;)
	{
		string s;
		fin >> s;

		int ans = 0;
		for (int x=0; x<s.length();)
		{
			if (val(s[x]) < val(s[x+1]))
			{
				ans = ans + val(s[x+1]) - val(s[x]);
				x += 2;
			}
			else
			{
				ans += val(s[x]);
				x++;
			}
		}

		fout << ans << endl;
	}

	return 0;
}

