def f a
a.map(&:chars).transpose.map{|i|i.reverse*""}
end
$h={}
def g m,l
$h[[m]+l]||=l[0]?l.any?{|i|$s[i-1].any?{|j|(k=m=~/#{j}/)&&(n=m+"";j.each_char{|c|k+=1;c==?a&&n[k-1]=?#};g n,l-[i])}}:!m[?a]
end
while(h,w=gets.split.map &:to_i)[0]>0
m=(1..h).map{gets.tr".\n","a#"}*""
$s=(1..gets.to_i).map{a,_=gets.split.map &:to_i
[i=(1..a).map{gets.chop.tr ?#,?a},j=f(i),k=f(j),f(k)].map{|l|l*(?.*(w-l[0].size+1))}.uniq}
gets.to_i.times{l=gets.split.map &:to_i
puts g(m,l[1..-1])?:YES:"NO"}end