import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._

  solve
  def solve: Unit = {
    val Array(expression, i) = readLine.split(' ')
    if (expression == "0") return
    expression.toList match {
      case g Genome Nil ⇒ g.nThGenome(i.toInt) match {
        case Right(c) ⇒ println(c)
        case Left(_) ⇒ println(0)
      }
      case g Genome t ⇒ println(g, t)
    }
    solve
  }
  object Genome {
    def unapply(arg: List[Char]): Option[(Genome, List[Char])] = {
      arg match {
        case l Term rest ⇒ rest match {
          case g Genome t ⇒ Some(SequenceGenome(l, g), t)
          case _ ⇒ Some(l, rest)
        }
        case _ ⇒ None
      }
    }
  }
  object Term{
    def unapply(arg: List[Char]): Option[(Genome, List[Char])] = {
      arg match {
        case '('::(g Genome ')'::t) ⇒ Some(g, t)
        case n Number (g Term t) ⇒ Some(RepeatGenome(g, n), t)
        case h::t if h.isLetter ⇒ Some(SingleGenome(h), t)
        case _ ⇒ None
      }
    }
  }
  trait Genome {
    def nThGenome(n: Int): Either[Int, Char]
    def length: Int
  }
  case class SingleGenome(char: Char) extends Genome {
    override def nThGenome(n: Int): Either[Int, Char] = if (n == 0) Right(char) else Left(n - 1)
    override def length: Int = 1
  }
  case class SequenceGenome(head: Genome, tail: Genome) extends Genome {
    override def nThGenome(n: Int): Either[Int, Char] = if (n >= length) Left(n - length) else head.nThGenome(n) match {
      case Left(l) ⇒ tail.nThGenome(l)
      case r ⇒ r
    }
    override val length: Int = (head.length + tail.length).let{i ⇒ if (i > 1000001) 1000001 else i}
  }
  case class RepeatGenome(genome: Genome, repeat: Int) extends Genome {
    override def nThGenome(n: Int): Either[Int, Char] = if (n >= length) Left(n - length) else genome.nThGenome(n % genome.length)
    override val length: Int = (genome.length.toLong * repeat).let{i ⇒ if (i > 1000001) 1000001 else i.toInt}
  }
  object Number {
    def unapply(arg: List[Char]): Option[(Int, List[Char])] = {
      arg.span(_.isDigit) match {
        case (Nil, _) ⇒ None
        case (number, t) ⇒ Some(number.mkString.toInt, t)
      }
    }
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}
