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;

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 right)
        {
            int directio_up=0,direction_right=0;

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

            for (var i = 0; i < dice_surface.Length; i++)
            {
                if (dice_surface[i] == right)
                {
                    direction_right = i;
                }
            }
            switch (directio_up+1)
            {
                case 1:
                    {
                        switch(direction_right)
                        {
                            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;
                    }
                case 2:
                    {
                        switch (direction_right)
                        {
                            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 3:
                    {
                        switch (direction_right)
                        {
                            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 4:
                    {
                        switch (direction_right)
                        {
                            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 5:
                    {
                        switch (direction_right)
                        {
                            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 6:
                    {
                        switch (direction_right)
                        {
                            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;
                    }
            }

            return 0;

        }

    }
}