#include <iostream>
#include <algorithm>
using namespace std;

#ifndef HELLO_HPP_
#define HELLO_HPP_

// This file was automatically generated by Caper.
// (http://jonigata.github.io/caper/caper.html)

#include <cstdlib>
#include <cassert>
#include <vector>

namespace calc {

enum Token {
 token_eof,
 token_Add,
 token_Digit,
 token_Div,
 token_LBranket,
 token_Mul,
 token_RBranket,
 token_Sub,
};

inline const char* token_label(Token t) {
 static const char* labels[] = {
 "token_eof",
 "token_Add",
 "token_Digit",
 "token_Div",
 "token_LBranket",
 "token_Mul",
 "token_RBranket",
 "token_Sub",
 };
 return labels[t];
}

template <class T, unsigned int StackSize>
class Stack {
public:
 Stack() { gap_ = 0; }

 void rollback_tmp() {
 gap_ = stack_.size();
 tmp_.clear();
 }

 void commit_tmp() {
 // may throw
 stack_.reserve(gap_ + tmp_.size());
 
 // expect not to throw
 stack_.erase(stack_.begin()+ gap_, stack_.end());
 stack_.insert(stack_.end(), tmp_.begin(), tmp_.end());
 tmp_.clear();
 }
 bool push(const T& f) {
 if (StackSize != 0 &&
 int(StackSize) <= int(stack_.size() + tmp_.size())) {
 return false;
 }
 tmp_.push_back(f);
 return true;
 }
 
 void pop(size_t n) {
 if (tmp_.size() < n) {
 n -= tmp_.size();
 tmp_.clear();
 gap_ -= n;
 } else {
 tmp_.erase(tmp_.end() - n, tmp_.end());
 }
 }

 T& top() {
 assert(0 < depth());
 if (!tmp_.empty()) {
 return tmp_.back();
 } else {
 return stack_[gap_ - 1];
 }
 }
 
 const T& get_arg(size_t base, size_t index) {
 size_t n = tmp_.size();
 if (base - index <= n) {
 return tmp_[n - (base - index)];
 } else {
 return stack_[gap_ - (base - n) + index];
 }
 }
 
 void clear() {
 stack_.clear();
 tmp_.clear();
 gap_ = 0; 
 }
 
 bool empty() const {
 if (!tmp_.empty()) {
 return false;
 } else {
 return gap_ == 0;
 }
 }
 
 size_t depth() const {
 return gap_ + tmp_.size();
 }
 
 T& nth(size_t index) {
 if (gap_ <= index) {
 return tmp_[index - gap_];
 } else {
 return stack_[index];
 }
 }

 void swap_top_and_second() {
 int d = depth();
 assert(2 <= d);
 T x = nth(d - 1);
 nth(d - 1) = nth(d - 2);
 nth(d - 2) = x;
 }

private:
 std::vector<T> stack_;
 std::vector<T> tmp_;
 size_t gap_;
 
};

template <class _Value, class _SemanticAction,
 unsigned int _StackSize = 0>
class Parser {
public:
 typedef Token token_type;
 typedef _Value value_type;

 enum Nonterminal {
 Nonterminal_Expr,
 Nonterminal_Factor,
 Nonterminal_Number,
 Nonterminal_Term,
 };

public:
 Parser(_SemanticAction& sa) : sa_(sa) { reset(); }

 void reset() {
 error_ = false;
 accepted_ = false;
 clear_stack();
 rollback_tmp_stack();
 if (push_stack(0, value_type())) {
 commit_tmp_stack();
 } else {
 sa_.stack_overflow();
 error_ = true;
 }
 }

 bool post(token_type token, const value_type& value) {
 rollback_tmp_stack();
 error_ = false;
 while ((this->*(stack_top()->entry->state))(token, value))
 ; // may throw
 if (!error_) {
 commit_tmp_stack();
 } else {
 recover(token, value);
 }
 return accepted_ || error_;
 }

 bool accept(value_type& v) {
 assert(accepted_);
 if (error_) { return false; }
 v = accepted_value_;
 return true;
 }

 bool error() { return error_; }

private:
 typedef Parser<_Value, _SemanticAction, _StackSize> self_type;

 typedef bool (self_type::*state_type)(token_type, const value_type&);
 typedef int (self_type::*gotof_type)(Nonterminal);

 bool accepted_;
 bool error_;
 value_type accepted_value_;
 _SemanticAction& sa_;

 struct table_entry {
 state_type state;
 gotof_type gotof;
 bool handle_error;
 };

 struct stack_frame {
 const table_entry* entry;
 value_type value;
 int sequence_length;

 stack_frame(const table_entry* e, const value_type& v, int sl)
 : entry(e), value(v), sequence_length(sl) {}
 };

 Stack<stack_frame, _StackSize> stack_;

 bool push_stack(int state_index, const value_type& v, int sl = 0) {
 bool f = stack_.push(stack_frame(entry(state_index), v, sl));
 assert(!error_);
 if (!f) { 
 error_ = true;
 sa_.stack_overflow();
 }
 return f;
 }

 void pop_stack(size_t n) {
 stack_.pop(n);
 }

