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];
    }
}

Measured memory_bytes: 5608