$VERBOSE = nil

class String
	def !@
		(?A.ord + (ord - ?A.ord + 1) % 26).chr
	end

	def -@
		(?A.ord + (ord - ?A.ord + 25) % 26).chr
	end

	def contract!
		k = size
		loop do
			0 while gsub!(/\+\-|\-\+/, "")
			0 while gsub!(/\+([A-Z])/){|x| !$1}
			0 while gsub!(/\-([A-Z])/){|x| -$1}

			gsub!(/\[([^\[\]]+?)\]/) do |x|
				$1.scan(/
					[-+]*[A-Z?]	
				/x).reverse.join
			end
			break if k == size
			k = size
		end
	end
end

loop do
	s = gets.chomp
	break if s == ?.
	s.contract!

	k = s.count(??)
	if k == 0
		puts s
	else
		a = []
		(?A..?Z).to_a.repeated_permutation(k) do |perm|
			e = s.dup
			perm.each do |c|
				e.sub!(/([\-\!]*)\?/){|x| eval($1 + "?" + c)}
			end
			a << e
		end	
		puts a.min
	end
end