#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;

struct Node{
    ll size;
    ll repeat;
    string s;
    vector<Node> v;
    Node(){
        size = 0;
        repeat = 0;
        s = "";
    }
    Node(ll size, ll repeat, string s){
        this->size = size;
        this->repeat = repeat;
        this->s = s;
    }
};

ll fetch(const string &s, ll index){
    ll po = 1;
    for(ll i = index + 1; i < s.size(); i++){
        if(s[i] == '(') po++;
        else if(s[i] == ')') po--;
        if(!po) return i;
    }
}

Node dfs(const string &s){
    ll num = 0;
    string t = "";
    Node ret(0, 1, "");
    auto f = [&]{
        if(t != ""){
            ret.v.push_back(Node(t.size(), 1, t));
            t = "";
        }
    };

    for(ll i = 0; i < s.size(); i++){
        if('0' <= s[i] && s[i] <= '9'){
            f();
            num = 10 * num + s[i] - '0';
        }else if('A' <= s[i] && s[i] <= 'Z'){
            for(ll j = 0; j < max<ll>(1, num); j++) t += s[i];
            num = 0;
        }else if(s[i] == '('){
            f();
            ll fe = fetch(s, i);
            Node tmp = dfs(s.substr(i + 1, (fe - 1) - (i + 1) + 1));
            tmp.repeat = max<ll>(1, num);
            i = fe;
            num = 0;
            ret.v.push_back(tmp);
        }
    }
    if(t != "") f();
    for(auto child : ret.v){
        ret.size += child.size * child.repeat;
        if(ret.size > 1000002) ret.size = 1000002;
    }
    if(ret.size < 1000002) ret.size = ret.repeat * (ret.size + ret.s.size());
    return ret;
}

char solve(const Node &n, ll i){
    if(n.s.size() > i) return n.s[i];
    for(auto child : n.v){
        if(child.size * child.repeat <= i){
            i -= child.size * child.repeat;
        }else{
            return solve(child, i % child.size);
        }
    }
    //return n.s[i];
}

int main(){
    while(1){
        string S;
        ll I;
        cin >> S >> I;
        if(S == "0" && !I) break;
        S = "(" + S + ")";
        auto node = dfs(S);
        if(node.size <= I) cout << 0 << endl;
        else cout << solve(node, I) << endl;
    }
    return 0;
}

