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: Accepted)

using System;
class main{
    static void Main(string[] args){
        string[] line = Console.ReadLine().Split(' ');
        int[] numbers = new int[6];
        for(int i = 0;i<6;i++){
            numbers[i] = int.Parse(line[i]);
        }
        dice dice = new dice();
        dice.setNumbers(numbers);

        int orders = int.Parse(Console.ReadLine());
        for (int i = 0; i < orders; i++) {
            string[] data = Console.ReadLine().Split(' ');
            int top = int.Parse(data[0]);
            int south = int.Parse(data[1]);
            if (top == dice.N)
            {
                if (south == dice.T)
                {
                    Console.WriteLine(dice.E);
                }
                else if (south == dice.E)
                {
                    Console.WriteLine(dice.B);
                }
                else if (south == dice.W)
                {
                    Console.WriteLine(dice.T);
                }
                else if(south == dice.B)
                {
                    Console.WriteLine(dice.W);
                }
            }
            else if (top == dice.W) 
            {
                if (south == dice.T)
                {
                    Console.WriteLine(dice.N);
                }
                else if (south == dice.N)
                {
                    Console.WriteLine(dice.B);
                }
                else if (south == dice.S)
                {
                    Console.WriteLine(dice.T);
                }
                else if (south == dice.B)
                {
                    Console.WriteLine(dice.S);
                }
            }
            else if (top == dice.E)
            {
                if (south == dice.T)
                {
                    Console.WriteLine(dice.S);
                }
                else if (south == dice.N)
                {
                    Console.WriteLine(dice.T);
                }
                else if (south == dice.S)
                {
                    Console.WriteLine(dice.B);
                }
                else if (south == dice.B)
                {
                    Console.WriteLine(dice.N);
                }
            }
            else if(top == dice.S)
            {
                if (south == dice.T)
                {
                    Console.WriteLine(dice.W);
                }
                else if (south == dice.E)
                {
                    Console.WriteLine(dice.T);
                }
                else if (south == dice.W)
                {
                    Console.WriteLine(dice.B);
                }
                else if (south == dice.B)
                {
                    Console.WriteLine(dice.E);
                }
            }
            else if (top == dice.T)
            {
                if (south == dice.N)
                {
                    Console.WriteLine(dice.W);
                }
                else if (south == dice.E)
                {
                    Console.WriteLine(dice.N);
                }
                else if (south == dice.W)
                {
                    Console.WriteLine(dice.S);
                }
                else if (south == dice.S)
                {
                    Console.WriteLine(dice.E);
                }
            }
            else if (top == dice.B)
            {
                if (south == dice.N)
                {
                    Console.WriteLine(dice.E);
                }
                else if (south == dice.E)
                {
                    Console.WriteLine(dice.S);
                }
                else if (south == dice.W)
                {
                    Console.WriteLine(dice.N);
                }
                else if (south == dice.S)
                {
                    Console.WriteLine(dice.W);
                }
            }
        }
    }
}
class dice
{
    private int _T, _B, _N, _E, _W, _S;
    public int T { get { return _T; } set { _T = value; } }
    public int B { get { return _B; } set { _B = value; } }
    public int N { get { return _N; } set { _N = value; } }
    public int E { get { return _E; } set { _E = value; } }
    public int W { get { return _W; } set { _W = value; } }
    public int S { get { return _S; } set { _S = value; } }

    public dice(){
        _T= _B= _N= _E= _W= _S = 0;
    }

    public void setNumbers(int[] numbers)
    {
        _T = numbers[0];
        _S = numbers[1];
        _E = numbers[2];
        _W = numbers[3];
        _N = numbers[4];
        _B = numbers[5];
    }
}