import java.io.*;

public class Problem5
{
    public static void main (String[] args) throws IOException
    {
	BufferedReader in = new BufferedReader (new FileReader ("DATA5.txt"));
	PrintWriter out = new PrintWriter (new FileWriter ("OUT5.txt"));

	int num[] [] = new int [5] [5];

	for (int x = 0 ; x < 5 ; x++)
	    for (int y = 0 ; y < 5 ; y++)
	    {
		String str = in.readLine ();


		num [x] [y] = solve (str, num);


	    }

	for (int x = 0 ; x < 5 ; x++)
	    for (int y = 0 ; y < 5 ; y++)
		out.println (num [x] [y]);






	// getting inputs

	in.close ();
	out.close ();

    } // end of main


    static int solve (String in, int[] [] num)
    {
	int result = 0;

	int len = in.length ();
	 char tempCal='9';
	for (int i = 0 ; i < len ; i++)
	{
	    char c = in.charAt (i);
	    if (c != ' ')
	    {
		if (number (c))
		{
		    if (tempCal!='9')
		    {
		     if (tempCal == '+')
		    result += (int) (c) - 48;
		    if (tempCal == '-')
		    result -= (int) (c) - 48;
		     if (tempCal == '*')
		    result *= (int) (c) - 48;
		    }
		}
		else if (c >= 'A' && c <= 'E')
		{
		    int temp = -1;
		    switch (c)
		    {
			case 'A':
			    temp = 0;
			    break;
			case 'B':
			    temp = 1;
			    break;
			case 'C':
			    temp = 2;
			    break;
			case 'D':
			    temp = 3;
			    break;
			case 'E':
			    temp = 4;
			    break;
		    }
		    i++;

		    int tempY = (int) (in.charAt (i)) - 49;
      
		     if (tempCal!='9')
		    {
		     if (tempCal == '+')
		   result += num[temp][tempY] ;
		    if (tempCal == '-')
		   result -= num[temp][tempY] ;
		     if (tempCal == '*')
		    result *= num[temp][tempY] ;
		    
		    }
		    
		    
		}
		else if (c == '+' || c == '-' || c == '*')
		{
		   tempCal=c;



		}


	    }
	    
	}

	return result;
    }


    static boolean number (char c)
    {
	int intc = (int) (c);

	if (intc < 58 && intc > 47)
	    return true;
	else
	    return false;

    }
} // end of class


