#include<iostream>
#include<vector>
#include<string>
using namespace std;

int Parse(string a) {
	int s = 0;
	for (int b = 0; b < a.length(); b++) {
		s *= 10;
		s += a[b] - 48;
	}
	return s;
}
int main() 
{
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) {
		vector<int>c;
		vector<char>d;
		string e;
		cin >> e; string g = "";
		for (int f = 0; f < e.length()-1; f++) {
			if (e[f]<'0' || e[f]>'9') { c.push_back(Parse(g)); g = ""; d.push_back(e[f]); }
			else g += e[f];
		}
		c.push_back(Parse(g));
		for (int o = 0; o < d.size(); o++) {
			if (d[o] == '*') {int q= c[o] * c[o + 1]; c[o + 1] =q; c[o] = q; }
			else if (d[o] == '/') { int q = c[o] / c[o + 1]; c[o + 1] = q; c[o] = q; }
		}
		int s = c[0];
		for (int k = 0; k < d.size(); k++) {
			if (d[k] == '+')s += c[k+1];
			else if (d[k] == '-')s -= c[k+1];
		}
		cout << s << endl;
	}
}