program Problem5;
Uses Crt;

Var
Flag,Input2,Loop:Integer;
Input:String;
A,B,C,D,E:Array[1..5] of Integer;
InputFile,OutputFile:Text;

Procedure RA;
begin
     For Loop:=1 to 5 do
     begin
     Readln(InputFile,Input);
        If Input='=A1 + A2' then
        begin
        A[Loop]:=A[1] + A[2]
        end
        else
            If Input='=A1 + A3' then
            begin
            A[Loop]:=A[1] + A[3]
            end
            else
                If Input='=A1 + A4' then
                begin
                A[Loop]:=A[1] + A[4]
                end
                else
                    If Input='=A2 + A1' then
                    begin
                    A[Loop]:=A[2] + A[1]
                    end
                    else
                        If Input='=A2 + A3' then
                        begin
                        A[Loop]:=A[2] + A[3]
                        end
                        else
                            If Input='=A2 + A4' then
                            begin
                            A[Loop]:=A[2] + A[4]
                            end
                            else
                                If Input='=A3 + A1' then
                                begin
                                A[Loop]:=A[3] + A[1]
                                end
                                else
                                    If Input='=A3 + A2' then
                                    begin
                                    A[Loop]:=A[3] + A[2]
                                    end
                                    else
                                        If Input='=A3 + A4' then
                                        begin
                                        A[Loop]:=A[3] + A[4]
                                        end
                                        else
                                            If Input='=A4 + A1' then
                                            begin
                                            A[Loop]:=A[4] + A[1]
                                            end
                                            else
                                                If Input='=A4 + A2' then
                                                begin
                                                A[Loop]:=A[4] + A[2]
                                                end
                                                else
                                                    If Input='=A4 + A3' then
                                                    begin
                                                    A[Loop]:=A[4] + A[3]
                                                    end
                                                    else
        If Input='=A1 - A2' then
        begin
        A[Loop]:=A[1] - A[2]
        end
        else
            If Input='=A1 - A3' then
            begin
            A[Loop]:=A[1] - A[3]
            end
            else
                If Input='=A1 - A4' then
                begin
                A[Loop]:=A[1] - A[4]
                end
                else
                    If Input='=A2 - A1' then
                    begin
                    A[Loop]:=A[2] - A[1]
                    end
                    else
                        If Input='=A2 - A3' then
                        begin
                        A[Loop]:=A[2] - A[3]
                        end
                        else
                            If Input='=A2 - A4' then
                            begin
                            A[Loop]:=A[2] - A[4]
                            end
                            else
                                If Input='=A3 - A1' then
                                begin
                                A[Loop]:=A[3] - A[1]
                                end
                                else
                                    If Input='=A3 - A2' then
                                    begin
                                    A[Loop]:=A[3] - A[2]
                                    end
                                    else
                                        If Input='=A3 - A4' then
                                        begin
                                        A[Loop]:=A[3] -A[4]
                                        end
                                        else
                                            If Input='=A4 - A1' then
                                            begin
                                            A[Loop]:=A[4] - A[1]
                                            end
                                            else
                                                If Input='=A4 - A2' then
                                                begin
                                                A[Loop]:=A[4] - A[2]
                                                end
                                                else
                                                    If Input='=A4 - A3' then
                                                    begin
                                                    A[Loop]:=A[4] - A[3]
                                                    end
                                                    else
        If Input='=A1 * A2' then
        begin
        A[Loop]:=A[1] * A[2]
        end
        else
            If Input='=A1 * A3' then
            begin
            A[Loop]:=A[1] * A[3]
            end
            else
                If Input='=A1 * A4' then
                begin
                A[Loop]:=A[1] * A[4]
                end
                else
                    If Input='=A2 * A1' then
                    begin
                    A[Loop]:=A[2] * A[1]
                    end
                    else
                        If Input='=A2 * A3' then
                        begin
                        A[Loop]:=A[2] * A[3]
                        end
                        else
                            If Input='=A2 * A4' then
                            begin
                            A[Loop]:=A[2] * A[4]
                            end
                            else
                                If Input='=A3 * A1' then
                                begin
                                A[Loop]:=A[3] * A[1]
                                end
                                else
                                    If Input='=A3 * A2' then
                                    begin
                                    A[Loop]:=A[3] * A[2]
                                    end
                                    else
                                        If Input='=A3 * A4' then
                                        begin
                                        A[Loop]:=A[3] * A[4]
                                        end
                                        else
                                            If Input='=A4 * A1' then
                                            begin
                                            A[Loop]:=A[4] * A[1]
                                            end
                                            else
                                                If Input='=A4 * A2' then
                                                begin
                                                A[Loop]:=A[4] * A[2]
                                                end
                                                else
                                                    If Input='=A4 * A3' then
                                                    begin
                                                    A[Loop]:=A[4] * A[3]
                                                    end
                                                    else
                                                        begin
                                                        Val(Input,Input2,Flag);
                                                        A[Loop]:=Input2;
     end;                                               end;
