loop do
    s = gets.chomp
    break if s == ?.
    0 while s.gsub!(/\+\-|\-\+/, "")
    0 while s.gsub!(/\+([A-Z])/) { (?A.ord + ($1.ord - ?A.ord + 1) % 26).chr }
    0 while s.gsub!(/\-([A-Z])/) { (?A.ord + ($1.ord - ?A.ord + 25) % 26).chr }
    0 while s.gsub!(/\[([^\[\]]+?)\]/) { $1.scan(/[-+]*[A-Z?]/).reverse.join }
    puts s.gsub(/[-+]*\?/, ?A)
end