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

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var oneLine = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var dice = new Dice(oneLine);
            //var rotateList = Console.ReadLine().Select(x => Enum.Parse(typeof(Direction), x.ToString())).ToList();
            //foreach (Direction direction in rotateList)
            //{
            //    dice.Rotate(direction);
            //}
            //Console.WriteLine(dice.Top);

            var n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                var diceNumber = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
                if (diceNumber[0] == dice.Right || diceNumber[0] == dice.Left)
                {
                    dice.RotateVertical(Direction.N);
                }

                while (dice.Top != diceNumber[0])
                {
                    dice.RotateHorizon(Direction.N);
                }

                while (dice.Front != diceNumber[1])
                {
                    dice.RotateVertical(Direction.N);
                }

                Console.WriteLine(dice.Left);
            }


        }
    }

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


        public Dice(IList<int> numbers)
        {
            //this.Number = numbers.ToArray();
            this.Top = numbers[0];
            this.Back = numbers[1];
            this.Right = numbers[2];
            this.Left = numbers[3];
            this.Front = numbers[4];
            this.Bottom = numbers[5];
        }


        public void RotateHorizon(Direction direction)
        {
            var tmp = this.Top;
            switch (direction)
            {
                case Direction.N:
                    this.Top = this.Back;
                    this.Back = this.Bottom;
                    this.Bottom = this.Front;
                    this.Front = tmp;
                    break;
                case Direction.E:
                    this.Top = this.Left;
                    this.Left = this.Bottom;
                    this.Bottom = this.Right;
                    this.Right = tmp;
                    break;
                case Direction.W:
                    this.Top = this.Right;
                    this.Right = this.Bottom;
                    this.Bottom = this.Left;
                    this.Left = tmp;
                    break;
                case Direction.S:
                    this.Top = this.Front;
                    this.Front = this.Bottom;
                    this.Bottom = this.Back;
                    this.Back = tmp;
                    break;
                default:
                    break;
            }
        }

        public void RotateVertical(Direction direction)
        {
            var tmp = this.Right;
            switch (direction)
            {
                case Direction.N:
                    this.Right = this.Back;
                    this.Back = this.Left;
                    this.Left = this.Front;
                    this.Front = tmp;
                    break;
                case Direction.S:
                    this.Right = this.Front;
                    this.Front = this.Left;
                    this.Left = this.Back;
                    this.Back = tmp;
                    break;
                default:
                    break;
            }
        }
    }

    /// <summary>
    /// ダイスを転がす方向
    /// </summary>
    public enum Direction
    {
        N,
        E,
        W,
        S
    }

}



Measured memory_bytes: 18392