// Original C++ solution (slower):
#include <bits/stdc++.h>



#define REP(i,n) for(int i=0;i<(int)(n);i++)



using namespace std;



const string lts = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";



pair<string, int> parse(const string &, int);



pair<string, int> letter(const string &s, int i) {

  if (i >= s.size()) throw "last";

  if (s[i] == '+') {

    auto res = letter(s, i+1);

    if (res.first[0] != 'Z')

      ++res.first[0];

    else

      res.first[0] = 'A';

    return res;

  } else if (s[i] == '-') {

    auto res = letter(s, i+1);

    if (res.first[0] != 'A')

      --res.first[0];

    else

      res.first[0] = 'Z';

    return res;

  }

  if ('A' <= s[i] && s[i] <= 'Z')

    return make_pair(string(1, s[i]), i+1);

  else

    throw "bad";

}



pair<string, int> str(const string &s, int i) {

  if (i >= s.size()) throw "last";

  if (s[i] == '[') {

    auto res = parse(s, i+1);

    reverse(begin(res.first),end(res.first));

    if (res.second >= s.size() || s[res.second] != ']') throw "bad";

    ++res.second;

    return res;

  }

  return letter(s, i);

}



pair<string, int> parse(const string &s, int i) {

  auto res = str(s, i);

  while(res.second < s.size() && s[res.second] != ']'){

    auto res2 = str(s, res.second);

    res.first += res2.first;

    res.second = res2.second;

  }

  return res;

}



string search(string &s, int i = 0) {

  if (i >= s.size()) {

    try {

      //cout<<s<<':';

      return parse(s, 0).first;

    } catch(...) {

      return "";

    }

  }

  if (s[i] != '?') return search(s, i+1);

  string res = "";

  for (char c:lts){

    if(!c) break;

    s[i] = c;

    string t = search(s, i+1);

    //cout<<t<<endl;

    if ((t != "" && t < res) || res == "") {

      res = t;

    }

  }

  s[i] = '?';

  return res;

}



int main() {

  while(1){

    string s;

    cin>>s;

    if(s==".") break;

    cout << search(s) << endl;

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



#define REP(i,n) for(int i=0;i<(int)(n);i++)



using namespace std;



pair<string, int> cipher(const string& s, int pos = 0);



pair<string, int> letter(const string& s, int pos) {

  if (s[pos] == '+') {

    string res;

    tie(res, pos) = letter(s, pos+1);

    if (res == "?") {

      return make_pair(res, pos);

    } else if (res == "Z") {

      res[0] = 'A';

      return make_pair(res, pos);

    } else {

      ++res[0];

      return make_pair(res, pos);

    }

  } else if (s[pos] == '-') {

    string res;

    tie(res, pos) = letter(s, pos+1);

    if (res == "?") {

      return make_pair(res, pos);

    } else if (res == "A") {

      res[0] = 'Z';

      return make_pair(res, pos);

    } else {

      --res[0];

      return make_pair(res, pos);

    }

  } else {

    return make_pair(s.substr(pos, 1), pos+1);

  }

}



pair<string, int> string_p(const string& s, int pos) {

  if (s[pos] == '[') {

    string res;

    tie(res, pos) = cipher(s, pos+1);

    reverse(begin(res),end(res));

    return make_pair(res, pos+1);

  } else {

    return letter(s, pos);

  }

}



pair<string, int> cipher(const string& s, int pos) {

  string res;

  string str;

  do {

    tie(str, pos) = string_p(s, pos);

    res += str;

  } while(pos < s.size() && s[pos] != ']');

  return make_pair(res, pos);

}



string convert(const string& s) {

  auto p = cipher(s).first;

  replace(begin(p),end(p),'?','A');

  return p;

}



int main() {

  while(1){

    string s;

    cin>>s;

    if (s == ".") break;

    cout << convert(s) << endl;

  }

  return 0;

}

// Fastest known solution for this problem: