using System;

namespace ITP1_11
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] dice = getdice();
            int q = int.Parse(Console.ReadLine());

            for (int i = 0; i < q; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                
                int x = checkdice(dice,int.Parse(input[0]),int.Parse(input[1]));
                Console.WriteLine(x);
            }
            
        }

        static int[] getdice()
        {
            int[] dice = new int[7];

            string[] input = Console.ReadLine().Split(' ');
            for (int i =1 ; i <= 6; i++)
            {
                dice[i] = int.Parse(input[i-1]);
            }

            return dice;
        }

        static int checkdice(int[] a, int b, int c)
        {
            while (a[1] != b | a[2] != c)
            {
                if (a[1] == b)
                {
                    while (a[2] != c)
                    {
                        int[] memo = new int[7];
                        for (int k = 1; k <= 6; k++)
                        {
                            memo[k] = a[k];
                        }
                        a[3] = memo[2];
                        a[2] = memo[4];
                        a[4] = memo[5];
                        a[5] = memo[3];
                    }
                }

                while (a[1] != b)
                {
                    int[] memo = new int[7];

                    if (a[3] == b)
                    {
                        for (int k = 1; k <= 6; k++)
                        {
                            memo[k] = a[k];
                        }
                        a[1] = memo[3];
                        a[3] = memo[6];
                        a[6] = memo[4];
                        a[4] = memo[1];
                        break;
                    }

                    if (a[4] == b)
                    {
                        for (int k = 1; k <= 6; k++)
                        {
                            memo[k] = a[k];
                        }
                        a[1] = memo[4];
                        a[4] = memo[6];
                        a[6] = memo[3];
                        a[3] = memo[1];
                        break;
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        for (int k = 1; k <= 6; k++)
                        {
                            memo[k] = a[k];
                        }
                        a[1] = memo[2];
                        a[2] = memo[6];
                        a[6] = memo[5];
                        a[5] = memo[1];
                        if (a[1] == b) break;
                    }


                }
            }
            return a[3];

        }

        static int turndice(string str)
        {
            int[] s = { 0, 1, 2, 3, 4, 5, 6 };
            for (int i = 0; i < str.Length; i++)
            {
                int[] memo = new int[7];
                for (int k = 1; k <= 6 ; k++)
                {
                    memo[k] = s[k];
                } 
                if (str[i] == 'E')
                {
                    s[1] = memo[4];
                    s[4] = memo[6];
                    s[6] = memo[3];
                    s[3] = memo[1];
                }
                else if(str[i] == 'N')
                {
                    s[1] = memo[2];
                    s[2] = memo[6];
                    s[6] = memo[5];
                    s[5] = memo[1];
                }
                else if (str[i] == 'S')
                {
                    s[1] = memo[5];
                    s[5] = memo[6];
                    s[6] = memo[2];
                    s[2] = memo[1];
                }
                else if (str[i] == 'W')
                {
                    s[1] = memo[3];
                    s[3] = memo[6];
                    s[6] = memo[4];
                    s[4] = memo[1];
                }
            }
            return s[1];
        }

       
    }
}

Measured memory_bytes: 9160