#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
//typedef pair<int, int> P;

/** Problem0109 : Smart Calculator **/
string s; int pos;
int factor();

int number()
{
	int ret=0;
	while (isdigit(s[pos])) {
		ret *= 10;
		ret += s[pos++]-'0';
	}
	return ret;
}

int term()
{
	int ret = number();
	
	for(;;) {
		if (s[pos] == '*') {
			pos++;
			ret *= factor();
		} else if (s[pos] == '/') {
			pos++;
			ret /= factor();
		} else {
			break;
		}
	}
	
	return ret;
}

int expression()
{
	int ret=term();
	
	for (;;) {
		if (s[pos] == '+') {
			pos++;
			ret += term();
		} else if (s[pos] == '-') {
			pos++;
			ret -= term();
		} else {
			break;
		}
	}
	
	return ret;
}

int factor()
{
	int ret;
	
	if (s[pos]=='(') {
		pos++;
		ret = expression();
		pos++;
	} else {
		ret = number();
	}
	return ret;
}

int main()
{
	int N; cin>>N;
	rep(i, N) {
		cin>>s;
		pos=0;
		cout << expression() << endl;
	}
}