### subroutines

# <genom> = <term> | <term> <genom>
# <term> = <elm>+ | <num> <elm> | <num> '(' <genom> ')'
# <elm> = 'A'..'Z'
# <num> = ('0'..'9')+

def genom(gnm, i)
  glen = 0
  gch = nil

  while ! gnm[$pos].nil? && gnm[$pos] != ')'
    tlen, tch = term(gnm, i)
    if gch.nil?
      gch = tch if ! tch.nil?
      i -= tlen
    end
    glen += tlen
  end

  [glen, gch]
end

def term(gnm, i)
  case gnm[$pos]
  when 'A'..'Z'
    len = 1
    loop do
      ch = gnm[$pos + len]
      break if ch.nil? || ch < 'A' || ch > 'Z'
      len += 1
    end
    tch = (i < len) ? gnm[$pos + i] : nil
    $pos += len
    return [len, tch]
  when '0'..'9'
    nlen = 1
    loop do
      ch = gnm[$pos + nlen]
      break if ch < '0' || ch > '9'
      nlen += 1
    end
    num = gnm[$pos, nlen].to_i
    $pos += nlen

    if gnm[$pos] == '('
      $pos += 1
      pos0 = $pos
      glen, gch = genom(gnm, i)
      $pos += 1
      gnlen = glen * num
      return [gnlen, gch] if ! gch.nil? || i >= gnlen

      $pos = pos0
      i0 = i % glen
      glen, gch = genom(gnm, i0)
      $pos += 1
      return [gnlen, gch]
    else
      tch = (i < num) ? gnm[$pos] : nil
      $pos += 1
      return [nlen, tch]
    end
  end
end

### main

loop do
  gnm, ist = gets.strip.split
  break if gnm == '0' && ist == '0'

  i = ist.to_i
  #p [gnm, i]

  $pos = 0
  num, ch = genom(gnm, i)
  #p [num, ch]

  puts (ch.nil? ? 0 : ch)
end