end;
Procedure RB;
begin
     For Loop:=1 to 5 do
     begin
     Readln(InputFile,Input);
        If Input='=A1 + A2' then
        begin
        B[Loop]:=A[1] +A[2]
        end
        else
            If Input='=A1 + A3' then
            begin
            B[Loop]:=A[1] + A[3]
            end
            else
                If Input='=A1 + A4' then
                begin
                B[Loop]:=A[1] + A[4]
                end
                else
                    If Input='=A2 + A1' then
                    begin
                    B[Loop]:=A[2] + A[1]
                    end
                    else
                        If Input='=A2 + A3' then
                        begin
                        B[Loop]:=A[2] + A[3]
                        end
                        else
                            If Input='=A2 + A4' then
                            begin
                            B[Loop]:=A[2] + A[4]
                            end
                            else
                                If Input='=A3 + A1' then
                                begin
                                B[Loop]:=A[3] + A[1]
                                end
                                else
                                    If Input='=A3 + A2' then
                                    begin
                                    B[Loop]:=A[3] + A[2]
                                    end
                                    else
                                        If Input='=A3 + A4' then
                                        begin
                                        B[Loop]:=A[3] + A[4]
                                        end
                                        else
                                            If Input='=A4 + A1' then
                                            begin
                                            B[Loop]:=A[4] + A[1]
                                            end
                                            else
                                                If Input='=A4 + A2' then
                                                begin
                                                B[Loop]:=A[4] + A[2]
                                                end
                                                else
                                                    If Input='=A4 + A3' then
                                                    begin
                                                    B[Loop]:=A[4] + A[3]
                                                    end
                                                    else
                                                        If Input='=A5 + A1' then
                                                        begin
                                                        B[Loop]:=A[5] + A[1]
                                                        End
                                                        Else
                                                            If Input='=A5 + A2' then
                                                            begin
                                                            B[Loop]:=A[5] + A[2]
                                                            End
                                                            Else
                                                                If Input='=A5 + A3' then
                                                                begin
                                                                B[Loop]:=A[5] + A[3]
                                                                End
                                                                Else
                                                                    If Input='=A5 + A4' then
                                                                    begin
                                                                    B[Loop]:=A[5] + A[4]
                                                                    End
                                                                    Else
                                                                        If Input='=A1 + A5' then
                                                                        begin
                                                                        B[Loop]:=A[1] + A[5]
                                                                        End
                                                                        Else
                                                                            If Input='=A2 + A5' then
                                                                            begin
                                                                            B[Loop]:=A[2] + A[5]
                                                                            End
                                                                            Else
                                                                                If Input='=A3 + A5' then
                                                                                begin
                                                                                B[Loop]:=A[3] + A[5]
                                                                                End
                                                                                Else
                                                                                    If Input='=A4 + A5' then
                                                                                    begin
                                                                                    B[Loop]:=A[4] + A[5]
                                                                                    End
                                                                                    Else
        If Input='=A1 - A2' then
        begin
        B[Loop]:=A[1] - A[2]
        end
        else
            If Input='=A1 - A3' then
            begin
            B[Loop]:=A[1] - A[3]
            end
            else
                If Input='=A1 - A4' then
                begin
                B[Loop]:=A[1] - A[4]
                end
                else
                    If Input='=A2 - A1' then
                    begin
                    B[Loop]:=A[2] - A[1]
                    end
                    else
                        If Input='=A2 - A3' then
                        begin
                        B[Loop]:=A[2] - A[3]
                        end
                        else
                            If Input='=A2 - A4' then
                            begin
                            B[Loop]:=A[2] - A[4]
                            end
                            else
                                If Input='=A3 - A1' then
                                begin
                                B[Loop]:=A[3] - A[1]
                                end
                                else
                                    If Input='=A3 - A2' then
                                    begin
                                    B[Loop]:=A[3] - A[2]
                                    end
                                    else
                                        If Input='=A3 - A4' then
                                        begin
                                        B[Loop]:=A[3] -A[4]
                                        end
                                        else
                                            If Input='=A4 - A1' then
                                            begin
                                            B[Loop]:=A[4] - A[1]
                                            end
                                            else
                                                If Input='=A4 - A2' then
                                                begin
                                                B[Loop]:=A[4] - A[2]
                                                end
                                                else
                                                    If Input='=A4 - A3' then
                                                    begin
                                                    B[Loop]:=A[4] - A[3]
                                                    end
                                                    else
        If Input='=A1 * A2' then
        begin
        B[Loop]:=A[1] * A[2]
        end
        else
            If Input='=A1 * A3' then
            begin
            B[Loop]:=A[1] * A[3]
            end
            else
                If Input='=A1 * A4' then
                begin
                B[Loop]:=A[1] * A[4]
                end
                else
                    If Input='=A2 * A1' then
                    begin
                    B[Loop]:=A[2] * A[1]
                    end
                    else
                        If Input='=A2 * A3' then
                        begin
                        B[Loop]:=A[2] * A[3]
                        end
                        else
                            If Input='=A2 * A4' then
                            begin
                            B[Loop]:=A[2] * A[4]
                            end
                            else
                                If Input='=A3 * A1' then
                                begin
                                B[Loop]:=A[3] * A[1]
                                end
                                else
                                    If Input='=A3 * A2' then
                                    begin
                                    B[Loop]:=A[3] * A[2]
                                    end
                                    else
                                        If Input='=A3 * A4' then
                                        begin
                                        B[Loop]:=A[3] * A[4]
                                        end
                                        else
                                            If Input='=A4 * A1' then
                                            begin
                                            B[Loop]:=A[4] * A[1]
                                            end
                                            else
                                                If Input='=A4 * A2' then
                                                begin
                                                B[Loop]:=A[4] * A[2]
                                                end
                                                else
                                                    If Input='=A4 * A3' then
                                                    begin
                                                    B[Loop]:=A[4] * A[3]
                                                    end
                                                    else
        
        If Input='=B1 + B2' then
        begin
        B[Loop]:=B[1] +B[2]
        end
        else
            If Input='=B1 + B3' then
            begin
            B[Loop]:=B[1] + B[3]
            end
            else
                If Input='=B1 + B4' then
                begin
                B[Loop]:=B[1] + B[4]
                end
                else
                    If Input='=B2 + B1' then
                    begin
                    B[Loop]:=B[2] + B[1]
                    end
                    else
                        If Input='=B2 + B3' then
                        begin
                        B[Loop]:=B[2] + B[3]
                        end
                        else
                            If Input='=B2 + B4' then
                            begin
                            B[Loop]:=B[2] + B[4]
                            end
                            else
                                If Input='=B3 + B1' then
                                begin
                                B[Loop]:=B[3] + B[1]
                                end
                                else
                                    If Input='=B3 + B2' then
                                    begin
                                    B[Loop]:=B[3] + B[2]
                                    end
                                    else
                                        If Input='=B3 + B4' then
                                        begin
                                        B[Loop]:=B[3] + B[4]
                                        end
                                        else
                                            If Input='=B4 + B1' then
                                            begin
                                            B[Loop]:=B[4] + B[1]
                                            end
                                            else
                                                If Input='=B4 + B2' then
                                                begin
                                                B[Loop]:=B[4] + B[2]
                                                end
                                                else
                                                    If Input='=B4 + B3' then
                                                    begin
                                                    B[Loop]:=B[4] + B[3]
                                                    end
                                                    else

        If Input='=B1 - B2' then
        begin
        B[Loop]:=B[1] - B[2]
        end
        else
            If Input='=B1 - B3' then
            begin
            B[Loop]:=B[1] - B[3]
            end
            else
                If Input='=B1 - B4' then
                begin
                B[Loop]:=B[1] - B[4]
                end
                else
                    If Input='=B2 - B1' then
                    begin
                    B[Loop]:=B[2] - B[1]
                    end
                    else
                        If Input='=B2 - B3' then
                        begin
                        B[Loop]:=B[2] - B[3]
                        end
                        else
                            If Input='=B2 - B4' then
                            begin
                            B[Loop]:=B[2] - B[4]
                            end
                            else
                                If Input='=B3 - B1' then
                                begin
                                B[Loop]:=B[3] - B[1]
                                end
                                else
                                    If Input='=B3 - B2' then
                                    begin
                                    B[Loop]:=B[3] - B[2]
                                    end
                                    else
                                        If Input='=B3 - B4' then
                                        begin
                                        B[Loop]:=B[3] - B[4]
                                        end
                                        else
                                            If Input='=B4 - B1' then
                                            begin
                                            B[Loop]:=B[4] - B[1]
                                            end
                                            else
                                                If Input='=B4 - B2' then
                                                begin
                                                B[Loop]:=B[4] - B[2]
                                                end
                                                else
                                                    If Input='=B4 - B3' then
                                                    begin
                                                    B[Loop]:=B[4] - B[3]
                                                    end
                                                    else
        If Input='=B1 * B2' then
        begin
        B[Loop]:=B[1] * B[2]
        end
        else
            If Input='=B1 * B3' then
            begin
            B[Loop]:=B[1] * B[3]
            end
            else
                If Input='=B1 * B4' then
                begin
                B[Loop]:=B[1] * B[4]
                end
                else
                    If Input='=B2 * B1' then
                    begin
                    B[Loop]:=B[2] * B[1]
                    end
                    else
                        If Input='=B2 * B3' then
                        begin
                        B[Loop]:=B[2] * B[3]
                        end
                        else
                            If Input='=B2 * B4' then
                            begin
                            B[Loop]:=B[2] * B[4]
                            end
                            else
                                If Input='=B3 * B1' then
                                begin
                                B[Loop]:=B[3] * B[1]
                                end
                                else
                                    If Input='=B3 * B2' then
                                    begin
                                    B[Loop]:=B[3] * B[2]
                                    end
                                    else
                                        If Input='=B3 * B4' then
                                        begin
                                        B[Loop]:=B[3] * B[4]
                                        end
                                        else
                                            If Input='=B4 * B1' then
                                            begin
                                            B[Loop]:=B[4] * B[1]
                                            end
                                            else
                                                If Input='=B4 * B2' then
                                                begin
                                                B[Loop]:=B[4] * B[2]
                                                end
                                                else
                                                    If Input='=B4 * B3' then
                                                    begin
                                                    B[Loop]:=B[4] * B[3]
                                                    end
                                                    else
                                                        begin
                                                        Val(Input,Input2,Flag);
                                                        B[Loop]:=Input2;
                                                        end;

     end;
