#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define for(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define mp make_pair
#define x first
#define y second

using namespace std;

static const double eps = 1e-9;

typedef pair<int, int> p;
typedef long long ll;

template<class t>
inline t sq(t a){return a*a;}

int expr();
int fact();
int num();

//式 ::= 項 | 項+式 | 項-式
//項 ::= (式) | 因子*項 | 因子/項
//因子 ::= 数字
string s;
int ptr;
int expr(){
	int x = fact();
	if(s[ptr] == '+'){
		ptr++;
		x += expr();
	}else if(s[ptr] == '-'){
		ptr++;
		x -= expr();
	}
	return x;
}

int fact(){
	int x;
	if(s[ptr] == '('){
		ptr++;
		x = expr();
		ptr++;
	}else{
		x = num();
		if(s[ptr] == '*'){
			ptr++;
			x *= fact();
		}
		else if(s[ptr] == '/'){
			ptr++;
			x/= fact();
		}
	}
	return x;
}

int num(){
	int x = 0;
	while('0' <= s[ptr] && s[ptr] <= '9'){
		x *= 10;
		x += (s[ptr]-'0');
		ptr++;
	}
	return x;
}


int main(){
	int n;
	cin >> n;
	while(n--){
		cin >> s;
		ptr = 0;
		cout << expr() << endl;
	}

	return 0;
}