import Control.Applicative

data Dice = Dice [Int] deriving (Show)

roll :: Dice -> Char -> Dice
roll (Dice [top, front, right, left, back, bottom]) 'S' = Dice [back, top, right, left, bottom, front]
roll (Dice [top, front, right, left, back, bottom]) 'E' = Dice [left, front, top, bottom, back, right]

turn1 :: Dice -> Dice
turn1 (Dice [top, front, right, left, back, bottom]) = Dice [top, right, back, front, left, bottom]
turn2 = turn1 . turn1
turn3 = turn2 . turn1

turnAll :: [Dice] -> [Dice]
turnAll dices =  [id, turn1, turn2, turn3] <*> dices

dices :: Dice -> [Dice]
dices dice = [dice
             , rev dice
             , toS dice
             , toE dice
             , rev (toS dice)
             , rev (toE dice)
             ]

toS = flip roll 'S'
toE = flip roll 'E'
rev = toS . toS

solve :: [Dice] -> [Int] -> Maybe Int
solve [] _                     = Nothing
solve ((Dice (x:y:z:_)):rest) [top, front]
    | top == x && front == y = Just z
    | otherwise              = solve rest [top, front]

main :: IO ()
main = do
    init <- Dice . map read . words <$> getLine
    getLine
    let diceall = turnAll . dices $ init
    qs <- map (map ri . words) . lines <$> getContents
    mapM_ putStrLn $ map pmaybe $ map (solve diceall) qs
        where ri :: String -> Int
              ri = read
              pmaybe :: Maybe Int -> String
              pmaybe Nothing  = "Nothing"
              pmaybe (Just n) = show n
