#include <iostream>
#include <vector>
#include <stack>

using namespace std;
#define ll long long
#define INITIAL 0
#define NUMBER 1
#define TYPE_CHAR 0
#define TYPE_NUM 1
#define TYPE_OPEN 2
#define TYPE_CLOSE 3
#define NODE_NUM 0
#define NODE_STR 1
#define NODE_PLUS 2
#define NODE_MUL 3
#define NODE_FUNC 4

struct Node{
  int type;
  int counts;
  string str;
  vector<Node> childs;
  ll size;
  ll sum_size;
  Node(int _type,int _counts,string _str){
    type=_type;
    counts=_counts;
    str=_str;
    size=0;
    sum_size=0;
    childs=vector<Node>();
  }
  ll set_size(){
    if(type==NODE_STR){
      size=str.size();
    }else if(type==NODE_MUL){
      ll sum=0;
      for(int i=0;i<childs.size();++i){
        sum+=childs[i].set_size();
      }
      if(sum>1<<30){
        sum=1e9;
      }
      sum_size=sum;
      size=sum*counts;
    }
    return size;
  }
  char find_char(ll i){
    if(i>=size){
      return '0';
    }
    if(type==NODE_STR){
      return str[i%size];
    }else if(type==NODE_MUL){
      i%=sum_size;
      for(int j=childs.size()-1;j>=0;--j){
        Node child=childs[j];
        if(child.size>i){
          return child.find_char(i);
        }else{
          i-=child.size;
        }
      }
    }
    return 'A';
  }
};

int char_type(char c){
  if('0'<=c&&c<='9'){
    return TYPE_NUM;
  }else if('A'<=c&&c<='Z'){
    return TYPE_CHAR;
  }else if(c=='('){
    return TYPE_OPEN;
  }else if(c==')'){
    return TYPE_CLOSE;
  }
}

int main(){
  string s;
  int i;
  cin>>s>>i;
  while(s!="0"||i!=0){
    int n=s.size();
    int state=INITIAL;
    string token="";
    int times=0;
    stack<Node> nodes;
    for(int i=0;i<n;++i){
      char c=s[i];
      int type=char_type(c);
      if(state==INITIAL){
        if(type==TYPE_CHAR){
          token+=c;
        }else if(type==TYPE_NUM){
          nodes.push(Node(NODE_STR,0,token));
          token="";
          times=c-'0';
          state=NUMBER;
        }else if(type==TYPE_CLOSE){
          Node node=Node(NODE_MUL,0,"");
          node.childs.push_back(Node(NODE_STR,0,token));
          while(nodes.top().type!=NODE_NUM){
            node.childs.push_back(nodes.top());
            nodes.pop();
          }
          node.counts=nodes.top().counts;
          nodes.pop();
          nodes.push(node);
          token="";
        }
      }else if(state==NUMBER){
        if(type==TYPE_CHAR){
          token+=c;
          Node node=Node(NODE_MUL,times,"");
          node.childs.push_back(Node(NODE_STR,0,token));
          nodes.push(node);
          times=0;
          token="";
          state=INITIAL;
        }else if(type==TYPE_NUM){
          times=times*10+c-'0';
        }else if(type==TYPE_OPEN){
          nodes.push(Node(NODE_NUM,times,""));
          times=0;
          state=INITIAL;
        }
      }
      //cout<<i<<" "<<state<<" "<<times<<" "<<token<<endl;
    }
    if(token!=""){
      nodes.push(Node(NODE_STR,0,token));
    }
    Node root(NODE_MUL,0,"");
    root.counts=1;
    while(!nodes.empty()){
      Node node=nodes.top();
      nodes.pop();
      root.childs.push_back(node);
      //cout<<node.type<<" "<<node.counts<<" "<<node.str<<endl;
    }
    root.set_size();
    cout<<root.find_char(i)<<endl;
    cin>>s>>i;
  }
  return 0;
}



Measured memory_bytes: 3156