using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dice2
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            Dice dice = new Dice(
                int.Parse(strs[0]),
                int.Parse(strs[1]),
                int.Parse(strs[2]),
                int.Parse(strs[3]),
                int.Parse(strs[4]),
                int.Parse(strs[5]));
            int count = int.Parse(Console.ReadLine());

            Dice2 problem = new Dice2(dice);
            for (int i = 0; i < count; i++)
            {
                line = Console.ReadLine();
                strs = line.Split(' ');
                Console.WriteLine(problem.FindRight(int.Parse(strs[0]), int.Parse(strs[1])));   
            }
        }
    }

    public class Dice2
    {
        private Dice dice;

        public Dice2(Dice dice)
        {
            this.dice = dice;
        }

        public int FindRight(int top, int front)
        {
            // topを検索
            bool isFinds = false; 
            for (int i = 0; i < 4; i++)
            {
                if (dice.GetNumber(1) == top)
                {
                    isFinds = true;
                    break;
                }
                dice.GoNorth();
            }
            if (isFinds == false)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (dice.GetNumber(1) == top)
                    {
                        isFinds = true;
                        break;
                    }
                    dice.GoEast();
                }
            }
            // 見つからないことはないはず
            if (isFinds ==false) throw new ArgumentException("見つかりませんでした。");

            // 時計回りを行ってfrontを検索
            for (int i = 0; i < 4; i++)
            {
                if (dice.GetNumber(2) == front)
                {
                    return dice.GetNumber(3);
                }
                dice.RotateRight();
            }
            // 見つからないことはないはず
            throw new ArgumentException("見つかりませんでした。");
        }


        private bool IsMatched(int top, int front)
        {
            if (dice.GetNumber(1) == top && dice.GetNumber(2) == front) return true;
            return false;
        }

    }

    public class Dice
    {
        private Dictionary<int, int> dice;

        public Dice(
            int face1,
            int face2,
            int face3,
            int face4,
            int face5,
            int face6)
        {
            dice = new Dictionary<int, int>();
            dice.Add(1, face1);
            dice.Add(2, face2);
            dice.Add(3, face3);
            dice.Add(4, face4);
            dice.Add(5, face5);
            dice.Add(6, face6);
        }

        public void GoEast()
        {
            Dictionary<int, int> temp = new Dictionary<int, int>();
            temp = new Dictionary<int, int>(dice);

            dice[3] = temp[1];
            dice[2] = temp[2];
            dice[6] = temp[3];
            dice[1] = temp[4];
            dice[5] = temp[5];
            dice[4] = temp[6];
        }

        public void GoNorth()
        {
            Dictionary<int, int> temp = new Dictionary<int, int>();
            temp = new Dictionary<int, int>(dice);

            dice[5] = temp[1];
            dice[1] = temp[2];
            dice[3] = temp[3];
            dice[4] = temp[4];
            dice[6] = temp[5];
            dice[2] = temp[6];
        }

        public void GoSouth()
        {
            Dictionary<int, int> temp = new Dictionary<int, int>();
            temp = new Dictionary<int, int>(dice);

            dice[2] = temp[1];
            dice[6] = temp[2];
            dice[3] = temp[3];
            dice[4] = temp[4];
            dice[1] = temp[5];
            dice[5] = temp[6];
        }

        public void GoWest()
        {
            Dictionary<int, int> temp = new Dictionary<int, int>();
            temp = new Dictionary<int, int>(dice);

            dice[4] = temp[1];
            dice[2] = temp[2];
            dice[1] = temp[3];
            dice[6] = temp[4];
            dice[5] = temp[5];
            dice[3] = temp[6];
        }

        public void RotateRight()
        {
            Dictionary<int, int> temp = new Dictionary<int, int>();
            temp = new Dictionary<int, int>(dice);

            dice[1] = temp[1];
            dice[3] = temp[2];
            dice[5] = temp[3];
            dice[2] = temp[4];
            dice[4] = temp[5];
            dice[6] = temp[6];
        }

        public void RotateLeft()
        {
            Dictionary<int, int> temp = new Dictionary<int, int>();
            temp = new Dictionary<int, int>(dice);

            dice[1] = temp[1];
            dice[4] = temp[2];
            dice[2] = temp[3];
            dice[5] = temp[4];
            dice[3] = temp[5];
            dice[6] = temp[6];
        }

        public int GetNumber(int face)
        {
            return dice[face];
        }
    }
}

Measured memory_bytes: 6112