#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

int expression(string &s,int &pos);


int factor(string &s,int &pos){
	if(s[pos]=='('){
		pos++;
		int ret=expression(s,pos);
		assert(s[pos]==')');
		pos++;
		return ret;
	}else{
		assert(isdigit(s[pos]));
		int ret=s[pos]-'0';
		pos++;
		while(isdigit(s[pos])){
			ret*=10;
			ret+=s[pos]-'0';
			pos++;
		}
		return ret;
	}
}

int term(string &s,int &pos){
	int ret=factor(s,pos);
	while(s[pos]=='*'||s[pos]=='/'){
		char op=s[pos];
		pos++;
		if(op=='*'){
			ret*=factor(s,pos);
		}else{
			ret/=factor(s,pos);
		}
	}
	return ret;
}

int expression(string &s,int &pos){
	int ret=term(s,pos);
	while(s[pos]=='+'||s[pos]=='-'){
		char op=s[pos];
		pos++;
		if(op=='+'){
			ret+=term(s,pos);
		}else{
			ret-=term(s,pos);
		}
	}
	return ret;
}

int main(){
	int n;
	cin>>n;
	REP(i,n){
		string s;
		cin>>s;
		int pos=0;
		int ans=expression(s,pos);
		assert(s[pos]=='=');
		cout<<ans<<endl;
	}
}