#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>

int parse_int(std::string const& s, size_t& i) {
  int res = s[i]-'0';
  while (isdigit(s[++i]))
    res = res*10 + s[i]-'0';
  return res;
}

int apply(int lhs, char op, int rhs) {
  if (op == '+') return lhs + rhs;
  if (op == '-') return lhs - rhs;
  if (op == '*') return lhs * rhs;
  if (op == '/') return lhs / rhs;
  assert(false);
}

const std::vector<std::string> ops = {"+-", "*/"};
int parse(std::string const& s, size_t& i, size_t preced = 0) {
  if (ops.size() == preced) {
    if (isdigit(s[i])) return parse_int(s, i);
    if (s[i] == '(') {
      int res = parse(s, ++i, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    assert(false);
  }
  int res = parse(s, i, preced+1);
  while (i < s.length()) {
    char op = s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    res = apply(res, op, parse(s, ++i, preced+1));
  }
  return res;
}

int main() {
  size_t n;
  scanf("%zu", &n);

  for (size_t i = 0; i < n; ++i) {
    char buf[1024];
    scanf("%s", buf);
    std::string s = buf;
    if (s.back() != '=') {
      printf("%s\n", s.c_str());
      continue;
    }

    size_t j = 0;
    printf("%d\n", parse(s, j));
  }
}

