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

namespace LogicSummoner
{
    class Program
    {
        enum Directoin
        {
            N,
            E,
            W,
            S,
            U,
            D,
        }

        class Dice
        {
            private int[] nums = new int[6];
            private List<Directoin> dirs;
            public Dice(IEnumerable<int> nums)
            {
                this.nums = nums.ToArray();
                dirs = new List<Directoin>()
                {
                    Directoin.U,
                    Directoin.S,
                    Directoin.E,
                    Directoin.W,
                    Directoin.N,
                    Directoin.D,
                };
            }
            public void Roll(Directoin roll)
            {
                switch (roll)
                {
                    case Directoin.N:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.E:
                                    break;
                                case Directoin.W:
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.S;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.E:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.S:
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.W;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.W:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.S:
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.E;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.S:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.U;
                                    break;
                                case Directoin.E:
                                    break;
                                case Directoin.W:
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.D;
                                    break;
                                case Directoin.U:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.D:
                                    dirs[i] = Directoin.N;
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            public void Rotate(Directoin rotate)
            {
                switch (rotate)
                {
                    case Directoin.E:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.U:
                                case Directoin.D:
                                default:
                                    break;
                            }
                        }
                        break;
                    case Directoin.W:
                        for (int i = 0; i < dirs.Count; i++)
                        {
                            switch (dirs[i])
                            {
                                case Directoin.N:
                                    dirs[i] = Directoin.W;
                                    break;
                                case Directoin.E:
                                    dirs[i] = Directoin.N;
                                    break;
                                case Directoin.W:
                                    dirs[i] = Directoin.S;
                                    break;
                                case Directoin.S:
                                    dirs[i] = Directoin.E;
                                    break;
                                case Directoin.U:
                                case Directoin.D:
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            public int Getnum(Directoin dir)
            {
                return nums[dirs.IndexOf(dir)];
            }
        }

        static void Main(string[] args)
        {
            var nums = GetNumbersInt();
            var q = GetNumber();
            var rolls = new[]
            {
                Directoin.S,
                Directoin.S,
                Directoin.S,
                Directoin.S,
                Directoin.W,
                Directoin.W,
                Directoin.W,
            };
            var rotates = new[]
            {
                Directoin.W,
                Directoin.W,
                Directoin.W,
                Directoin.W
            };
            for (int i = 0; i < q; i++)
            {
                var area = GetNumbersInt();
                var dice = new Dice(nums);
                foreach (var roll in rolls)
                {
                    dice.Roll(roll);
                    if (dice.Getnum(Directoin.U) == area[0])
                    {
                        break;
                    }
                }
                foreach (var rotate in rotates)
                {
                    dice.Rotate(rotate);
                    if (dice.Getnum(Directoin.S) == area[1])
                    {
                        System.Console.WriteLine(dice.Getnum(Directoin.E));
                        break;
                    }
                }
            }
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}

Measured memory_bytes: 10092