### main

loop do
  plen = gets.to_i
  break if plen == 0

  cnum = gets.to_i
  wdth = gets.to_i
  cspc = gets.to_i

  lines = []

  loop do
    line = gets.strip
    break if line == '?'

    while line.length > wdth
      lines << line[0, wdth]
      line[0, wdth] = ''
    end

    lines << line + '.' * (wdth - line.length)
  end
  #p lines

  cplen = plen * cnum
  rlen = lines.length % cplen
  if rlen > 0
    lines += ['.' * wdth] * (cplen - rlen)
  end
  #p lines.length

  while ! lines.empty?
    plines = plen.times.map{''}

    for col in (0...cnum)
      for i in (0...plen)
        plines[i] += '.' * cspc if col > 0
        plines[i] += lines.shift
      end
    end

    plines.each{|pl| puts pl}
    puts '#'
  end

  puts '?'
end