$str = ''
$pos = 0

def exp()
  #puts "exp():#{$pos}"

  ret = term();
  while true
    ch = $str[$pos]
    $pos += 1
    if ch == '+'
      ret += term()
    elsif ch == '-'
      ret -= term()
    else
      break;
    end
  end

  return ret
end

def term()
  #puts "term():#{$pos}"

  ret = elm()
  while true
    case $str[$pos]
    when '*'
      $pos += 1
      ret *= elm()
    when '/'
      $pos += 1
      ret /= elm()
    else
      break
    end
  end

  return ret
end

def elm()
  #puts "elm():#{$pos}"

  ch = $str[$pos]
  $pos += 1

  return exp() if ch == '('
  return -elm() if ch == '-'
  return elm() if ch == '+'

  x = ch.ord - '0'.ord
  while /\d/ =~ $str[$pos]
    x = 10 * x + ($str[$pos].ord - '0'.ord)
    $pos += 1
  end

  return x
end

### main

n = gets.chomp.to_i

n.times.each do
  $str = gets.chomp
  $pos = 0
  #p str
  num = exp()
  puts num
end