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 ITP1_11_B
{
    class Dice
    {
        private int[,] adj = new int[6, 4] { { 2, 3, 5, 4 }, { 1, 4, 6, 3 }, { 1, 2, 6, 5 }, { 1, 5, 6, 2 }, { 1, 3, 6, 4 }, { 2, 4, 5, 3 } };
        public int Top { get; private set; }
        public int North { get; private set; }
        public Dice(int top = 1, int north = 5) { Top = top; North = north; }

        public int GetRight(int top, int front)
        {
            int index = GetIndex(top, front);
            return adj[top - 1, (index + 1) % 4];
        }

        private int GetIndex(int top, int val)
        {
            for (int i = 0; i < 4; i++) if (adj[top - 1, i] == val) return i;
            throw new Exception();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int[] a = Array.ConvertAll(strs, int.Parse);
            int n = int.Parse(Console.ReadLine());
            Dice dice = new Dice();
            for (int i = 0; i < n; i++)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                Console.WriteLine(dice.GetRight(GetNum(a,input[0]),GetNum(a,input[1])));
            }    
        }

        static int GetNum(int[] array,int val)
        {
            for (int i = 0; i < array.Length; i++) if (array[i] == val) return i+1;
            throw new Exception();
        }
    }
}