#include <cstdlib>
#include <iostream>
#include <sstream>
#include <stack>
#include <fstream>
using namespace std;
stack<int> vals;
stack<int> ops;
const string order = "^/*-+(";
#define isNum(a) ((a)<='9'&&(a)>='0')

#define debug cout
char* readNum(char*it){
      bool neg = false;
      if(*it == '-'){neg=true;it++;}
      while(not isNum(*it))++it;
      int cur = *it -'0';
      for( ++it;isNum(*it);++it)cur=cur*10+*it-'0';
      if(neg) cur= -cur;
     // debug<<"read "<<cur<<endl;
      vals.push(cur);
      return it;
}
void evalTop(){
     if(ops.empty())debug<<"no ops";
     if(vals.size()< 2)debug<<"not enough vals";
     int b = vals.top();vals.pop();
     int a = vals.top();vals.pop();
     char op = order[ops.top()];ops.pop();
     if(op=='+')a+=b;
     if(op=='-')a-=b;
     if(op=='*')a*=b;
     if(op=='/')a/=b;
     if(op=='('||op==')')debug<<"Evaluated bracket";
     if(op=='^'){
           stringstream ss;
           ss<<abs(a)<<abs(b);
           stringstream iss(ss.str());
           iss>>a;  
              
     }
     vals.push(a);
}

int main(int argc, char *argv[])
{
     ifstream fin("DATA4.txt",ifstream::in);
     ofstream fout("OUT4.txt",ofstream::out);
    //freopen("OUT4.txt","w",stdout);
    int t;
    for(t=5;t--;){
         string str; getline(fin,str);
        // cout<<str<<endl;
         bool lastWasOp = true;
         while(vals.size())vals.pop();
          while(ops.size())ops.pop();
         for(char*it=(char*)str.c_str();*it;++it){
                // puts(it);
                // if(ops.size()) debug<<"op: "<<order[ops.top()];
                // if(vals.size()) debug<<"vals: "<<vals.top();
                // debug<<endl;
                 if(*it==' ')continue;
                 int a=order.find(*it);
                 if(*it == '('){
                        ops.push(a);
                        lastWasOp =true;
                 }
                 else if(*it==')'){
                      int match = order.find('(');
                        while(ops.size()&&ops.top() != match)
                                evalTop();
                       // if(ops.empty())debug<<"unmatched bracket";
                        ops.pop();
                        lastWasOp =false;
                 }
                 else if(a!= string::npos){
                          if(lastWasOp){
                                  it=readNum(it)-1;
                                  lastWasOp = false; 
                          }
                          else{
                               while(ops.size()&&ops.top() <= a)
                                    evalTop();
                               ops.push(a);
                               lastWasOp =true;
                          }                     
                 }
                 else if(isNum(*it)){
                      it=readNum(it)-1;
                      lastWasOp=false;
                 }   

         }
               while(ops.size())evalTop();    
         // cout<<vals.top()<<endl; 
          fout<<vals.top()<<endl;
                  
    }

    return EXIT_SUCCESS;
}