End;

Procedure RC;
Begin
     For Loop:=1 to 5 do
     begin
     Readln(InputFile,Input);
     Val(Input,Input2,Flag);
     C[Loop]:=Input2;
     end;
End;

Procedure RD;
Begin
     For Loop:=1 to 5 do
     begin
     Readln(InputFile,Input);
     Val(Input,Input2,Flag);
     D[Loop]:=Input2;
     end;
End;

Procedure RE;
Begin
     For Loop:=1 to 5 do
     begin
     Readln(InputFile,Input);
     Val(Input,Input2,Flag);
     E[Loop]:=Input2;
     end;
End;

Procedure WA;
begin
     For Loop:=1 to 5 do
     begin
     Writeln(OutputFile,A[Loop]);
     end;
End;
Procedure WB;
begin
     For Loop:=1 to 5 do
     begin
     Writeln(OutputFile,B[Loop]);
     end;
End;

Procedure WC;
begin
     For Loop:=1 to 5 do
     begin
     Writeln(OutputFile,C[Loop]);
     end;
End;

Procedure WD;
begin
     For Loop:=1 to 5 do
     begin
     Writeln(OutputFile,D[Loop]);
     end;
End;

Procedure WE;
begin
     For Loop:=1 to 5 do
     begin
     Writeln(OutputFile,E[Loop]);
     end;
End;

begin
Randomize;
Assign(InputFile,'Data5.txt');
Assign(OutputFile,'Out5.txt');
Reset(InputFile);
Rewrite(OutputFile);

For Loop:= 1 to 5 do
begin
A[Loop]:=0;
B[Loop]:=0;
C[Loop]:=0;
D[Loop]:=0;
E[Loop]:=0;
end;

RA;
RB;
RC;
RD;
RE;
WA;
WB;
WC;
WD;
WE;
Close(OutputFile);
End.

