#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << (x) << endl
using namespace std;
struct Term
{
    using Ptr = shared_ptr<Term>;
    Term(const int rep, const vector<Ptr>& child, const int unit, const string& s) : rep{rep}, child{child}, unit{unit}, s{s} {}
    int rep;
    vector<Ptr> child;
    int unit;
    string s;
};
using Ptr = Term::Ptr;
string S;
string::iterator c;
Ptr parse()
{
    if (not isdigit(*c)) {
        string s;
        for (; 'A' <= *c and *c <= 'Z'; c++) { s.push_back(*c); }
        return make_shared<Term>(1, vector<Ptr>{}, (int)s.size(), s);
    }
    string d;
    for (; isdigit(*c); c++) { d.push_back(*c); }
    const int D = d == "" ? 1 : stoi(d);
    Ptr ans = make_shared<Term>(D, vector<Ptr>{}, 0, "");
    bool hasb = false;
    if (*c == '(') { hasb = true, c++; }
    if (not hasb) { return (ans->unit = 1, ans->s = string(1, *c), c++, ans); }
    for (; *c != ')';) {
        const auto p = parse();
        ans->child.push_back(p);
        ans->unit = min(ans->unit + (p->unit) * (p->rep), 1000001);
    }
    c++;
    return ans;
}
string toString(const Ptr p)
{
    if (p->child.empty()) { return p->s; }
    string s = to_string(p->rep) + "(";
    for (const auto& c : p->child) { s += toString(c); }
    s += ")";
    return s;
}
int main()
{
    while (true) {
        int N;
        cin >> S >> N;
        if (S == "0" and N == 0) { break; }
        S = "1(" + S + ")";
        c = S.begin();
        const Ptr root = parse();
//        show(toString(root));
        if (N >= root->unit * root->rep) {
            cout << 0 << endl;
            continue;
        }
        Ptr p = root;
        while (true) {
            if (p->child.empty()) {
                cout << p->s[N] << endl;
                break;
            } else {
                for (const auto& c : p->child) {
                    if (N >= c->rep * c->unit) {
                        N -= c->rep * c->unit;
                    } else {
                        N %= c->unit;
                        p = c;
                        break;
                    }
                }
            }
        }
    }
    return 0;
}

