#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

struct Node {
    string pattern;
    ll len,factor;
    vector<Node*> child;
};

int p;

Node *parse(string &s) {
    if(isdigit(s[p])) {
        int r = 0;
        while(isdigit(s[p])) {
            r *= 10;
            r += s[p] -'0';
            p++;
        }

        Node *node = new Node();
        node->factor = r;
        if(s[p] == '(') {
            p++;
            while(s[p] != ')') {
                Node *nr = parse(s);
                node->child.push_back(nr);
            }
            p++;
            node->len = 0;
            for(int i=0; i<node->child.size(); ++i) {
                node->len += node->child[i]->len;
            }
            node->len *= node->factor;
            return node;
        }else{
            node->pattern = string(1,s[p]);
            p++;
            node->len = r;
            return node;
        }
    }

    Node *node = new Node();
    string pattern = "";
    while(p < s.length() && isalpha(s[p])) {
        pattern += string(1,s[p]);
        p++;
    }
    node->pattern = pattern;
    node->len = pattern.length();
    node->factor = 1;
    return node;
}

void dff(Node *v) {
    cout<<v->len<<" -> "<<v->pattern<<endl;
    for(int i=0; i<v->child.size(); ++i)
        dff(v->child[i]);
}

char dfs(Node *v,ll idx) {
    if(v->child.empty()) {
        string pat = v->pattern;
//        cout<<pat.length()<<" "<<v->factor<<" "<<idx<<" "<<pat<<endl;
        if(idx < v->factor*pat.length()) return pat[idx%(pat.length())];
        v->len = pat.length()*(v->factor);
        return '-';
    }

    ll offset = 0;
    for(int i=0; i<v->child.size(); ++i) {
        char c = dfs(v->child[i],idx-offset);
        if(c != '-') return c;
        offset += v->child[i]->len;
    }
    if(idx/offset < v->factor) {
        idx %= offset;
        return dfs(v,idx);
    }
    v->len = offset*v->factor;
    return '-';
}

int main() {
    int n;
    string s;
    while(cin>>s) {
        cin>>n;
        if(s == "0" && n == 0) break;
        p = 0;
        s += ")";
        s = "1(" + s;
        Node *root = parse(s);

//        dff(root);
        char ans = dfs(root,n);
        if(ans == '-') cout<<"0"<<endl;
        else cout<<ans<<endl;
    }
}