// AOJ 1145: The Genome Database of All Space Life
// 2017.10.1 bal4u@uu

#include <stdio.h>
#include <ctype.h>

char buf[102];
char ans;

char *expr();

char *factor(char *p, long long w, long long *n)
{
	int k;

	if (*p == '(') {
		if ((p = expr(p+1, w, n)) == NULL) return NULL;
		p++;
	} else {
		char *q = p;
		while (isalpha(*p)) p++;
		k = p - q;
		if (w*k <= *n) *n -= w*k;
		else {
			*n %= k;
			while (*n > 0 && isalpha(*q)) q++, (*n)--;
			ans = *q;
			return NULL;
		}
	}
	return p;
}

char *expr(char *p, long long k, long long *n)
{
	long long r;

	while (*p) {
		if (*p == ')') break;
		r = 1; if (isdigit(*p)) {
			r = 0; while (isdigit(*p)) r = 10 * r + (*p++ - '0');
		}
		if ((p = factor(p, k*r, n)) == NULL) return NULL;
	}
	return p;
}

int main()
{
	long long i;

	while (scanf("%s%lld", buf, &i) && *buf != '0') {
		ans = '0';
		expr(buf, 1LL, &i);
		putchar(ans), putchar('\n');
	}
	return 0;
}