

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <complex>
#include <cctype>
#include <cassert>

using namespace std;

int n;
string S;
int cur;

int digit(){
	assert(isdigit(S[cur]));
	int n = S[cur] - '0';
	cur++;
	return n;
}

int number(){
	int n = digit();
	while(cur < S.size() && isdigit(S[cur])){
		n = n * 10 + digit();
	}
	return n;
}

int expression();
int factor(){
	if (S[cur] != '(') return number();
	cur++;
	int n = expression();
	cur++;
	return n;	
}

int term(){
	int sum = factor();
	while(cur < S.size() && (S[cur] == '*' || S[cur] == '/')){
		char op = S[cur];
		cur++;
		int b = factor();
		if(op == '*') sum *= b;
		else sum /= b;
	}
	return sum;
}

int expression(){
	int sum = term();
	while(cur < S.size() && (S[cur] == '+' || S[cur] == '-')){
		char op = S[cur];
		cur++;
		int b = term();
		if(op == '+') sum += b;
		else sum -= b;
	}
	return sum;
	
}


int main(void){

	cin >> n;

	for(int i = 0; i < n; i++){
		cur = 0;
		cin >> S;
		S.resize(S.size()-1);
		cout << expression() << endl;
	}
	
    return 0;
}