#include<iostream>
#include<algorithm>
using namespace std;
string s;
string rep="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int id;
char g();
string f()
{
	string ans="";
	while(id<s.size()&&s[id]!=']')
	{
		if(s[id]=='[')
		{
			id++;
			string t=f();
			id++;
			reverse(t.begin(),t.end());
			ans+=t;
		}
		else
		{
			ans+=g();
		}
	}
	return ans;
}
char g()
{
	if(s[id]=='+'||s[id]=='-')
	{
		bool f=s[id]=='+';
		id++;
		char a=g();
		if(a=='~')return a;
		else if(f)
		{
			return a<'Z'?a+1:'A';
		}
		else
		{
			return a>'A'?a-1:'Z';
		}
	}
	else
	{
		return s[id++];
	}
}
int main()
{
	while(cin>>s,s!=".")
	{
		string ans="~";
		int id1=-1,id2=-1,id3=-1;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='?')
			{
				if(id1<0)id1=i;
				else if(id2<0)id2=i;
				else id3=i;
			}
		}
		if(id1<0)
		{
			id=0;
			ans=f();
		}
		else
		{
			for(int i1=0;i1<rep.size();i1++)
			{
				s[id1]=rep[i1];
				if(id2<0)
				{
					id=0;
					ans=min(ans,f());
				}
				else
				{
					for(int i2=0;i2<rep.size();i2++)
					{
						s[id2]=rep[i2];
						if(id3<0)
						{
							id=0;
							ans=min(ans,f());
						}
						else
						{
							for(int i3=0;i3<rep.size();i3++)
							{
								s[id3]=rep[i3];
								id=0;
								ans=min(ans,f());
							}
						}
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}

