#include <iostream>
#include <string>
using namespace std;

int number(string &s, int &iter) {
	int ret = 0;
	while ('0' <= s[iter] && s[iter] <= '9') {
		ret *= 10;
		ret += s[iter] - '0';
		iter++;
	}
	return ret;
}

int dfs(string &s, int &iter, int pos) {
	int len = 0;
	int start = iter;
	
	while (iter < s.length()) {
		if ('A' <= s[iter] && s[iter] <= 'Z') {
			if (len == pos) { cout << s[iter] << endl; }
			len++;
			if (len > 1000010) len = 1000010;
			iter++;
		}
		else if ('0' <= s[iter] && s[iter] <= '9') {
			int num = number(s, iter);
			if (s[iter] == '(') {
				iter++;
				int tmpIter = iter;
				int resLen = dfs(s, iter, -1);
				if (len <= pos && pos < len + resLen * num) {
					iter = tmpIter;
					dfs(s, iter, (pos - len) % resLen);
				}
				len += resLen * num;
				if (len > 1000010) len = 1000010;
			}
			else {
				if (len <= pos && pos < len + num) {
					cout << s[iter] << endl;
				}
				len += num;
				if (len > 1000010) len = 1000010;
				iter++;
			}
		}
		else if (s[iter] == ')') {
			iter++;
			break;
		}
	}
	return len;
}


int main() {
	string s;
	int pos;
	while (cin >> s >> pos) {
		if (s == "0") break;
		int iter = 0;
		int length = dfs(s, iter, pos);
		if (length <= pos) { cout << 0 << endl; }
	}
	return 0;
}
