v = []

loop do
  cards = gets.chomp
  break if cards == '-'

  m = gets.to_i

  m.times do
    h = gets.to_i
    tmp = cards.slice!(0, h)
    cards += tmp
  end

  v << cards
end

v.each do |i|
  puts i
end

