object Main extends App {
  import scala.io.StdIn._
  val tetoris = Array.fill(4){
    val Array(h, w) = readLine.trim.split(' ').map(_.toInt)
    new Tetoromino(h, w, Array.fill(h){readLine.trim})
  }
  for (_ ← 0 until readInt()) {
    val state = State(Array.fill(4){readLine.trim})
    println(
      if (canFill(state, 0)(tetoris)) "Yes" else "No"
    )
  }
  def canFill(state: State, used: Int = 0)(implicit rest: Array[Tetoromino]): Boolean = {
    if (used == 14 || used == 13 || used == 11 || used == 7) true
    else rest.indices.filter(i ⇒ (used & (1 << i)) == 0).exists(i ⇒ state.put(rest(i)).exists(s ⇒ canFill(s, used | (1 << i))))
  }
}

case class Coordinate(x: Int, y: Int) {
  def +(that: Coordinate): Coordinate = Coordinate(x + that.x, y + that.y)
  def -(that: Coordinate): Coordinate = Coordinate(x - that.x, y - that.y)
}
class Tetoromino(val h: Int, val w: Int, state: Array[String]) {
  val block = (0 until h).flatMap(y ⇒ (0 until w).map(x ⇒ Coordinate(x, y))).filter(c ⇒ state(c.y)(c.x) == '#').toList match {
    case h::t ⇒ Coordinate(0, 0)::t.map(_ - h)
    case Nil ⇒ ???
  }
}
object State {
  def apply(state: Array[String]): State = {
    val empties = state.indices.flatMap(y ⇒ state(y).indices.filter(x ⇒ state(y)(x) == '.').map(x ⇒ Coordinate(x, y))).toSet
    new State(empties)
  }
}
class State(private val empties: Set[Coordinate]) {
  private val topLeft = Some(empties).filter(_.nonEmpty).map(_.minBy(c ⇒ c.y * 100 + c.x))
  def put(that: Tetoromino): Option[State] = {
    topLeft.map(c ⇒ that.block.map(_ + c)).filter(coords ⇒ coords.forall(empties.contains)).map(coords ⇒ new State(empties -- coords))
  }
}
