#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class range {
private:
  struct Iterator {
    int val, inc;
    int operator*() {return val;}
    bool operator!=(Iterator& itr) {return val != itr.val;}
    void operator++() {val += inc;}
  };
  Iterator i, n;
public:
  range(int n) : i({0, 1}), n({n, 1}) {}
  range(int i, int n) : i({i, 1}), n({n, 1}) {}
  range(int i, int inc, int n) : i({i, inc}), n({n, inc}) {}
  Iterator& begin() {return i;}
  Iterator& end() {return n;}
};

template<class T> inline T at(const vector<T> &v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

template<class T> inline bool is_max(T &a, const T &b) {return a < b ? a = b, true : false;}
template<class T> inline bool is_min(T &a, const T &b) {return a > b ? a = b, true : false;}

class Parser {
private:
  string s;
  long long p;
  
  string factor() {
    string res;
    if (s[p] == '[') {
      ++p;
      res = expr();
      ++p;
      reverse(res.begin(), res.end());
      return res;
    }
    while (isalpha(s[p])) res += s[p++];
    return res;
  }
  
  string expr() {
    string res;
    while (true) {
      if (s[p] == '+') {
        ++p;
        string f = expr();
        if (f[0] == 'Z') f[0] = 'A';
        else ++f[0];
        res += f;
      } else if (s[p] == '-') {
        ++p;
        string f = expr();
        if (f[0] == 'A') f[0] = 'Z';
        else --f[0];
        res += f;
      } else if (isalpha(s[p]) || s[p] == '[') {
        res += factor();
      } else {
        break;
      }
    }
    return res;
  }
  
public:
  Parser(string s) : s(s + '@'), p(0) {}
  string eval() {return expr();}
};

string solve(string str) {
  int index = str.find("?");
  if (index == (int)string::npos) {
    Parser parser(str);
    return parser.eval();
  }
  string res;
  for (int i : range(100)) res += "Z";
  for (int i : range('A', 'Z' + 1)) {
    str[index] = i;
    is_min(res, solve(str));
  }
  return res;
}

int main() {
  while (true) {
    string str;
    cin >> str;
    if (str == ".") break;
    cout << solve(str) << endl;
  }
}