#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e14+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
string s;int bas;
class bun{
public:
	char c;//文字
	int kuri;//繰り返し回数
	llint len;//文字列長
	vector<bun> ko;//中身
	void make(void){
		if('A'<=s[bas]&&s[bas]<='Z'){
			c=s[bas];bas++;
			kuri=1;len=1;
			return;
		}
		//そうでなければ数字のはず
		kuri=0;
		while('0'<=s[bas]&&s[bas]<='9'){kuri*=10;kuri+=s[bas]-'0';bas++;}
		if(kuri==0){cerr<<"bag"<<__LINE__<<endl;}
		if(s[bas]=='('){
			bas++;len=0;c='#';
			while(s[bas]!=')'){
				ko.emplace_back();
				ko.back().make();
				len+=ko.back().len;
			}
			mineq(len,big);len*=kuri;mineq(len,big);
			bas++;
		}
		else{c=s[bas];bas++;len=kuri;}
		return;
	}
	char putc(llint index){
		if(len<=index){return '0';}
		if(c!='#'){return c;}
		index%=(len/kuri);//一回当たりの回数
		for(auto it:ko){
			if(index<it.len){return it.putc(index);}
			else{index-=it.len;}
		}
	}
};
bool solve(void){
	bun aa;
	string ss;cin>>ss;
	if(ss=="0"){return false;}
	s="1("+ss+")";bas=0;
	aa.make();
	int ind;cin>>ind;
	cout<<aa.putc(ind)<<endl;
	return true;
}
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	while(solve()){}
	return 0;
}

