//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 1000000


int ar[2][14];
int main(){
	string str;
	int N;
	cin>>N;
	VI res;
	stack <string>st;
	REP(ii,N){
		cin>>str;
		priority_queue<pair<int,char> > buf;
		priority_queue<pair<int,char> > buf2;
		
		bool ch=false;
		int t=0;
		string temp="";
		REP(i,SZ(str)){
			if(str[i]=='+'||str[i]=='-'){
				if((!ch&&(buf.empty()||(buf.top()).first<i))||(ch&&(buf2.empty()||(buf2.top()).first<i))){
					if(!ch)buf.push(MP(i,str[i]));
					else buf2.push(MP(i,str[i]));
				}else{
					if(!ch){
						temp+=(buf.top()).second;
						buf.pop();
						buf.push(MP(i,str[i]));
					}else{
						temp+=(buf2.top()).second;
						buf2.pop();
						buf2.push(MP(i,str[i]));
					}
				}
			}else if(str[i]=='*'||str[i]=='/'){
				if(!ch){
					buf.push(MP(300-i,str[i]));
				}else{
					buf2.push(MP(300-i,str[i]));
				}
			}else if(str[i]=='('){
				ch=true;
			}else if(str[i]==')'){
				while(!buf2.empty()){
					temp+=(buf2.top()).second;
					buf2.pop();
				}
				ch=false;
			}else if(str[i]=='='){
				while(!buf.empty()){
					temp+=(buf.top()).second;
					buf.pop();
				}
			}else if(str[i]>='0'&&str[i]<='9'){
				if(i+1<SZ(str)&&str[i+1]>='0'&&str[i+1]<='9'){
					t+=(unsigned int)(str[i]-'0');
					t*=10;
				}else{
					t+=(unsigned int)(str[i]-'0');
					//cout<<t<<endl;
					temp+=toString(t);
					t=0;
				}
			}
		}
		stack <int> st;
		REP(i,SZ(temp)){
			if(temp[i]>='0'&&temp[i]<='9'){
				st.push((unsigned int)(temp[i]-'0'));
			}else if(temp[i]=='+'){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t1+t2);
			}else if(temp[i]=='-'){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t2-t1);
			}else if(temp[i]=='*'){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t2*t1);
			}else if(temp[i]=='/'){
				int t1=st.top();
				st.pop();
				int t2=st.top();
				st.pop();
				st.push(t2/t1);
			}
		}
		res.PB(st.top());
	}
	REP(i,N)cout<<res[i]<<endl;
	return 0;
}

//5+4*3+2/6=
//(1+4)*(3+7)/5=
//5+4-3=
//(1+5)*(2+3)=