import io.StdIn.{readLine, readInt}
object Main extends App {
  val s = readLine.map(numerize)
  val t = readLine.map(numerize)
  val q = readInt
  val abcds = Seq.fill(q)(readLine.split(" ").toSeq.map(_.toInt))

  val ss = s.inits.map(_.sum).toList.reverse
  val ts = t.inits.map(_.sum).toList.reverse

  for (Seq(a, b, c, d) <- abcds) {
    val s = (ss(b) - ss(a - 1)) % 3
    val t = (ts(d) - ts(c - 1)) % 3
    println(if (s == t) "YES" else "NO")
  }

  def numerize(ab: Char) = ab - 'A' + 1
}
