def check_size arr
  ans=0
  while a=arr.shift
    case a
    when /[A-Z]+/
      ans+=a.size
    when /\d+/
      t=arr.shift
      ans+=a.to_i*(t==?(?check_size(arr):t.size)
    when ?)
      break
    end
  end
  ans
end

def get_ch arr,n
  #p [arr,n]
  while a=arr.shift
    case a
    when /[A-Z]+/
      l=a.size
      if n<l
        return a[n]
      end
      n-=l
    when /\d+/
      arr.shift if arr[0]==?(
      tarr=arr.dup
      l=check_size(tarr)
      #p [l,arr,tarr,n]
      if n<l*a.to_i
        n%=l
        return get_ch(arr,n)
      end
      arr=tarr
      n-=l*a.to_i
    end
  end
  #p [arr,n,"error"]
  #n
end

while gets
  a,b=$_.split
  break if a==?0
  cnt=b.to_i
  arr = a.scan(/[A-Z]+|\(|\)|\d+/)
#  p check_size arr
  puts get_ch(arr,cnt)||0
end