#include <iostream>
#include <cassert>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>

namespace {
  
int operate(char op, int arg1, int arg2)
{
  switch (op) {
  case ')':
  case '=': return arg1;
  case '+': return arg1 + arg2;
  case '-': return arg1 - arg2;
  case '*': return arg1 * arg2;
  case '/': assert(arg2 != 0); return arg1 / arg2;
  }
  assert(0);
}

int evaluate(std::string& str, size_t first, size_t last)
{
  size_t current = 0;
  std::vector<int> arg;
  std::vector<char> op;

  arg.push_back(0);
  
  for (size_t pos = first; pos <= last; ) {
  	
    // 数字
    if (isdigit(str[pos])) {
      arg[current] = (arg[current] * 10) + (str[pos] - '0');
       ++pos;
      continue;
    }

    // 括弧
    if (str[pos] == '(') {
      size_t paren_end = pos + 1;
      int nest = 0;

      // 括弧に対応する閉じ括弧の場所を検索
      for (; paren_end <= last; ++paren_end) {
        if (str[paren_end] == ')') {
          if (!nest) break;
          else --nest;
        }
        else if (str[paren_end] == '(') {
          ++nest;
        }
      }

      assert(paren_end != last + 1);
      arg[current] = evaluate(str, pos + 1, paren_end);
      pos = paren_end + 1;
      continue;
    }

    // 演算子
    op.push_back(char(str[pos]));
    if (current == 0) {
      ++current;
      arg.push_back(0);
      ++pos;
      continue;
    }

    if (op[current - 1] == '*' || op[current - 1] == '/') {
      arg[current - 1] = operate(op[current - 1], arg[current - 1], arg[current]);
      op[current - 1] = op[current];
      arg[current] = 0;
      op.pop_back();
    } 
    else {
      ++current;
      arg.push_back(0);
    }
    ++pos;
  }
  
  // + -
  
  for (size_t i = 1; i < current; ++i) {
  	arg[0] = operate(op[i - 1], arg[0], arg[i]);
  }
  
  return arg[0];
}

} // unnamed namespace

int main()
{
  int n;
  std::cin >> n;
  
  for (int i = 0; i < n; ++i) {
    std::string exp;
    std::cin >> exp;

    std::cout << evaluate(exp, 0, exp.size()) << std::endl;
  }

  return 0;
}