def change_str(str)
  current_chr = str[0]
  continue_count = 1
  new_string = ""
  (1..str.length).each do |index|
    if current_chr != str[index]
      new_string += current_chr + continue_count.to_s
      continue_count = 1
      current_chr = str[index]
    else 
      continue_count += 1
    end
  end  
  new_string += current_chr + continue_count.to_s
  new_string
end

while str = gets do
  str = gets.chomp
  num = gets.chomp.to_i
  break if num == 0
  num.times do |n|
    str = change_str(str)
  end
  puts str
end