#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>

using namespace std;

#define mod 1000000007

long long int getlen(string s)
{
	long long int ans = 0;
	for(int i = 0; i < s.length(); i++){
		if(isdigit(s[i])){
			long long int num = s[i] - '0';
			i++;
			while(isdigit(s[i])){
				num = num * 10 + (s[i] - '0');
				i++;
			}
			if(s[i] != '('){
				ans += num;
				continue;
			}
			int kakko = 1;
			int tmp = i + 1;
			while(kakko > 0){
				if(s[tmp] == '(') kakko++;
				else if(s[tmp] == ')') kakko--;
				tmp++;
			}
			string tmps = s.substr(i + 1, tmp - 1 - (i + 1));
			ans += num * getlen(tmps);
			i = tmp - 1;
		} else {
			ans++;
		}
		if(ans > mod) ans = mod;
	}
	// cout << s << " " << ans << endl;
	return ans;
}

char solve(string s, int n)
{
	// cout << s << n << endl;
	long long int nowlen = 0;
	bool allchar = true;
	for(int i = 0; i < s.length(); i++){
		if(isdigit(s[i])){
			allchar = false;
			long long int num = s[i] - '0';
			i++;
			while(isdigit(s[i])){
				num = num * 10 + (s[i] - '0');
				i++;
			}
			if(s[i] != '('){
				// cout << s[i] << nowlen + num << endl;
				if(nowlen + num > n) return s[i];
				else {
					nowlen += num;
					continue;
				}
			}
			int kakko = 1;
			int tmp = i + 2;
			while(kakko > 0){
				if(s[tmp] == '(') kakko++;
				else if(s[tmp] == ')') kakko--;
				tmp++;
			}
			string tmps = s.substr(i + 1, tmp - 1 - (i + 1));
			long long int tmpl = getlen(tmps);
			// cout << tmps << " " << tmpl << " " << nowlen << " " << n << " " << num << endl;
			if(nowlen + num * tmpl > n) return solve(tmps, (n - nowlen) % tmpl);
			i = tmp - 1;
			nowlen += num * tmpl;
			// cout << nowlen << endl;
		} else {
			if(nowlen == n) return s[i];
			nowlen++;
		}
	}
	if(allchar && n < s.length()) return s[n];
	return '0';
}

int main()
{
	string s;
	int n;
	while(1){
		cin >> s >> n;
		if(s == "0") break;
		cout << solve(s, n) << endl;
	}
	return 0;
}