n = gets.to_i s, t = gets.chomp.split a = gets.chomp.split.map &:to_i a.each do |x| res = [] cnt = x / s.length while (x - cnt * s.length) % t.length != 0 do cnt -= 1 end cnt.times do res << s end ((x - cnt * s.length)/t.length).times do res << t end puts res.join(" ") end