import scala.math._
import scala.collection.mutable.ListBuffer

object Main {
  //rt.gc()??§??¬??????????????¬?????????????????????
  //val rt = Runtime.getRuntime()
  val sc = new java.util.Scanner(System.in)
  def canPut(m: Array[Array[Char]], l: Array[Array[Char]], x: Int, y: Int): Boolean = {
    if(m.size < x + l.size || m(0).size < y + l(0).size) {
      return false
    }
    for(i <- 0 until l.size; j <- 0 until l(0).size) {
      if(m(x+i)(y+j) == '#' && l(i)(j) == '#') {
        return false
      }
    }
    return true
  }
  def put(m: Array[Array[Char]], l: Array[Array[Char]], x: Int, y: Int) {
    for(i <- 0 until l.size; j <- 0 until l(0).size) {
      if(l(i)(j) == '#') {
        m(x+i)(y+j) = '#'
      }
    }
  }
  def remove(m: Array[Array[Char]], l: Array[Array[Char]], x: Int, y: Int) {
    for(i <- 0 until l.size; j <- 0 until l(0).size) {
      if(l(i)(j) == '#') {
        m(x+i)(y+j) = '.'
      }
    }
  }
  def test(m: Array[Array[Char]], ls: List[Array[Array[Char]]]):Boolean = ls match {
    case Nil => {
      m.flatten.forall(_ == '#')
    }
    case head::tail => {
      val r90 = Array.ofDim[Char](head(0).size, head.size)
      val r180 = Array.ofDim[Char](head.size, head(0).size)
      val r270 = Array.ofDim[Char](head(0).size, head.size)
      for(i <- 0 until head.size; j <- 0 until head(0).size) {
        r90(j)(head.size - 1 - i) = head(i)(j)
        r180(head.size - 1 - i)(head(0).size - 1 - j) = head(i)(j)
        r270(head(0).size - 1 - j)(i) = head(i)(j)
      }
      val lr = List(head, r90, r180, r270)
      val ng = Array(false, false, false, false)
      for(i <- 0 until m.size; j <- 0 until m(0).size) {
        for(k <- 0 until 4 if !ng(k)) {
          if(canPut(m, lr(k), i, j)) {
            put(m, lr(k), i, j)
            if(test(m, ls.tail)) {
              remove(m, lr(k), i, j)
              return true
            } else {
              remove(m, lr(k), i, j)
              ng(k) = true
            }
          }
        }
      }
      false
    }
  }
  def main(args: Array[String]) {
    while(true) {
      val h, w = sc.nextInt
      if((h,w) == (0, 0)) return

      val m = Array.ofDim[Char](h, w)
      for(i <- 0 until h) {
        m(i) = sc.next.toArray
      }
      val n = sc.nextInt
      val p = new Array[Array[Array[Char]]](n)
      for(i <- 0 until n) {
        val hi, wi = sc.nextInt
        p(i) = Array.ofDim[Char](hi, wi)
        for(j <- 0 until hi) {
          p(i)(j) = sc.next.toArray
        }
      }

      def f(a: Array[Int], d: Int): Boolean = {
        if(d == a.size) {
          return test(m, a.map(p(_)).toList)
        } else {
          for(j <- d until a.size) {
            val tmp = a(d)
            a(d) = a(j)
            a(j) = tmp
            if(f(a, d+1)) {
              return true
            }
            a(j) = a(d)
            a(d) = tmp
          }
        }
        return false
      }

      val np = sc.nextInt
      sc.nextLine
      for(i <- 0 until np) {
        val c = sc.nextLine.split(" ").map(_.toInt - 1).tail
        if(m.flatten.count(_ == '.') != c.map(p(_).flatten.count(_ == '#')).sum) {
          println("NO")
        } else {
          println(if(f(c, 0)) "YES" else "NO")
        }
      }
    }
  }
}