#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1000001

char base[101];
char *ans_buf,*work;
int ans_index,result_index,base_length;
int work_index,work_length;

void recursive(int left,int right){

	if(left > right)return;

	int keisu = 0,index;

	for(index = left; index <= right && base[index] >= 'A' && base[index] <= 'Z' && work_index < ans_index+1;index++){
		work[work_index++] = base[index];
		work[work_index] = '\0';
	}

	for(;index <= right && base[index] >= '0' && base[index] <= '9';index++){
		keisu = 10*keisu + (base[index]-'0');
	}

	if(keisu == 0){
		for(work_length = 0; work[work_length] != '\0';work_length++);
		return;
	}

	//keisu != 0

	if(base[index] == '('){

		int depth = 1,next_right = -1,max_depth = 1;
		bool numFLG = false;

		for(int i = index+1; i <= right; i++){
			if(base[i] == '('){
				depth++;
				max_depth = max(max_depth,depth);
			}else if(base[i] == ')'){
				depth--;
				if(next_right == -1 && depth == 0){
					next_right = i;
					break;
				}
			}else if(base[i] >= '0' && base[i] <= '9'){
				numFLG = true;
			}
		}

		if(max_depth == 1){


			if(!numFLG){

				for(int i = 0; i < keisu && work_index < ans_index+1; i++){
					for(int k = index+1;k <= next_right-1 && work_index < NUM;k++){
						work[work_index++] = base[k];
						work[work_index] = '\0';
					}
				}

				recursive(next_right+1,right);
			}else{

				int pre_index = work_index;

				recursive(index+1,next_right-1);
				for(work_length = 0; work[pre_index+work_length] != '\0';work_length++);

				for(int i = 0; i < keisu-1 && work_index < ans_index+1; i++){
					for(int k = 0; k < work_length && work_index < NUM;k++){
						work[work_index++] = work[pre_index+k];
						work[work_index] = '\0';
					}
				}

				recursive(next_right+1,right);
			}

		}else{
			depth = 1,next_right = -1;
			for(int i = index+1; i <= right; i++){
				if(base[i] == '('){
					depth++;
				}else if(base[i] == ')'){
					depth--;
					if(next_right == -1 && depth == 0){
						next_right = i;
						break;
					}
				}
			}

			int pre_index = work_index;

			recursive(index+1,next_right-1);
			for(work_length = 0; work[pre_index+work_length] != '\0';work_length++);

			for(int i = 0; i < keisu-1 && work_index < ans_index+1; i++){
				for(int k = 0; k < work_length && work_index < NUM;k++){
					work[work_index++] = work[pre_index+k];
					work[work_index] = '\0';
				}
			}

			recursive(next_right+1,right);
		}

	}else{
		for(int i = 0; i < keisu && work_index < ans_index+1; i++){
			work[work_index++] = base[index];
			work[work_index] = '\0';
		}
		if(index + 1 <= right){
			recursive(index+1,right);
		}

	}

	for(work_length = 0; work[work_length] != '\0';work_length++);
}

void func(){

	for(int a = 0; a < NUM+9; a++)ans_buf[a] = '0';
	result_index = 0;
	for(base_length = 0; base[base_length] != '\0';base_length++);

	int left = 0,right = 0,depth;

	while(left < base_length && result_index < ans_index+1){

		depth = 0;
		for(int i = left; ;i++){
			if(base[i] == '('){
				depth++;
			}else if(base[i] == ')'){
				depth--;
				if(depth == 0){
					right = i;
					break;
				}
			}else if(base[i] >= 'A' && base[i] <= 'Z'){
				if(depth == 0){
					right = i;
					break;
				}
			}else{
				//Do nothing
			}
		}

		work_index = 0;
		work_length = 0;
		work[0] = '\0';
		recursive(left,right);

		for(int a = 0; work[a] != '\0' && result_index < NUM;a++){
			ans_buf[result_index++] = work[a];
		}

		left = right+1;
	}

	printf("%c\n",ans_buf[ans_index]);
}


int main(){

	ans_buf = new char[1000020];
	work = new char[1000020];

	while(true){
		scanf("%s %d",base,&ans_index);
		if(base[0] == '0' && ans_index == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 5168