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