#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
using State = string::const_iterator;

class Solve {
public:
    string S;
    int M = 0;

    string letter(State &begin) {
        int cnt = 0;
        while (true) {
            if (*begin == '+') {
                cnt++;
                begin++;
            } else if (*begin == '-') {
                cnt--;
                begin++;
            } else if (*begin == '[' || *begin == ']') {
                return "";
            } else {
                cnt += *begin - 'A';
                begin++;
                cnt = ((cnt % 26) + 26) % 26;
                char retch = static_cast<char>('A' + cnt);
                string ret;
                ret += retch;
                return ret;
            }
        }
    }

    string str(State &begin, State end) {
        if (*begin == '[') {
            begin++;
            string tmp = cifer(begin, end);
            begin++;
            reverse(tmp.begin(), tmp.end());
            return tmp;
        } else {
            return letter(begin);
        }
    }

    string cifer(State &begin, State end) {
        string ret;
//        cerr << (begin == end) << endl;
        while (begin != end && *begin != ']') {
            ret += str(begin, end);
//            begin++;
        }
        return ret;
    }


    string dfs(int n, string cs) {
        if (n == M) {
            string nS;
            int cnt = 0;
            for (auto e : S) {
                if (e == '?') nS += cs[cnt++];
                else nS += e;
            }
            State begin = nS.begin();
            string ret = cifer(begin, nS.end());
            return ret;
        } else {
            string ret = "~";
            for (char c = 'A'; c <= 'Z'; c++) {
                string ncs = cs;
                ncs += c;
                string tmp = dfs(n + 1, ncs);
                chmin(ret, tmp);
            }
            return ret;
        }
    }

    bool solve() {
        cin >> S;
        if (S == ".") return false;
        for (auto e : S) {
            if (e == '?') M++;
        }
        string ans = dfs(0, string());
        cout << ans << endl;


        return true;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    while (Solve().solve());

    return 0;
}



Measured memory_bytes: 3264