def priority_calculator(array)
  result = array.shift.to_i
  while array.size > 0
    result = result.method(array.shift.to_sym).call(array.shift.to_i)
  end
  return result
end
def subordinate_calculator(array)
  result = array.shift.to_i
  while array.size > 0
    result = result.method(array.shift.to_sym).call(array.shift.to_i)
  end
  return result
end
def sinple_calculator(string)
  reg = /\d+[\*\/]\d+([\*\/]\d+)*+/
  while string.match(/[\*\/]/)
    string.gsub!(reg){|matched|
      priority_calculator(matched.scan(/\d+|\D/))
    }
  end
  return subordinate_calculator(string.scan(/\d+|\D/))
end
def smartcalculator(string)
  reg = /\([^()]+?\)/
  while string.match(/[()]/)
    string.gsub!(reg){|matched|
      sinple_calculator(matched[1...-1])
    }
  end
  return sinple_calculator(string)
end
def main(input = STDIN)
  input.gets.to_i.times do
    puts smartcalculator(input.gets.chomp[0...-1])
  end
end
main