#include <string>
#include <iostream>
#include <cctype>
#include <cassert>
using namespace std;
int parse();
size_t cur = 0; // 解析開始位置
string S;

char readchar() {
  assert(cur < S.size());
  char ret = S[cur];
  cur += 1;
  return ret;
  // return S[cur++]; と一行で書くこともできる
}
char peek() { // 1 文字読むが cur を進めない
  assert(cur < S.size());
  return S[cur];
}

int digit() {
  assert(isdigit(peek())); // S[cur] が数字であることを確認
  int n = readchar() - '0'; // ’0’ を 0 に変換
  return n;
}

int number() {
  int n = digit();
  while (cur < S.size() && isdigit(peek())) // 次も数字か 1 文字先読
    n = n*10 + digit();
  return n;
}

int factor();
int term() {
  int a = factor();
  while (cur < S.size() && peek() != ')' && (peek() == '*' || peek() == '/')) {
    char op = readchar();
    int b = factor();
    if (op == '*') a *= b; else a /= b;
  }
  return a;
}

int expression(); // 前方宣言
int factor() {
  if (peek() != '(') return number();
  cur += 1;
  int n = expression();
  assert(peek() == ')');
  cur += 1;
  return n;
}

int expression() {
  int a = term();
  while (cur < S.size() && (peek() == '+' || peek() == '-')) { // 足し算か引き算が続く間
    char op = readchar();
    int b = term();
    if (op == '+') {
      a += b;
    }
    else
    {
      a -= b;
    }
  }
  return a;
}



int parse() { return expression(); }
int main() {
  int N;
  cin >> N;
  for (int i=0; i<N; ++i) {
    cur = 0;
    cin >> S;
    S.resize(S.size()-1); // 最後の=を無視
  cout << expression() << endl;
  }
}
