#include<stdio.h>
#include<stdlib.h>

int roop(int *a,int n,char *ans,int times,char str[]){
  while(1){
    if(times==0)return 0;
    int i;
    for(i=0;str[i]!='\0';i++){
      if(str[i]>=65&&str[i]<=90){
	if(*a==n)*ans=str[i];
	*a = *a + 1;
      }
      else if(str[i]>=48&&str[i]<=57){
	int j;
	int rt;
	char rooptimes[16];
	char roopstr[256];
	for(j=i;str[j]>=48&&str[j]<=57;j++){
	  rooptimes[j-i] = str[j];
	}
	rt = atoi(rooptimes);    
	i = j;
	if(str[i]=='('){
	  i++;
	  int bracketscount = 1;
	  for(j=i;bracketscount>0;j++){
	    roopstr[j-i] = str[j];
	    if(str[j]=='(')bracketscount++;
	    if(str[j]==')')bracketscount--;
	  }
	  roopstr[j-i-1] = '\0';
	  i = j-1;
	}
	else if(str[i]>=65&&str[i]<=90){
	  roopstr[0] = str[i];
	  roopstr[1] = '\0';
	}
	roop(a,n,ans,rt,roopstr);
      }
      if(*ans!='0')return 0;
    }
    times--;
  }
}
char genome(char first[]){
  char str[256];
  char c[16];
  int n;
  int i; 
  int count=0;
  char ans = '0';
  char *p;
  p = &ans;
  for(i=0;first[i]!=' ';i++){
    str[i]=first[i];
  }
  i++;
  str[i] = '\0';
  n = i;
  for(i=0;first[n]!='\n';i++){
    c[i]=first[n];
    n++;
  }
  n = atoi(c);


  for(i=0;str[i]!='\0';i++){
    if(str[i]>=65&&str[i]<=90){
      if(count==n)ans = str[i];
      count++;
    }
    else if(str[i]>=48&&str[i]<=57){
      int j;
      int rt;
      char rooptimes[16];
      char roopstr[256];
      for(j=i;str[j]>=48&&str[j]<=57;j++){
	rooptimes[j-i] = str[j];
      }
      rt = atoi(rooptimes);    
      i = j;
      if(str[i]=='('){
	i++;
	int bracketscount = 1;
	for(j=i;bracketscount>0;j++){
	  roopstr[j-i] = str[j];
	  if(str[j]=='(')bracketscount++;
	  if(str[j]==')')bracketscount--;
	}
	roopstr[j-i-1] = '\0';
	i = j-1;
      }
      else if(str[i]>=65&&str[i]<=90){
	roopstr[0] = str[i];
	roopstr[1] = '\0';
      }
      roop(&count,n,p,rt,roopstr);
    }
    if(ans!='0')break;
  }
  return ans;
}

int main(void){

  char first[256];
  char answer[1024];
  int i = 0;
  while(1){
    fgets(first,256,stdin);
    if(first[0]=='0'&&first[1]==' '&&first[2]=='0'&&first[3]=='\n')break;
    answer[i] = genome(first);
    i++;
  }
  for(i=0;answer[i]!='\0';i++){
    if(answer[i]=='0')printf("0\n");
    else printf("%c\n",answer[i]);
  }
  return 0;
}