// The "Problem5" class.
import java.awt.*;
import java.io.*;

public class Problem5
{

    public static void main (String[] args) throws IOException
    {
	BufferedReader input = new BufferedReader (new FileReader ("DATA5.txt"));
	PrintWriter output = new PrintWriter (new FileWriter ("OUT5.txt"));

	String col[] [] = new String [5] [5];

	for (int d = 0 ; d < 5 ; d++)
	    for (int e = 0 ; e < 5 ; e++)
		col [d] [e] = input.readLine ();



	for (int d = 0 ; d < 5 ; d++)
	{
	    int answer = 0;
	    int cell = 0;
	    for (int e = 0 ; e < 5 ; e++)
	    {
		if ((col [d] [e].substring (0, 1)).equals ("="))
		{
		    col [d] [e] = col [d] [e].substring (1, col [d] [e].length ());  //taking out the "="

		    String cols[] = col [d] [e].split (" ");
		    for (int x = 0 ; x < cols.length ; x++)
		    {
			if (cols [x].equals ("A"))
			    cols [x] = col [0] [Integer.parseInt (cols [x].substring (1, 2)) - 1];
			if (cols [x].equals ("B"))
			    cols [x] = col [1] [Integer.parseInt (cols [x].substring (1, 2)) - 1];
			if (cols [x].equals ("C"))
			    cols [x] = col [2] [Integer.parseInt (cols [x].substring (1, 2)) - 1];
			if (cols [x].equals ("D"))
			    cols [x] = col [3] [Integer.parseInt (cols [x].substring (1, 2)) - 1];
			if (cols [x].equals ("E"))
			    cols [x] = col [4] [Integer.parseInt (cols [x].substring (1, 2)) - 1];

		    }
		    /*for (int x = 0 ; x < cols.length ; x++)
		    {
			if (x == 0)
			{
			    if (cols [x].equals ("+"))
				answer = Integer.parseInt (cols [x]) + Integer.parseInt (cols [x + 1]);
			    if (cols [x].equals ("-"))
				answer = Integer.parseInt (cols [x]) - Integer.parseInt (cols [x + 1]);
			    if (cols [x].equals ("*"))
				answer = Integer.parseInt (cols [x]) * Integer.parseInt (cols [x + 1]);
			}
			else
			{
			    if (cols [x].equals ("+"))
				answer = answer + Integer.parseInt (cols [x + 1]);
			    if (cols [x].equals ("-"))
				answer = answer - Integer.parseInt (cols [x + 1]);
			    if (cols [x].equals ("*"))
				answer = answer * Integer.parseInt (cols [x + 1]);
			}
		    }*/
		    col [d] [e] = String.valueOf (answer);
		    output.println (col [d] [e]);
		} //if == "="
		else
		    output.println (col [d] [e]);
	    }
	}

	output.close ();
    } // main method
} // Problem5 class



