using System;

namespace AOJ
{
    class Program
    {
        
        static void Main(string[] args)
        {
            var read = Console.ReadLine();
            var dice_surface_arry = read.Split();
            var dice_obj = new dice(dice_surface_arry);

            read = Console.ReadLine();
            int roop_num = int.Parse(read);

            for (var i = 0; i < roop_num;i++ )
            {
                read = Console.ReadLine();
                var direction = read.Split(' ');
                Console.WriteLine(dice_obj.dice_direction(int.Parse(direction[0]),int.Parse(direction[1])));
                
            }
        }

    }

    //?????????????????????
    class dice
    {
        //?????????????????¨??¢
        int[] dice_surface = new int [6];
        
        //??????????????????????????¨??¢??????????????£?????????
        public dice(string[] sueface_temp)
        {
            for(var i=0;i<dice_surface.Length;i++)
            {
                dice_surface[i] = int.Parse(sueface_temp[i]);
            }
        }

        //?????????????????¨?????\??¬????????????????????????
        public int dice_emulate(string order)
        {
            int[] dice_temp = new int[6];

            for (var i = 0; i < order.Length;i++ )
            {
                switch(order.Substring(i,1))
                {
                    case"N":
                        {
                            dice_temp[0] = dice_surface[0];
                            dice_temp[1] = dice_surface[1];
                            dice_temp[4] = dice_surface[4];
                            dice_temp[5] = dice_surface[5];

                            dice_surface[4] = dice_temp[0];
                            dice_surface[0] = dice_temp[1];
                            dice_surface[1] = dice_temp[5];
                            dice_surface[5] = dice_temp[4];

                            break;
                        }
                    case "S":
                        {
                            dice_temp[0] = dice_surface[0];
                            dice_temp[1] = dice_surface[1];
                            dice_temp[4] = dice_surface[4];
                            dice_temp[5] = dice_surface[5];

                            dice_surface[0] = dice_temp[4];
                            dice_surface[1] = dice_temp[0];
                            dice_surface[5] = dice_temp[1];
                            dice_surface[4] = dice_temp[5];
                            break;
                        }
                    case"E":
                        {
                            dice_temp[0] = dice_surface[0];
                            dice_temp[2] = dice_surface[2];
                            dice_temp[3] = dice_surface[3];
                            dice_temp[5] = dice_surface[5];

                            dice_surface[0] = dice_temp[3];
                            dice_surface[2] = dice_temp[0];
                            dice_surface[3] = dice_temp[5];
                            dice_surface[5] = dice_temp[2];

                            break;
                        }

                    case"W":
                        {
                            dice_temp[0] = dice_surface[0];
                            dice_temp[2] = dice_surface[2];
                            dice_temp[3] = dice_surface[3];
                            dice_temp[5] = dice_surface[5];

                            dice_surface[3] = dice_temp[0];
                            dice_surface[0] = dice_temp[2];
                            dice_surface[5] = dice_temp[3];
                            dice_surface[2] = dice_temp[5];
                            break;
                        }
                }

            }

                return dice_surface[0];
        }

        void dice_horizone_rotation(string course)
        {
            switch(course)
            {
                case"right":
                    {

                        break;
                    }
                case"left":
                    {

                        break;
                    }
            }
        }

        public int dice_direction(int up,int front)
        {
            int directio_up=0,direction_front=0;

            for (var i = 0; i < dice_surface.Length;i++ )
            {
                if(dice_surface[i]==up)
                {
                    directio_up = i+1;
                }
            }

            for (var i = 0; i < dice_surface.Length; i++)
            {
                if (dice_surface[i] == front)
                {
                    direction_front = i+1;
                }
            }
            switch (directio_up)
            {
                case 1:
                    {
                        switch(direction_front)
                        {
                            case 2:
                                return dice_surface[2];

                            case 3:
                                return dice_surface[4];

                            case 4:
                                return dice_surface[1];

                            case 5:
                                return dice_surface[3];
                        }

                        break;
                    }
                case 2:
                    {
                        switch (direction_front)
                        {
                            case 1:
                                return dice_surface[3];

                            case 3:
                                return dice_surface[0];

                            case 4:
                                return dice_surface[5];

                            case 6:
                                return dice_surface[2];
                        }
                        break;
                    }
                case 3:
                    {
                        switch (direction_front)
                        {
                            case 1:
                                return dice_surface[1];

                            case 2:
                                return dice_surface[5];

                            case 5:
                                return dice_surface[0];

                            case 6:
                                return dice_surface[4];
                        }
                        break;
                    }

                case 4:
                    {
                        switch (direction_front)
                        {
                            case 1:
                                return dice_surface[4];

                            case 2:
                                return dice_surface[0];

                            case 5:
                                return dice_surface[5];

                            case 6:
                                return dice_surface[1];
                        }
                        break;
                    }
                case 5:
                    {
                        switch (direction_front)
                        {
                            case 1:
                                return dice_surface[2];

                            case 3:
                                return dice_surface[5];

                            case 4:
                                return dice_surface[0];

                            case 6:
                                return dice_surface[3];
                        }
                        break;
                    }
                case 6:
                    {
                        switch (direction_front)
                        {
                            case 2:
                                return dice_surface[3];

                            case 3:
                                return dice_surface[1];

                            case 4:
                                return dice_surface[4];

                            case 5:
                                return dice_surface[2];
                        }
                        break;
                    }
            }

            return 0;

        }

    }
}

Measured memory_bytes: 9120