using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace Dice_II
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            Dice dice = new Dice(input);
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; ++i)
            {
                var work = Console.ReadLine().Split(' ');
                int a = int.Parse(work[0]);
                int b = int.Parse(work[1]);
                Console.WriteLine(dice.Right_Surface(a, b));
            }
        }
    }


    class Dice
    {
        private int[] surface;

        public Dice()
        {
            Console.WriteLine("???????????\????????????");
            Environment.Exit(-1);
        }
        public Dice(String[] str)
        {
            surface = new int[6];
            for (int i = 0; i < 6; ++i)
            {
                this.surface[i] = int.Parse(str[i]);
            }
        }// End_Constructor

        public int[] Get_Surface()
        {
            return this.surface;
        }
        public int Get_Surface(int n)
        {
            return this.surface[n];
        }

        public void Rotation(char c)
        {
            switch (c)
            {
                case 'E':
                    this.Rotation_E();
                    break;
                case 'N':
                    this.Rotation_N();
                    break;
                case 'S':
                    this.Rotation_S();
                    break;
                case 'W':
                    this.Rotation_W();
                    break;
                default:
                    Console.WriteLine("??\?????¨???????");
                    Environment.Exit(-1);
                    break;
            }
        }// End_Rotation

        private void Rotation_E()
        {
            this.Rotation_Run(0, 3, 5, 2);
        }

        private void Rotation_N()
        {
            this.Rotation_Run(0, 1, 5, 4);
        }

        private void Rotation_S()
        {
            this.Rotation_Run(0, 4, 5, 1);
        }
        private void Rotation_W()
        {
            this.Rotation_Run(0, 2, 5, 3);
        }

        static void Swap(ref int a, ref int b)
        {
            var t = a;
            a = b;
            b = t;
        }

        void Rotation_Run(int a, int b, int c, int d)
        {
            var work = this.surface[a];
            this.surface[a] = this.surface[b];
            this.surface[b] = this.surface[c];
            this.surface[c] = this.surface[d];
            this.surface[d] = work;
        }// End_Rotation_Run

        public int Right_Surface(int a, int b)
        {
            if (a == this.surface[0])
            {
                if (b == this.surface[1]) return this.surface[2];
                if (b == this.surface[2]) return this.surface[4];
                if (b == this.surface[3]) return this.surface[1];
                if (b == this.surface[4]) return this.surface[3];
            }   
            else if (a == this.surface[1])
            {
                if (b == this.surface[0]) return this.surface[3];
                if (b == this.surface[2]) return this.surface[0];
                if (b == this.surface[3]) return this.surface[5];
                if (b == this.surface[5]) return this.surface[2];
            }
            else if (a == this.surface[2])
            {
                if (b == this.surface[0]) return this.surface[1];
                if (b == this.surface[1]) return this.surface[5];
                if (b == this.surface[5]) return this.surface[4];
                if (b == this.surface[4]) return this.surface[0];
            }
            else if (a == this.surface[3])
            {
                if (b == this.surface[0]) return this.surface[4];
                if (b == this.surface[1]) return this.surface[0];
                if (b == this.surface[4]) return this.surface[5];
                if (b == this.surface[5]) return this.surface[1];
            }
            else if (a == this.surface[4])
            {
                if (b == this.surface[0]) return this.surface[2];
                if (b == this.surface[2]) return this.surface[5];
                if (b == this.surface[3]) return this.surface[0];
                if (b == this.surface[5]) return this.surface[3];
            }
            else if (a == this.surface[5])
            {
                if (b == this.surface[1]) return this.surface[3];
                if (b == this.surface[2]) return this.surface[1];
                if (b == this.surface[3]) return this.surface[4];
                if (b == this.surface[4]) return this.surface[2];
            }
            else
            {
                Console.WriteLine("???????????????");
                return -1;
            }
            return -1;
        }// End_Right_Surface
    }// End_CLass
}


Measured memory_bytes: 9100