import scala.io.StdIn.{readLine,readInt}
/**
  * AOJ
  */

object Main {

  def main(args: Array[String]): Unit = {

    val dice = readLine().split(" ").map(_.toInt)
    val q =readInt()
    for(_ <- 1 to q){
      val sides = readLine().split(" ").map(_.toInt)
      println(findSide(sides(1),4,"HHH",findSide(sides(0),0,"WNNNW",dice))(3))
    }
  }

  def findSide(up:Int,findSide:Int,searchCommands:String,dice:Array[Int]) : Array[Int] = {
    if(dice(findSide) == up){return dice}
    var d = dice
    for(c <- searchCommands.toCharArray){
      d = getNextStatus(c,d)
      if(d(findSide) == up){return d}
    }
    throw new Exception()
  }

  def getNextStatus(cmd:Char,dice:Array[Int]): Array[Int] = cmd
    match {
      case 'N' => Array(dice(1),dice(5),dice(2),dice(3),dice(0),dice(4))
      case 'W' => Array(dice(2),dice(1),dice(5),dice(0),dice(4),dice(3))
      case 'H' => Array(dice(0),dice(3),dice(1),dice(4),dice(2),dice(5))
    }
}