using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var labels = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            var num = int.Parse(Console.ReadLine());
            var questions = new int[num][];
            for (int i = 0; i < questions.Length; i++)
            {
                questions[i] = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            }

            var result=new int[questions.Length];
            var dice = new Dice(labels);
            for (int i = 0; i < questions.Length; i++)
            {
                var top = questions[i][0];
                if (top != dice.Top)
                {
                    if (top == dice.Front) dice.RollY(true);
                    else if (top == dice.Rear) dice.RollY(false);
                    else if (top == dice.Left) dice.RollZ(true);
                    else if (top == dice.Right) dice.RollZ(false);
                    else
                    {
                        dice.RollZ(true);
                        dice.RollZ(true);
                    }
                }
                var front = questions[i][1];
                if (front == dice.Front) result[i] = dice.Right;
                else
                {
                    if (front == dice.Right) result[i] = dice.Rear;
                    else if (front == dice.Left) result[i] = dice.Front;
                    else result[i] = dice.Left;
                }
            }

            foreach (var item in result)
            {
                Console.WriteLine(item);
            }
            Console.ReadLine();
        }
    }

    class Dice
    {
        public int Front { get; private set; }
        public int Bottom { get; private set; }
        public int Right { get; private set; }
        public int Left { get; private set; }
        public int Top { get; private set; }
        public int Rear { get; private set; }

        public Dice(int[] label)
        {
            Front = label[0];
            Bottom = label[1];
            Right = label[2];
            Left = label[3];
            Top = label[4];
            Rear = label[5];
        }

        public void RollX(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Left;
                Left = Rear;
                Rear = Right;
                Right = temp;
            }
            else
            {
                temp = Front;
                Front = Right;
                Right = Rear;
                Rear = Left;
                Left = temp;
            }
        }
        public void RollY(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Front;
                Front = Bottom;
                Bottom = Rear;
                Rear = Top;
                Top = temp;
            }
            else
            {
                temp = Front;
                Front = Top;
                Top = Rear;
                Rear = Bottom;
                Bottom = temp;
            }
        }
        public void RollZ(bool direction)
        {
            var temp = 0;
            if (direction)
            {
                temp = Top;
                Top = Left;
                Left = Bottom;
                Bottom = Right;
                Right = temp;
            }
            else
            {
                temp = Top;
                Top = Right;
                Right = Bottom;
                Bottom = Left;
                Left = temp;
            }
        }
    }
}

Measured memory_bytes: 5692