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;

public class Program
{
    /// <summary>
    /// プログラムエントリポイント
    /// </summary>
    public static void Main()
    {
        //サイコロの目入力
        string[] aryStrDice = Console.ReadLine().Split(' ');

        //置き換え用のint[]の宣言
        int[] aryIntDice = new int[6];

        //入力されたサイコロの目をint[]に置き換える
        for (int i = 0; i < 6; i++)
        {
            aryIntDice[i] = int.Parse(aryStrDice[i]);
        }

        //問題回数を入力
        int countQ = int.Parse(Console.ReadLine());

        //Diceクラスのインスタンス生成
        Dice insDice = new Dice(aryIntDice);

        //入力された countQ 回数分繰り返す
        for( int i = 0 ; i < countQ ; i++ )
        {
            //サイコロの　上面　前面　を入力
            string[] inputData = Console.ReadLine().Split(' ');
            //メソッド ( 引数 入力された 上面,前面 ) の戻り値を出力
            Console.WriteLine( insDice.serachRightOfDice(int.Parse(inputData[0]),int.Parse(inputData[1])) );
        }

    }

}

/// <summary>
/// Diceクラス
/// </summary>
class Dice
{
    int[] aryIntDice;

    /// <summary>
    /// コンストラクタ
    /// </summary>
    /// <param name="aryIntDice">int[] サイコロの目</param>
    public Dice(int[] aryIntDice)
    {
        this.aryIntDice = aryIntDice;
    }

    /// <summary>
    /// サイコロを動かして入力された　上面と前面　にあわせて
    /// その状態の右面を返す
    /// </summary>
    /// <param name="topOfDice">サイコロの目　上面</param>
    /// <param name="frontOfDice">サイコロの目　前面</param>
    /// <returns>サイコロの目　右面</returns>
    public int serachRightOfDice(int topOfDice, int frontOfDice)
    {
        //N方向に４回動かして topOfDice と サイコロの目 が同じなら抜ける
        for (int i = 0; i < 4; i++)
        {
            if (this.aryIntDice[0] == topOfDice)
            {
                break;
            }
            //N方向に動かす
            runOperationN();
        }

        //E方向に４回動かして topOfDice と サイコロの目 が同じなら抜ける
        for (int i = 0; i < 4; i++)
        {
            if (this.aryIntDice[0] == topOfDice)
            {
                break;
            }
            //E方向に動かす
            runOperationE();
        }

        //４回 R 回転して frontOfDice と サイコロの目 が同じなら抜ける
        for (int i = 0; i < 4; i++)
        {
            if (this.aryIntDice[1] == frontOfDice)
            {
                break;
            }
            //右に回転させる
            runOperationR();
        }

        //サイコロの目　右側を返す
        return aryIntDice[2];

    }

    /// <summary>
    /// サイコロを命令に従って動かす E方向
    /// </summary>
    private void runOperationE()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[3];
        aryIntDice[3] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[2];
        aryIntDice[2] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす N方向
    /// </summary>
    private void runOperationN()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[1];
        aryIntDice[1] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[4];
        aryIntDice[4] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす S方向
    /// </summary>
    private void runOperationS()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[4];
        aryIntDice[4] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[1];
        aryIntDice[1] = tmpStorage;
    }
    /// <summary>
    /// サイコロを命令に従って動かす W方向
    /// </summary>
    private void runOperationW()
    {
        int tmpStorage = aryIntDice[0];
        aryIntDice[0] = aryIntDice[2];
        aryIntDice[2] = aryIntDice[5];
        aryIntDice[5] = aryIntDice[3];
        aryIntDice[3] = tmpStorage;
    }

    /// <summary>
    /// サイコロを命令に従って動かす 右ロール
    /// </summary>
    private void runOperationR()
    {
        int tmpStorage = aryIntDice[1];
        aryIntDice[1] = aryIntDice[2];
        aryIntDice[2] = aryIntDice[4];
        aryIntDice[4] = aryIntDice[3];
        aryIntDice[3] = tmpStorage;
    }

}