#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>

using namespace std;
string analyze(string in)
{
    stringstream i(in);
    stringstream j(in);
    int lop;
    j >> lop;
    stringstream k;
    k << lop;
    stringstream o;
    if (k.str() == i.str())
    {
        return in;
    }
    int endb = 0;
    for(int z = in.size()-1; z >=0; z--)
    {
        if (in[z] == ')')
        {
            endb = z;
        }
        if(in[z] == '(')
        {

            for (int y = 0; y < z; y++)
            {
                o << in[y];
            }
            o << analyze(in.substr(z+1,endb-z-1));
            for (int y = endb+1; y < in.size(); y++)
            {
                o << in[y];
            }
            return analyze(o.str());
        }
    }
    for(int z = in.size()-1; z >=0; z--)
    {
        if (in[z] == '^')
        {
            endb = z;
        //read left operand
        int uio = z;
        while(uio>0 && (in[uio] == '-' || (in[uio] > 47 && in[uio] < 58) )) uio--;
        stringstream temp;
        temp << in.substr(uio+1, z-uio-1);
        int lop;
        temp >> lop;
        //get right operand;
        temp.str().clear();
        temp << in.substr(z+1, in.size()-1-z);
        int rop =0;
        temp >> rop;
        temp.str().clear();
        temp << abs(lop) << abs(rop);
        stringstream ooo;
        ooo << rop;
       return analyze(in.substr(0, uio) + temp.str() + in.substr(ooo.str().size()+z+1, in.size()-ooo.str().size()-z-1));
        }
    }
    for(int z = in.size()-1; z >=0; z--)
    {
        if (in[z] == '*')
        {
            endb = z;
        //read left operand
        int uio = z;
        while((in[uio] == '-' || (in[uio] > 47 && in[uio] < 58) ) && uio >0) uio--;
        stringstream temp;
        temp << in.substr(uio+1, z-uio-1);
        int lop;
        //get right operand;
        temp >> lop;
        temp.str().clear();
        stringstream sex;
        sex << in.substr(z+1, in.size()-z);
        int rop =0;
        sex >> rop;
        stringstream fuck;
        fuck << (lop* rop);
        stringstream ooo;
        ooo << rop;
        return analyze(in.substr(0, uio) + fuck.str() + in.substr(ooo.str().size()+z, in.size()-ooo.str().size()-z));
        }
    }
    for(int z = in.size()-1; z >=0; z--)
    {
        if (in[z] == '/')
        {
            endb = z;
        //read left operand
        int uio = z;
        while((in[uio] == '-' || (in[uio] > 47 && in[uio] < 58) ) && uio >0) uio--;
        stringstream temp;
        temp << in.substr(uio+1, z-uio-1);
        int lop;
        temp >> lop;
        //get right operand;
        temp.str().clear();
        temp << in.substr(z+1, in.size()-1-z);
        int rop =0;
        temp >> rop;
        temp.str().clear();
        temp << lop/rop;
        stringstream ooo;
        ooo << rop;
       return analyze(in.substr(0, uio) + temp.str() + in.substr(ooo.str().size()+z+1, in.size()-ooo.str().size()-z-1));
        }
    }
    for(int z = in.size()-1; z >=0; z--)
    {
        if (in[z] == '+')
        {
            endb = z;
        //read left operand
        int uio = z;
        while((in[uio] == '-' || (in[uio] > 47 && in[uio] < 58) ) && uio >0) uio--;
        stringstream temp;
        temp << in.substr(uio+1, z-uio-1);
        int lop;
        temp >> lop;
        //get right operand;
        temp.str().clear();
        temp << in.substr(z+1, in.size()-1-z);
        int rop =0;
        temp >> rop;
        temp.str().clear();
        temp << lop+ rop;
        stringstream ooo;
        ooo << rop;
       return analyze(in.substr(0, uio) + temp.str() + in.substr(ooo.str().size()+z+1, in.size()-ooo.str().size()-z-1));
        }
    }

    for(int z = in.size()-1; z >=0; z--)
    {
        if (in[z] == '-')
        {
            endb = z;
        //read left operand
        int uio = z;
        while((in[uio] == '-' || (in[uio] > 47 && in[uio] < 58) ) && uio >0) uio--;
        stringstream temp;
        temp << in.substr(uio+1, z-uio-1);
        int lop;
        temp >> lop;
        //get right operand;
        temp.str().clear();
        temp << in.substr(z+1, in.size()-1-z);
        int rop =0;
        temp >> rop;
        temp.str().clear();
        temp << lop- rop;
        stringstream ooo;
        ooo << rop;
       return analyze(in.substr(0, uio) + temp.str() + in.substr(ooo.str().size()+z+1, in.size()-ooo.str().size()-z-1));
        }
    }
    if (o.str().size()==0)
    {
        return in;
    }
    else return o.str();
}
int main()
{
    freopen("DATA4.txt", "r", stdin);
    freopen("OUT4.txt", "w", stdout);
    for (int i = 0; i < 5; i++)
    {
        string in;
        getline(cin,in);
        string sin;
        for(int j = 0; j < in.size(); j++)
        {
            if(in[j] == ' ')
            {
            }
            else
            {
                sin.push_back(in[j]);
            }
        }
        cout << analyze(sin) << endl;
    }
    return 0;
}

