import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.NoSuchElementException;

class Tree {
	boolean leaf;
	String str;
	ArrayList<Tree> nodes;
	ArrayList<Integer> repeats;
	int num;

	Tree() {
		str = null;
		leaf = false;
		nodes = new ArrayList<Tree>();
		repeats = new ArrayList<Integer>();
		num = 0;
	}

	void setStr(String s) {
		str = s;
		leaf = true;
	}

	void addChild(Tree t, int rep) {
		nodes.add(t);
		repeats.add(rep);
		num++;
	}

	long length() {
		if (leaf)
			return str.length();
		long len = 0;
		for (int i = 0; i < num; i++) {
			Tree t = nodes.get(i);
			int rep = repeats.get(i);
			len += t.length() * rep;
		}
		return len;
	}

	int charAt(long index) {
		if (leaf) {
			if (index >= str.length())
				return -1;
			return str.charAt((int) index);
		} else {
			for (int ononon = 0; ononon < num; ononon++) {
				Tree t = nodes.get(ononon);
				int rep = repeats.get(ononon);
				int chr = t.charAt(index);
				if (chr != -1)
					return chr;
				long len = t.length();
				if (index - len * rep < 0) {
					index %= len;
					return t.charAt(index);
				} else {
					index -= len * rep;
				}
			}
			return -1;
		}
	}

	public String toString() {
//		System.out.println("tostr leaf? " + leaf + " " + num);
		if (leaf)
			return str;
		String s = "";
		for (int i = 0; i < num; i++) {
			Tree t = nodes.get(i);
			int rep = repeats.get(i);
//			System.out.println("node rep=" + rep);
			if (rep > 1) {
				s += rep + "(" + t + ")";
			} else {
				s += t;
			}
		}
		return s;
	}
}

class SReader {
	int idx;
	String[] ss;

	SReader(String[] ss) {
		this.ss = ss;
	}

	String next() {
		return ss[idx];
	}

	boolean end() {
		return idx == ss.length;
	}

	String read() {
		return ss[idx++];
	}

	void read(String expected) {
		if (!read().equals(expected))
			throw new RuntimeException("ha?");
	}

	boolean readIf(String s) {
		if (ss[idx].equals(s)) {
			idx++;
			return true;
		}
		return false;
	}
}

public class Main {
	private static void solve() {
		while (true) {
			String s = nes();
			if (s.equals("0")) {
				nei();
				break;
			}
			s = s.replaceAll("([0-9]+)([A-Z])", "$1($2)").replaceAll("[0-9]+|\\(|\\)", " $0 ").replaceAll(" +", " ")
					.trim();
			String[] ss = s.split(" ");
			long idx = nei();
			SReader r = new SReader(ss);
			Tree t = parseTree(r);
			int ONON = t.charAt(idx);
			if (ONON == -1)
				out("0");
			else
				out((char) ONON);
		}
	}

	private static Tree parseTree(SReader r) {
		Tree t = new Tree();
		while (!r.end() && !r.next().equals(")")) {
			String n = r.read();
			if (n.replaceAll("[0-9]", "").isEmpty()) {
				r.read("("); // "("
				t.addChild(parseTree(r), Integer.parseInt(n));
				r.read(")"); // ")"
			} else {
				Tree tt = new Tree();
				tt.setStr(n);
				t.addChild(tt, 1);
			}
		}
		return t;
	}

	static void out(String val) {
		IO.out(val);
	}

	static void out(Object val) {
		IO.out(String.valueOf(val));
	}

	static void out(int val) {
		IO.out(String.valueOf(val));
	}

	static void out(long val) {
		IO.out(String.valueOf(val));
	}

	static void out(char val) {
		IO.out(String.valueOf(val));
	}

	static void out(double val) {
		IO.out(BigDecimal.valueOf(val).toPlainString());
	}

	static void out(boolean val) {
		IO.out(String.valueOf(val));
	}

	static void kil(String val) {
		IO.out(val);
		IO.flush();
		System.exit(0);
	}

	static void kil(Object val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(int val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(long val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(char val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(float val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(double val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static void kil(boolean val) {
		IO.out(String.valueOf(val));
		IO.flush();
		System.exit(0);
	}

	static String nes() {
		return IO.next();
	}

	static int nei() {
		return IO.nextInt();
	}

	static long nel() {
		return IO.nextLong();
	}

	static double ned() {
		return IO.nextDouble();
	}

	static char nec() {
		return IO.nextChar();
	}

	static String[] nss(int n) {
		String[] as = new String[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.next();
		}
		return as;
	}

	static int[] nis(int n) {
		int[] as = new int[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextInt();
		}
		return as;
	}

	static long[] nls(int n) {
		long[] as = new long[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextLong();
		}
		return as;
	}

	static double[] nds(int n) {
		double[] as = new double[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextDouble();
		}
		return as;
	}

	static char[] ncs(int n) {
		char[] as = new char[n];
		for (int i = 0; i < n; i++) {
			as[i] = IO.nextChar();
		}
		return as;
	}

	static String[][] nss2(int n, int m) {
		String[][] as = new String[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.next();
			}
		}
		return as;
	}

	static int[][] nis2(int n, int m) {
		int[][] as = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextInt();
			}
		}
		return as;
	}

	static long[][] nls2(int n, int m) {
		long[][] as = new long[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextLong();
			}
		}
		return as;
	}

	static double[][] nds2(int n, int m) {
		double[][] as = new double[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextDouble();
			}
		}
		return as;
	}

	static char[][] ncs2(int n, int m) {
		char[][] as = new char[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				as[i][j] = IO.nextChar();
			}
		}
		return as;
	}

	static int parseInt(String val) {
		return Integer.parseInt(val);
	}

	static int parseInt(char val) {
		return Integer.parseInt(String.valueOf(val));
	}

	static long parseLong(String val) {
		return Long.parseLong(val);
	}

	public static void main(String[] args) {
		try {
			solve();
			IO.flush();
		} catch (NumberFormatException | NoSuchElementException e) {
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

final class IO {
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out, false);
	private static final byte[] buffer = new byte[1024];
	private static int ptr = 0;
	private static int len = 0;

	private static boolean hasNextByte() {
		if (ptr < len)
			return true;
		ptr = 0;
		try {
			len = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return len > 0;
	}

	private static int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	static boolean hasNext() {
		byte c;
		while (hasNextByte() && ((c = buffer[ptr]) < '!' || c > '~'))
			ptr++;
		return hasNextByte();
	}

	static String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (b >= '!' && b <= '~') {
			sb.append((char) b);
			b = readByte();
		}
		return sb.toString();
	}

	static char nextChar() {
		if (!hasNext())
			throw new NoSuchElementException();
		return (char) readByte();
	}

	static long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

	static int nextInt() {
		if (!hasNext())
			throw new NoSuchElementException();
		int n = 0;
		int sign = 1;
		int b = readByte();
		if (b == '-') {
			sign = -1;
			b = readByte();
		}
		if (b < '0' || '9' < b)
			throw new NumberFormatException();
		while (true) {
			if ('0' <= b && b <= '9')
				n = n * 10 + b - '0';
			else if (b == -1 || b < '!' || b > '~')
				return n * sign;
			else
				throw new NumberFormatException();
			b = readByte();
		}
	}

	static double nextDouble() {
		return Double.parseDouble(next());
	}

	static void out(String val) {
		out.println(val);
	}

	static void flush() {
		out.flush();
	}
}



Measured memory_bytes: 42432