### 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)
    gch = tch if gch.nil? && ! tch.nil?
    i -= tlen if gch.nil?
    glen += tlen
  end

  [glen, gch]
end

def term(gnm, i)
  if /[A-Z]/ =~ gnm[$pos]
    len = parse_alph(gnm)
    tch = (i < len) ? gnm[$pos + i] : nil
    $pos += len
    return [len, tch]
  end

  len = parse_num(gnm)
  num = gnm[$pos, len].to_i
  $pos += len

  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 [num, tch]
  end
end

def parse_alph(gnm)
  len = 0
  while /[A-Z]/ =~ gnm[$pos + len]
    len += 1
  end
  len
end

def parse_num(gnm)
  len = 0
  while /[0-9]/ =~ gnm[$pos + len]
    len += 1
  end
  len
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