
import std.stdio, std.ascii, std.array, std.string;

alias int function(int, int) Op;

enum Type {LParen, RParen, Plus, Minus, Multi, Div, Number, Equal}

struct Token {
  Type type;
  union V {
    int number;
    Op op;
  }
  V variant;
}

Token[char] table;
Token[] state;

static this() {
  table =
    ['+': Token(Type.Plus),
     '-': Token(Type.Minus),
     '*': Token(Type.Multi),
     '/': Token(Type.Div),
     '(': Token(Type.LParen),
     ')': Token(Type.RParen),
     '=': Token(Type.Equal)];
  
  table['+'].variant.op = (x, y) => x + y;
  table['-'].variant.op = (x, y) => x - y;
  table['*'].variant.op = (x, y) => x * y;
  table['/'].variant.op = (x, y) => x / y;
}

Token[] tokenize(string str) {
  Token[] tokens;
  int i = 0;
  while(str.length > i) {
    if (isDigit(str[i])) {
      Token token;
      int number = 0;
      do {
        number = 10 * number + (str[i] - '0');
      } while(isDigit(str[++i]));
      token.type = Type.Number;
      token.variant.number = number;
      tokens ~= token;
    }
    else {
      tokens ~= table[str[i++]];
    }    
  }
  return tokens;
}

Token[] expect(Token[] tokens, Type type) {  
  if (tokens[0].type != type) throw new Exception("unexpected token.");
  else
    return tokens[1..$];
}

void operate(Token token) {
  Token a = state.back; state.popBack;
  Token b = state.back; state.popBack;
  assert(a.type == Type.Number && b.type == Type.Number);
  Token t;
  t.type = Type.Number;
  t.variant.number = token.variant.op(b.variant.number, a.variant.number);
  state ~= t;
}

Token[] factor(Token[] tokens) {
  switch(tokens[0].type) {
  case Type.Number:
    state ~= tokens.front;
    tokens.popFront;
    break;
  case Type.LParen:
    tokens.popFront;
    tokens = expect(expression(tokens), Type.RParen);
    break;
  default:
    throw new Exception("error occured");
    break;
  }
  return tokens;
}

Token[] term(Token[] tokens) {
  tokens = factor(tokens);
  while(tokens[0].type == Type.Multi ||
        tokens[0].type == Type.Div) {
    Token front = tokens.front;
    tokens.popFront;
    tokens = factor(tokens);
    operate(front);
  }
  return tokens;
}

Token[] expression(Token[] tokens) {
  tokens = term(tokens);
  while(tokens[0].type == Type.Plus ||
        tokens[0].type == Type.Minus) {
    Token front = tokens.front;
    tokens.popFront;
    tokens = term(tokens);
    operate(front);
  }
  return tokens;
}

alias expression parse;

int eval(string line) {
  state = [];
  parse(line.tokenize);
  return state[0].variant.number;
}

void main() {
  int times;
  readf("%d\n", &times);
  foreach(t; 0..times) {
    readln.chomp.eval.writeln;
  }
}