h,w,n=gets.split.map(&:to_i) s=h.times.map{gets.chomp.chars}.transpose.map{|e|h-(e.index('#')||h)} c=n.times.map{gets.to_i} c.each{|e|s[e]-=1} c0=c.map{[1,0,0]} (0...n).sort_by{|e|c[e]}.each{|i| 3.times{|j| dec=[j==0 ? 2 : 3,s[c[i]+j]].min s[c[i]+j]-=dec c0[i][j]+=dec } } c0.each{|e|puts e.map{|f|['.']*(3-f)+['#']*f}.transpose.map(&:join)}