#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<iomanip>
#include<assert.h>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


struct Stage{
	Stage(){
		cin >> s >> id;
	}
	
	bool is_end(){
		return s == "0";
	}
	
	void action(){
		stack<Gram> st;
		auto grams = trans_gram();
		for (auto gram : grams)
		{
			//解凍
			if (gram.kind == 'p' && gram.par == ')')
			{
				auto alpha = st.top(); st.pop();
				auto parL = st.top(); st.pop();
				auto roop = st.top(); st.pop();
				gram = roop_modify(roop, alpha);
			}


			//結合
		start:;
			while(!st.empty() && gram.kind == 'a')
			{
				Gram tmp;
				switch (st.top().kind){
				case 'a':
					tmp = st.top(); st.pop();
					gram = append(tmp, gram);
					break;
				case 'n':
					tmp = st.top(); st.pop();
					gram = roop_modify(tmp, gram);
					break;
				default:
					goto last;
				}
			}
		last:;
			st.push(gram);
		}
		string res = "";
		while (!st.empty()) {
			if (st.top().kind == 'a') {
				res = st.top().s + res;
				if (res.size() >= id)
				{
					res = res.substr(0, id + 10);
				}
			}
			st.pop();
		}
		if (id >= res.size()) {
			cout << 0 << endl;
		}
		else {
			cout << res[id] << endl;
		}
	}
	
private:
	struct Gram {
		char kind;
		int num;
		string s;
		char par;
	};

	int id;
	string s;
	
	vector<Gram> trans_gram()const
	{
		vector<Gram> grams;
		REP(i, s.size())
		{
			Gram gram;
			switch (s[i])
			{
			case '(':
				gram.kind = 'p';
				gram.par = '(';
				break;
			case ')':
				gram.kind = 'p';
				gram.par = ')';
				break;
			default:
				if (is_num(s[i])) {
					int num = 0;
					do {
						num *= 10;
						num += s[i] - '0';
						i++;
					} while (is_num(s[i]));
					i--;
					gram.kind = 'n';
					gram.num = num;
				}
				else if (is_alpha(s[i])) {
					string tmp{ s[i] };
					while (i < s.size() - 1 && is_alpha(s[i + 1])) {
						tmp += {s[i + 1]};
						i++;
					}
					gram.kind = 'a';
					gram.s = tmp;
				}
				else {
					assert(false);
				}
				break;
			}
			grams.push_back(gram);
		}
		return grams;
	}

	bool is_num(const char& c) const{
		return '0' <= c && c <= '9';
	}
	bool is_alpha(const char& c)const {
		return 'A' <= c && c <= 'Z';
	}
	Gram roop_modify(const Gram& roop, const Gram& alpha)const
	{
		assert(roop.kind == 'n');
		assert(alpha.kind == 'a');

		Gram gram;
		gram.kind = 'a';
		REP(i, roop.num)
		{
			gram.s += alpha.s;
			if (gram.s.size() > id)break;
		}
		return gram;
	}
	Gram append(Gram l, const Gram& r)const 
	{
		assert(l.kind == 'a');
		assert(r.kind == 'a');
		l.s += r.s;
		if (l.s.size() > id) {
			l.s = l.s.substr(0, id + 10);
		}
		return l;
	}
};

//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	while(true){
		Stage stage;
		if(stage.is_end())break;
		stage.action();
	}
	debug();
	
	return 0;
}