 stack_frame* stack_top() {
 return &stack_.top();
 }

 const value_type& get_arg(size_t base, size_t index) {
 return stack_.get_arg(base, index).value;
 }

 void clear_stack() {
 stack_.clear();
 }

 void rollback_tmp_stack() {
 stack_.rollback_tmp();
 }

 void commit_tmp_stack() {
 stack_.commit_tmp();
 }

 void recover(token_type, const value_type&) {
 }

 bool call_nothing(Nonterminal nonterminal, int base) {
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, value_type());
 }

 bool call_0_Identity(Nonterminal nonterminal, int base, int arg_index0) {
 int arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 int r = sa_.Identity(arg0);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_Combine(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 int arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 int arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 int r = sa_.Combine(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeAdd(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 int arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 int arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 int r = sa_.MakeAdd(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeSub(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 int arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 int arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 int r = sa_.MakeSub(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeDiv(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 int arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 int arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 int r = sa_.MakeDiv(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool call_0_MakeMul(Nonterminal nonterminal, int base, int arg_index0, int arg_index1) {
 int arg0; sa_.downcast(arg0, get_arg(base, arg_index0));
 int arg1; sa_.downcast(arg1, get_arg(base, arg_index1));
 int r = sa_.MakeMul(arg0, arg1);
 value_type v; sa_.upcast(v, r);
 pop_stack(base);
 int dest_index = (this->*(stack_top()->entry->gotof))(nonterminal);
 return push_stack(dest_index, v);
 }

 bool state_0(token_type token, const value_type& value) {
 switch(token) {
 case token_Digit:
 // shift
 push_stack(/*state*/ 16, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 2, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_0(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Expr: return 1;
 case Nonterminal_Term: return 3;
 case Nonterminal_Factor: return 9;
 case Nonterminal_Number: return 14;
 default: assert(0); return false;
 }
 }

 bool state_1(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 // accept
 accepted_ = true;
 accepted_value_ = get_arg(1, 0);
 return false;
 case token_Add:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_Sub:
 // shift
 push_stack(/*state*/ 7, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_1(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_2(token_type token, const value_type& value) {
 switch(token) {
 case token_Digit:
 // shift
 push_stack(/*state*/ 16, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 2, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_2(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Expr: return 4;
 case Nonterminal_Term: return 3;
 case Nonterminal_Factor: return 9;
 case Nonterminal_Number: return 14;
 default: assert(0); return false;
 }
 }

 bool state_3(token_type token, const value_type& value) {
 switch(token) {
 case token_Div:
 // shift
 push_stack(/*state*/ 12, value);
 return false;
 case token_Mul:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_eof:
 case token_Add:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_Identity(Nonterminal_Expr, /*pop*/ 1, 0);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_3(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_4(token_type token, const value_type& value) {
 switch(token) {
 case token_Add:
 // shift
 push_stack(/*state*/ 5, value);
 return false;
 case token_RBranket:
 // shift
 push_stack(/*state*/ 15, value);
 return false;
 case token_Sub:
 // shift
 push_stack(/*state*/ 7, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_4(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_5(token_type token, const value_type& value) {
 switch(token) {
 case token_Digit:
 // shift
 push_stack(/*state*/ 16, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 2, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_5(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Term: return 6;
 case Nonterminal_Factor: return 9;
 case Nonterminal_Number: return 14;
 default: assert(0); return false;
 }
 }

 bool state_6(token_type token, const value_type& value) {
 switch(token) {
 case token_Div:
 // shift
 push_stack(/*state*/ 12, value);
 return false;
 case token_Mul:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_eof:
 case token_Add:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_MakeAdd(Nonterminal_Expr, /*pop*/ 3, 0, 2);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_6(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_7(token_type token, const value_type& value) {
 switch(token) {
 case token_Digit:
 // shift
 push_stack(/*state*/ 16, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 2, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_7(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Term: return 8;
 case Nonterminal_Factor: return 9;
 case Nonterminal_Number: return 14;
 default: assert(0); return false;
 }
 }

 bool state_8(token_type token, const value_type& value) {
 switch(token) {
 case token_Div:
 // shift
 push_stack(/*state*/ 12, value);
 return false;
 case token_Mul:
 // shift
 push_stack(/*state*/ 10, value);
 return false;
 case token_eof:
 case token_Add:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_MakeSub(Nonterminal_Expr, /*pop*/ 3, 0, 2);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_8(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_9(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_Div:
 case token_Mul:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_Identity(Nonterminal_Term, /*pop*/ 1, 0);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_9(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_10(token_type token, const value_type& value) {
 switch(token) {
 case token_Digit:
 // shift
 push_stack(/*state*/ 16, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 2, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_10(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Factor: return 11;
 case Nonterminal_Number: return 14;
 default: assert(0); return false;
 }
 }

 bool state_11(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_Div:
 case token_Mul:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_MakeMul(Nonterminal_Term, /*pop*/ 3, 0, 2);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_11(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_12(token_type token, const value_type& value) {
 switch(token) {
 case token_Digit:
 // shift
 push_stack(/*state*/ 16, value);
 return false;
 case token_LBranket:
 // shift
 push_stack(/*state*/ 2, value);
 return false;
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_12(Nonterminal nonterminal) {
 switch(nonterminal) {
 case Nonterminal_Factor: return 13;
 case Nonterminal_Number: return 14;
 default: assert(0); return false;
 }
 }

 bool state_13(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_Div:
 case token_Mul:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_MakeDiv(Nonterminal_Term, /*pop*/ 3, 0, 2);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_13(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_14(token_type token, const value_type& value) {
 switch(token) {
 case token_Digit:
 // shift
 push_stack(/*state*/ 17, value);
 return false;
 case token_eof:
 case token_Add:
 case token_Div:
 case token_Mul:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_Identity(Nonterminal_Factor, /*pop*/ 1, 0);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_14(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_15(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_Div:
 case token_Mul:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_Identity(Nonterminal_Factor, /*pop*/ 3, 1);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_15(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_16(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_Digit:
 case token_Div:
 case token_Mul:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_Identity(Nonterminal_Number, /*pop*/ 1, 0);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_16(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 bool state_17(token_type token, const value_type& value) {
 switch(token) {
 case token_eof:
 case token_Add:
 case token_Digit:
 case token_Div:
 case token_Mul:
 case token_RBranket:
 case token_Sub:
 // reduce
 return call_0_Combine(Nonterminal_Number, /*pop*/ 2, 0, 1);
 default:
 sa_.syntax_error();
 error_ = true;
 return false;
 }
 }

 int gotof_17(Nonterminal nonterminal) {
 assert(0);
 return true;
 }

 const table_entry* entry(int n) const {
 static const table_entry entries[] = {
 { &Parser::state_0, &Parser::gotof_0, false },
 { &Parser::state_1, &Parser::gotof_1, false },
 { &Parser::state_2, &Parser::gotof_2, false },
 { &Parser::state_3, &Parser::gotof_3, false },
 { &Parser::state_4, &Parser::gotof_4, false },
 { &Parser::state_5, &Parser::gotof_5, false },
 { &Parser::state_6, &Parser::gotof_6, false },
 { &Parser::state_7, &Parser::gotof_7, false },
 { &Parser::state_8, &Parser::gotof_8, false },
 { &Parser::state_9, &Parser::gotof_9, false },
 { &Parser::state_10, &Parser::gotof_10, false },
 { &Parser::state_11, &Parser::gotof_11, false },
 { &Parser::state_12, &Parser::gotof_12, false },
 { &Parser::state_13, &Parser::gotof_13, false },
 { &Parser::state_14, &Parser::gotof_14, false },
 { &Parser::state_15, &Parser::gotof_15, false },
 { &Parser::state_16, &Parser::gotof_16, false },
 { &Parser::state_17, &Parser::gotof_17, false },
 };
 return &entries[n];
 }

};

} // namespace calc

#endif // #ifndef HELLO_HPP_



class unexpected_char : public std::exception {};

class scanner {
public:
 using char_type = char;

private:
 string s;
 int pos;
public:
 scanner(string s) : s(s), pos(0) {}

 calc::Token get(int& v) {
 char c;
 do {
 c = getc();
 } while (isspace(c));
 // ?¨???????
 switch( c ) {
 case '+': return calc::token_Add;
 case '-': return calc::token_Sub;
 case '*': return calc::token_Mul;
 case '/': return calc::token_Div;
 case '(': return calc::token_LBranket;
 case ')': return calc::token_RBranket;
 case '=': return calc::token_eof;
 }

 // ??´??°
 if( isdigit( c ) ) {
 v = c - '0';
 return calc::token_Digit;
 }

 cerr << c << endl;
 throw unexpected_char();
 }

private:
 char_type getc() {
 if (pos == s.size()) return EOF;
 return s[pos++];
 }
};

struct SemanticAction {
 void syntax_error(){}
 void stack_overflow(){}
 void downcast( int& x, int y ) { x = y; }
 void upcast( int& x, int y ) { x = y; }

 int Identity( int n ) { return n; }
 int Combine(int x, int y) {
 return x*10 + y;
 }
 int MakeAdd(int x, int y) {
// cerr << "expr " << x << " + " << y << endl;
 return x + y; 
 }
 int MakeSub(int x, int y) {
// cerr << "expr " << x << " - " << y << endl;
 return x - y; 
 }
 int MakeMul(int x, int y) {
// cerr << "expr " << x << " * " << y << endl;
 return x * y;
 }
 int MakeDiv(int x, int y) {
// cerr << "expr " << x << " / " << y << endl;
 return x / y;
 }
};

int main() {
 int n;
 cin >> n; cin.ignore();
 for (int i = 0; i < n; i++) {
 string s;
 getline(cin, s);
 scanner scn(s);
 SemanticAction sa;
 calc::Parser<int, SemanticAction> parser(sa);
 calc::Token token;
 while (true) {
 int v;
 token = scn.get(v);
 if (parser.post(token, v)) { break; }
 }
 int v;
 if (parser.accept(v)) {
 cout << v << endl;
 }
 }
 return 0;
}