#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

class Parser {
public:
	using Iter = string::const_iterator;
	Iter it;
	Parser(Iter it) :it(it) {}
	void cmp(char expected) { if (*it != expected)cerr << *it << " is not " << expected << endl; assert(*it == expected); }
	/*
	EBNF
	???=???,{('+'|'-'),???}; //??°???????????????????????¨??????????¨??????§?????????
	???=c,{('*'|'/'),c};
	c ='('???')' | integer;
	*/
	int a() {
		int ret = b();
		while (true) {
			if (*it == '+') {
				it++;
				ret += b();
			}
			else if (*it == '-') {
				it++;
				ret -= b();
			}
			else break;
		}
		return ret;
	}
	int b() {
		int ret = c();
		while (true) {
			if (*it == '*') {
				it++;
				ret *= c();
			}
			else if (*it == '/') {
				it++;
				ret /= c();
			}
			else break;
		}
		return ret;
	}
	int c() {
		int ret;
		if (*it == '(') {
			it++;
			ret = a();
			cmp(')');
			it++;
		}
		else ret = integer();
		return ret;
	}
	int integer() {
		int ret = 0;
		while (isdigit(*it)) {
			ret *= 10;
			ret += *it - '0';
			it++;
		}
		return ret;
	}
};

signed main() {
	int n; cin >> n; cin.ignore();
	for (string s; getline(cin, s) && s != "$"; ) {
		s += "$";
		Parser P(s.begin());
		cout << P.a() << endl;
	}
	return 0;
}