#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

void calc(string st, stack<ll> &s) {	
	if(st == "*") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(a * b);
	} else if(st == "+") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(a + b);
	} else if(st == "-") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(b - a);
	} else if(st == "/") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(b / a);
	} else {
		s.push(atoi(st.c_str()));
	}
}
int getPriority(string s) {
	if(s == "(") {
		return 5;
	} else if(s == "*" || s == "/") {
		return 3;
	} else if(s == "+" || s == "-") {
		return 2;
	} else if(s == ")") { 
		return 1;
	} else return 4;
}

int main() {
	int n;
	cin >> n;
	while(n--) {
		string str;
		cin >> str;
		str.erase(--str.end());
		
		vector<string> v;
		
		int f = 0;
		rep(i, str.size()) {			
			if(isdigit(str[i])) {
				f++;
			} else {
				if(f) {
					string st;
					rep(j,f) {
						st += str[i - f + j];
					}
					v.push_back(st);
					string st2;
					st2 += str[i];
					v.push_back(st2);
					f = 0;
				} else {
					string st3;
					st3 += str[i];
					v.push_back(st3);
				}
			}
		}
		if(f) {
			string st;
			rep(j,f) {
				st += str[str.size() - f + j];
			}
			v.push_back(st);
		}

		stack<string> s;
		vector<string> nv;
		stack<ll> ret;
		int p = 0;
		rep(i,v.size()) {
			p = getPriority(v[i]);
			while(!s.empty() && getPriority(s.top()) > p && s.top() != "(") {
				nv.push_back(s.top());
				s.pop();
			}
			if(v[i] == ")") {
				s.pop();
			} else {
				s.push(v[i]);
			}
		}
		while(!s.empty()) {
			nv.push_back(s.top());
			s.pop();
		}
		rep(i,nv.size()) {
			calc(nv[i], ret);
		}
		cout << ret.top() << endl;
	}
	return 0;
}