Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice II

Construct a dice from a given sequence of integers in the same way as Dice I.

You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I. Write a program to print an integer on the right side face.

Input

In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.
In the second line, the number of questions $q$ is given.

In the following $q$ lines, $q$ questions are given. Each question consists of two integers on the top face and the front face respectively.

Output

For each question, print the integer on the right side face.

Constraints

$0 \leq $ the integer assigned to a face $ \leq 100$

The integers are all different

$1 \leq q \leq 24$

Sample Input

1 2 3 4 5 6
3
6 5
1 3
3 2

Sample Output

3
5
6

Solution in C# (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _001_FindingMissingCards
{
    class Dice
    {
        private int[] num = new int[7];

        public Dice(int[] given)
        {
            num[1] = given[0];
            num[2] = given[1];
            num[3] = given[2];
            num[4] = given[3];
            num[5] = given[4];
            num[6] = given[5];
        }

        public int topNumber()
        {
            return num[1];
        }

        public int frontNumber()
        {
            return num[2];
        }
        public int rightNumber()
        {
            return num[3];
        }
        public int leftNumber()
        {
            return num[4];
        }
        public int backNumber()
        {
            return num[5];
        }

        public int bottomNumber()
        {
            return num[6];
        }

        private void moveNorth()
        {
            int tmp = num[1];
            num[1] = num[2];
            num[2] = num[6];
            num[6] = num[5];
            num[5] = tmp;
        }
        private void moveSouth()
        {
            moveNorth();
            moveNorth();
            moveNorth();
        }
        private void moveEast()
        {
            int tmp = num[1];
            num[1] = num[4];
            num[4] = num[6];
            num[6] = num[3];
            num[3] = tmp;
        }
        private void moveWest()
        {
            moveEast();
            moveEast();
            moveEast();
        }

        public void moveByCommand(char[] commands)
        {
            for (int i = 0; i < commands.Length; i++)
            {
                if (commands[i] == 'N')
                {
                    moveNorth();
                }
                else if (commands[i] == 'E')
                {
                    moveEast();
                }
                else if (commands[i] == 'W')
                {
                    moveWest();
                }
                else if (commands[i] == 'S')
                {
                    moveSouth();
                }

            }
        }

        public int getrightNumber(int topnum, int fronnum)
        {
            int x = 0;

            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    this.moveByCommand("E".ToCharArray());

                    if (topnum == this.topNumber() && fronnum == this.frontNumber())
                    {
                        x = this.rightNumber();
                    }
                }
                this.moveByCommand("N".ToCharArray());
                if (topnum == this.topNumber() && fronnum == this.frontNumber())
                {
                    x = this.rightNumber();
                }

            }

            this.moveByCommand("EN".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("SWWS".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            this.moveByCommand("E".ToCharArray());
            if (topnum == this.topNumber() && fronnum == this.frontNumber())
            {
                x = this.rightNumber();
            }
            

            return x;
        }
    }

    class Program
    {
        static void Main()
        {
            var tmp1 = Console.ReadLine().Split(' ');
            var sample1 = new int[tmp1.Length];
            for (int i = 0; i < tmp1.Length; i++)
            {
                sample1[i] = Convert.ToInt32(tmp1[i]);
            }
            Dice a = new Dice(sample1);


            var numSets = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < numSets; i++)
            {
                var trset = Console.ReadLine().Split(' ');
                var ans = a.getrightNumber(Convert.ToInt32(trset[0]),
                    Convert.ToInt32(trset[1]));
                Console.WriteLine(ans);

            }



            //var commands = Console.ReadLine().ToCharArray();




            //a.moveByCommand(commands);

            //Console.WriteLine(a.topNumber());

            /*
            var numOfComm = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < numOfComm; i++)
            {
                var commands = Console.ReadLine().Split(' ');
                Console.WriteLine(a.getrightNumber(Convert.ToInt32(commands[0]), Convert.ToInt32(commands[1])));
            }*/

        }
    }
}