#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int digits(auto& i) {
  int res = 0;
  while (isdigit(*i)) res = 10 * res + *i++ - '0';
  return res;
}
int expr(auto& i);
int num(auto& i) {
  switch (*i) {
    case '+': return num(++i);
    case '-': return -num(++i);
    case '(': {
      int res = expr(++i);
      return ++i, res;
    }
    default: return digits(i);
  }
}
int term(auto& i) {
  int res = num(i);
  while (true) switch (*i) {
    case '*': res *= num(++i); break;
    case '/': res /= num(++i); break;
    default: return res;
  }
}
int expr(auto& i) {
  int res = term(i);
  while (true) switch (*i) {
    case '+': res += term(++i); break;
    case '-': res -= term(++i); break;
    default: return res;
  }
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  while (n--) {
    string s; cin >> s;
    auto i = begin(s);
    cout << expr(i) << '\n';
  }
}
