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



Sample input:
1 2 3 4 5 6
3
6 5
1 3
3 2


Sample output:
3
5
6

Submission status: Runtime Error

Solution code:
class dice_2:
    def __init__(self,label):
        self.spots = label

    def result(self,top,front):
        if top == 1:
            self.order=[2,3,5,4,2]
        elif top == 2:
            self.order=[6,3,1,4,6]
        elif top == 3:
            self.order=[2,6,5,1,2]
        elif top == 4:
            self.order=[2,1,5,6,2]
        elif top == 5:
            self.order=[1,3,6,4,1]
        elif top == 6:
            self.order=[2,4,5,3,2]

        for i in range(4):
            if self.order[i] == front:
                self.right = self.order[i+1]

    def output(self):
        print(self.spots[self.right-1])

label = list(map(int,input().split()))
dice = dice_2(label)
for i in range(int(input())):
    top,front = map(int,(input().split()))
    dice.result(top,front)
    dice.output()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
from sys         import exit
from collections import Iterable
from unittest    import TestCase
import random

import numpy as np

def top_face_after_rolling_dice():
    try:
        faces    = [int(num) for num in input().rstrip().split()]
        rollings = input().rstrip()
    except:
        return __input_error()

    dice = ArbitraryValueCubicDice(faces[0], faces[1], faces[2], faces[3], faces[4], faces[5])
    dice.put(dice.TOP, dice.SOUTH, dice.EAST, dice.WEST, dice.NORTH, dice.BOTTOM)
#    dice.throw()
    for operator in rollings:
        dice.roll(operator)

    print(dice.get_value(dice.TOP))

class ArbitraryValueCubicDice():
    
    (TOP, BOTTOM, EAST, WEST, SOUTH, NORTH, RIGHT, LEFT) = ("top", "bottom", "E", "W", "S", "N", "R", "L")
    (stVALUE, stDIRECTION) = ("value", "direction")

    (plus_x, minus_x, plus_y, minus_y, plus_z, minus_z) = ( (1,0,0), (-1,0,0), (0,1,0), (0,-1,0), (0,0,1), (0,0,-1) )

#    ROLL_x2y = ( ( 0,-1, 0), ( 1, 0, 0), ( 0, 0, 1) )
#    ROLL_y2x = ( ( 0, 1, 0), (-1, 0, 0), ( 0, 0, 1) )
#    ROLL_y2z = ( ( 1, 0, 0), ( 0, 0,-1), ( 0, 1, 0) )
#    ROLL_z2y = ( ( 1, 0, 0), ( 0, 0, 1), ( 0,-1, 0) )
#    ROLL_z2x = ( ( 0, 0, 1), ( 0, 1, 0), (-1, 0, 0) )
#    ROLL_x2z = ( ( 0, 0,-1), ( 0, 1, 0), ( 1, 0, 0) )

    ROLL_x2y = np.array([ [ 0,-1, 0], [ 1, 0, 0], [ 0, 0, 1] ])
    ROLL_y2x = np.array([ [ 0, 1, 0], [-1, 0, 0], [ 0, 0, 1] ])
    ROLL_y2z = np.array([ [ 1, 0, 0], [ 0, 0,-1], [ 0, 1, 0] ])
    ROLL_z2y = np.array([ [ 1, 0, 0], [ 0, 0, 1], [ 0,-1, 0] ])
    ROLL_z2x = np.array([ [ 0, 0, 1], [ 0, 1, 0], [-1, 0, 0] ])
    ROLL_x2z = np.array([ [ 0, 0,-1], [ 0, 1, 0], [ 1, 0, 0] ])

    DIRECTION = { EAST : plus_x,   WEST : minus_x,  NORTH : plus_y,   SOUTH : minus_y,  TOP   : plus_z,   BOTTOM : minus_z }
    OPERATOR  = { EAST : ROLL_z2x, WEST : ROLL_x2z, NORTH : ROLL_z2y, SOUTH : ROLL_y2z, RIGHT : ROLL_y2x, LEFT   : ROLL_x2y }
    
    #??¢???index??§?????????,???????????????
    def __init__(self, n_f0, n_f1, n_f2, n_f3, n_f4, n_f5):
        self.info = [ {self.stVALUE: n_fi} for n_fi in [n_f0, n_f1, n_f2, n_f3, n_f4, n_f5]]

    def put(self, dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5):  #?????°????????£?????????
        for (info, dir_fi) in zip(self.info, [dir_f0, dir_f1, dir_f2, dir_f3, dir_f4, dir_f5]):
            info[self.stDIRECTION] = self.DIRECTION[dir_fi]

    def roll(self, operator) : #opetator: (EAST, WEST, SOUTH, NORTH, RIGHT, LEFT) ??????????????????
        for info in self.info:
#            info[self.stDIRECTION] = tuple( np.dot(self.OPERATOR[operator], np.array(info[self.stDIRECTION])))
            vector = info[self.stDIRECTION]
            matrix = self.OPERATOR[operator]
            info[self.stDIRECTION] = tuple([sum( [matrix[row][col]*vector[col] for col in range(len(vector))] ) for row in range(len(matrix))])
            
    def throw(self,roll_times = 20):
        operators = tuple(self.OPERATOR.keys())
        for i in range(roll_times):
            self.roll(operators[random.randrange(len(operators))])
    
    def re_put(self, top = None, bottom = None, east = None, west = None, north = None, south = None):
        inputdata = [ {} for i in range(6) ]
        
        dir_key = (self.TOP, self.BOTTOM, self.EAST, self.WEST, self.NORTH, self.SOUTH)
        for (key, value) in zip(dir_key, (top, bottom, east, west, north, south)):
            if value is not None :
                inputdata[self.__get_index(value = value)] = {self.stDIRECTION : self.DIRECTION[key], self.stVALUE: value } 

        current_info = [ self.info[i] if inputdata[i] else {} for i in range(len(inputdata)) ]

        before_vectors = []
        after_vectors  = []
        
        index = 0
        for before, after in zip(current_info, inputdata):
            if before :
                for i in range(index):
                    if np.dot( np.array(before_vectors[i]), np.array(before[self.stDIRECTION]) ) != 0 :
                        break
                else :
                    before_vectors.append( before[self.stDIRECTION] )
                    after_vectors .append( after[self.stDIRECTION]    )
                    index += 1
            if index > 1 :
                break
        
        if len(before_vectors) == 0 :
            return None
        elif len(before_vectors) == 1 :
            pass
        elif len(before_vectors) == 2 :
            before_vectors.append( tuple( np.cross( np.array(before_vectors[0]), np.array(before_vectors[1]) ) ) )
            after_vectors .append( tuple( np.cross( np.array( after_vectors[0]), np.array( after_vectors[1]) ) ) )
        
        before_vectors = np.array( before_vectors ).T
        after_vectors  = np.array(  after_vectors ).T

        operator_matrix = np.dot( after_vectors, np.linalg.inv( before_vectors ) ).astype(np.int)

        for before, after in zip(current_info, inputdata):
            if before :

                if after[self.stDIRECTION] != tuple( np.dot( operator_matrix, np.array(before[self.stDIRECTION]) ) ):
                    return None
        
        for info in self.info:
            info[self.stDIRECTION] = tuple ( np.dot( operator_matrix, np.array(info[self.stDIRECTION]) ) )
            
    def get_value(self, direction):
        for info in self.info:
            if info[self.stDIRECTION] == self.DIRECTION[direction] :
                return info[self.stVALUE]
    
    def get_direction(self, value, vector = False):
        for info in self.info:
            if info[self.stVALUE] != value :
                continue
            if vector :
                return info[self.stDIRECTION]

            dir_key_values = self.DIRECTION.items()
            for items in dir_key_values:
                if info[self.stDIRECTION] in items:
                        return items[0] #string
    
    def __get_index(self, dir_vector = None, value = None, dir_key = None):
        for i,info in enumerate(self.info):
            if (dir_vector is not None) or (dir_key is not None):
                if info[self.stDIRECTION] in (dir_vector, self.DIRECTION.get(dir_key)) :
                    return i
            elif value is not None :
                if info[self.stVALUE] == value :
                    return i
    
    def __matrix_product(self, matrix_left, matrix_right):
        return([ [sum( [matrix_left[i][j]*matrix_right[j][k] for j in range(len(matrix_right))] ) for k in range(len(matrix_right[0]))] for i in range(len(matrix_left)) ])

    def __outer_product(self, vector_left, vector_right):   #each vector must have 3 elements.
        return tuple( [ vector_left[i-2] * vector_right[i-1] - vector_left[i-1] * vector_right[i-2] for i in range(3)] )

def __input_error():
    print("input error")
    return -1
    

class __TestValueClass(TestCase):
    def testEqual(self, func, tuples, eff_digit = None, print_success = False):
        self.testFunction(self.assertEqual,func,tuples,eff_digit,print_success)
    
    def testFunction(self,assertfunc,func,tuples,eff_digit,print_success):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], Iterable):
                    value = func(*item[0])
                else:
                    value = func(item[0])
                
                if eff_digit is None :
                    assertfunc(value,item[1])
                else :
                    format_str = "{0:."+str(eff_digit)+"g}"
                    assertfunc(format_str.format(value),format_str.format(item[1]))
                    
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                info = []
                info.append(["arguments"     , item[0]    ])
                info.append(["compared value", item[1]    ])
                info.append(["message"       , "\n" + msg ])
                for info_state in info :
                    print(info_state[0].ljust(swidth) + ":", info_state[1])
                exit()

        if print_success :
            print(func.__name__,": succeeded")

#test
if __name__ == "__main__" :
#    test = __TestValueClass()
    top_face_after_rolling_dice()

Submission status: Runtime Error

Solution code:
#ITP1_11-B Dice 2
rep=[
    [0,0,0,0,0],
    [2,3,5,4,2],
    [3,1,4,6,3],
    [1,2,6,5,1],
    [1,5,6,2,1],
    [1,3,6,4,1],
    [2,4,5,3,2]
]
d = input().split(" ")
q = int(input())

for i in range(q):
    a,b = [int(x) for x in input().split(" ")]
    for j in range(4):
        if(rep[a][j]==b):
            print(rep[a][j+1])

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self):
        self.face = {12:3, 13:5, 14:2, 15:4, 21:4, 23:1, 24:6, 26:3, 31:2, 32:6, 35:1, 36:5, 41:5, 42:1, 45:6, 46:2, 51:3, 53:6, 54:1, 56:4, 62:4, 63:2, 64:5, 65:3}
    
    def right_face(self, face):
        return self.face[face]

d = Dice()
dice = [dice for dice in input().split()]
q = int(input())
for i in range(q):
    face = input().split()
    face = int("".join(face))
    n = d.right_face(face)
    print(dice[n-1])

Submission status: Runtime Error

Solution code:
class Dice():
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def rotate_north(self):
        self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north
    
    def rotate_south(self):
        self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south

    def rotate_west(self):
        self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom

    def rotate_east(self):
        self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east
        
dice = Dice(list(map(int,input().split())))
q = int(input())

for i in range(q):
    rot = list(map(int,input().split()))
    if rot[0]==dice.top:
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.west:
        dice.rotate_east()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.bottom:
        dice.rotate_east()
        dice.rotate_east()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.east:
        dice.rotate_west()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.north:
        dice.rotate_south()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.south():
        dice.rotate_north()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    print(h)

Submission status: Runtime Error

Solution code:
class Converter:
    d = {
        "1 2": 2,
        "1 3": 4,
        "1 4": 1,
        "1 5": 3,
        "2 1": 3,
        "2 3": 0,
        "2 4": 5,
        "2 6": 2,
        "3 1": 1,
        "3 2": 5,
        "3 5": 0,
        "3 6": 4,
        "4 1": 4,
        "4 2": 0,
        "4 5": 5,
        "4 6": 1,
        "5 1": 2,
        "5 3": 5,
        "5 4": 0,
        "5 6": 3,
        "6 2": 3,
        "6 3": 1,
        "6 4": 4,
        "6 5": 2,
        }

    def __init__(self, s):
        self.pip = s.split()

    def __call__(self, s):
        print(self.pip[self.d[s]])

cv = Converter(input())
n = int(input())
for _ in range(n):
    cv(input())

Submission status: Runtime Error

Solution code:
class Dice2(Dice1):

    def __init__(self, v): # v [Top, Front, Right, Left, Back, Bottom ]
        super().__init__(v)

        self.dTFR = {}
        for i, j, k in ((ii, (ii++2)%6, (ii+4)%6) for ii in  range(6)):
            self.dTFR[self.view[i]]=[self.view[v] for v in (j, k, 5-j, 5-k, j)]


d2, q = Dice2(list(map(int, input().split()))), int(input())
for i in range(q):
    t, f = map(int, input().split())
    print(d2.dTFR[t][d2.dTFR[t].index(f)+1] )

Submission status: Runtime Error

Solution code:
#include <queue>
#include <vector>
#include <string>
#include <cassert>
#include <iostream>
#include <algorithm>
 
enum class Direction
{
    North = 0,
    East,
    South,
    West,
};
 
struct Number
{
    Number(int t, int f, int r, int l, int b, int btm)
        :top(t), front(f), right(r), left(l), back(b), bottom(btm) {}
 
    int top;
    int front;
    int right;
    int left;
    int back;
    int bottom;
};
 
bool operator==(const Number &lhs, const Number &rhs)
{
    return
        lhs.top == rhs.top &&
        lhs.front == rhs.front &&
        lhs.right == rhs.right &&
        lhs.left == rhs.left &&
        lhs.back == rhs.back &&
        lhs.bottom == rhs.bottom;
}
 
class Dice
{
    public:
        explicit Dice(const Number &number) :number_(number) {}
 
        Dice rotate_to(Direction direction) const
        {
            const Number number = [&](Direction direction) {
                switch(direction)
                {
                    default:
                        assert(!"Invalid Direction.");
                    case Direction::North:
                        return Number(number_.front, number_.bottom, number_.right, number_.left, number_.top, number_.back);
                    case Direction::East:
                        return Number(number_.left, number_.front, number_.top, number_.bottom, number_.back, number_.right);
                    case Direction::South:
                        return Number(number_.back, number_.top, number_.right, number_.left, number_.bottom, number_.front);
                    case Direction::West:
                        return Number(number_.right, number_.front, number_.bottom, number_.top, number_.back, number_.left);
                }
            }(direction);
            return Dice(number);
        }
 
        Number number() const { return number_; }
 
    private:
        Number number_;
};
 
bool operator==(const Dice &lhs, const Dice &rhs)
{
    return lhs.number() == rhs.number();
}
 
Dice make_dice()
{
    int top, front, right, left, back, bottom;
    std::cin >> top >> front >> right >> left >> back >> bottom;
    Number number(top, front, right, left, back, bottom);
    Dice dice(number);
    return dice;
}
 
bool exist(const Dice & dice, const std::vector<Dice> &memo)
{
    return std::find(memo.begin(), memo.end(), dice) != memo.end();
}
 
int solve_core(std::queue<Dice> &dices, std::vector<Dice> &memo, int top, int front)
{
    const std::vector<Direction> directions = { Direction::North, Direction::East, Direction::South, Direction::West };
    while(true)
    {
        for(const auto &direction : directions)
        {
            const auto dice = dices.front().rotate_to(direction);
            const auto number = dice.number();
            if(number.top == top && number.front == front)
            {
                return number.right;
            }
            if(exist(dice, memo))
            {
                continue;
            }
            dices.push(dice);
        }
        dices.pop();
    }
}
 
std::vector<int> solve()
{
    const auto dice = make_dice();
    int questions;
    std::cin >> questions;
    std::vector<int> ans;
    for(int i = 0; i < questions; ++i)
    {
        int top, front;
        std::cin >> top >> front;
        std::vector<Dice> memo = { dice };
        std::queue<Dice> dices; dices.push(dice);
        ans.push_back(solve_core(dices, memo, top, front));
    }
    return ans;
}
 
int main()
{
    const auto ans = solve();
    for(const auto &e : ans)
    {
        std::cout << e << std::endl;
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
d=input().split()
n={0:(1,2,4,3,1),1:(0,3,5,2,0),2:(0,1,5,4,0),3:(1,0,4,5,1),4:(0,2,5,3,0),5:(1,3,4,2,1)}
for _ in range(int(input())):
 t,f=[d.index(s) for s in input().split()]
 n=n[int(t)]
 print(d[n[n.index(int(f))+1]])

Submission status: Runtime Error

Solution code:
def face(x,y,dice):
    if (x==dice[5] and y==dice[4])or(x==dice[4] and y==dice[0])or(x==dice[0] and y==dice[1])or(x==dice[1] and y==dice[5]):
        return dice[2]
    elif (x==dice[0] and y==dice[2])or(x==dice[2] and y==dice[5])or(x==dice[5] and y==dice[3])or(x==dice[3] and y==dice[0]):
        return dice[4]
    elif (y==dice[5] and x==dice[4])or(y==dice[4] and x==dice[0])or(y==dice[0] and x==dice[1])or(y==dice[1] and x==dice[5]):
        return dice[3]
    elif (y==dice[0] and x==dice[2])or(y==dice[2] and x==dice[5])or(y==dice[5] and x==dice[3])or(y==dice[3] and x==dice[0]):
        return dice[1]
    elif (x==dice[2] and y==dice[1])or(x==dice[1] and y==dice[3])or(x==dice[3] and y==dice[4])or(x==dice[4] and y==dice[2]):
        return dice[5]
    else:
        return dice[0]
         
 
for i in range(n):
    a,b=map(int,raw_input().split())
    print face(a,b,l)

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self, top, dside):
        self.top = top
        self.dside = dside
        self.rside = None
        self.num = [self.top, self.dside, 7-self.top, 7-self.dside]
    def rside_num(self):
        if 2 in self.num and 3 in self.num:
            if(self.num.index(3)==self.num.index(2)+1 or 
                self.num==[3, 5, 4, 2]):
                self.rside = 1
            else:
                self.rside = 6
        elif 1 in self.num and 4 in self.num:
            if(self.num.index(4)==self.num.index(1)+1 or 
                self.num==[3, 6, 4, 1]):
                self.rside = 2
            else:
                self.rside = 5
        else:
            if(self.num.index(2)==self.num.index(1)+1 or
                self.num==[2, 6, 5, 1]):
                self.rside = 3
            else:
                self.rside = 4

num = list(map(int, input().split()))
n = int(input())
for i in range(n):
    value = list(map(int, input().split()))
    dice = Dice((num.index(value[0])+1), (num.index(value[1]+1)))
    dice.rside_num()
    print(dice.rside)

Submission status: Runtime Error

Solution code:
class Dice2():
    def front(self,up,front,dice):
        #index == 5
        if (up==dice[2] and front==dice[1])
        or(up==dice[1] and front==dice[3])
        or(up==dice[3] and front==dice[4])
        or(up==dice[4] and front==dice[2]):
            return dice[5]
        #index == 4
        elif (up==dice[0] and front==dice[2])
        or(up==dice[2] and front==dice[5])
        or(up==dice[5] and front==dice[3])
        or(up==dice[3] and front==dice[0]):
            return dice[4]
        #index == 3
        elif (front==dice[5] and up==dice[4])
        or(front==dice[4] and up==dice[0])
        or(front==dice[0] and up==dice[1])
        or(front==dice[1] and up==dice[5]):
            return dice[3]
        #index == 2
        elif (up==dice[5] and front==dice[4])
        or(up==dice[4] and front==dice[0])
        or(up==dice[0] and front==dice[1])
        or(up==dice[1] and front==dice[5]):
            return dice[2]
        #index == 1
        elif (front==dice[0] and up==dice[2])
        or(front==dice[2] and up==dice[5])
        or(front==dice[5] and up==dice[3])
        or(front==dice[3] and up==dice[0]):
            return dice[1]
        #index == 0
        else:
            return dice[0]

dice = [int(i) for i in input().split()]
p = int(input())
dc2 = Dice2()
ans = []
for i in range(p):
    up,front = map(int,input().split())
    ans.append(dc2.front(up,front,dice))
for i in range(p):
    print(ans[i])

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self,t,f,r,l,b,u):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.b = b
        self.u = u
        self.a=[t,f,r,l,b,u]
        self.direction={'S':(4,0,2,3,5,1),'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),'Y':(0,3,1,4,2,5)}
    def roll(self,d):
        self.a=[self.a[i] for i in self.direction[d]]
        self.t = self.a[0]
        self.f = self.a[1]
        self.r = self.a[2]
        self.l = self.a[3]
        self.b = self.a[4]
        self.u = self.a[5]
t,f,r,l,b,u=map(int,input().split())
dice1=Dice(t,f,r,l,b,u)
t,f,r,l,b,u=map(int,input().split())
dice2=Dice(t,f,r,l,b,u)
s='SSSEWW'
w='YYY'
ans='No'
for j in s:
    for r in w:
        if dice1.a==dice2.a:
            ans='Yes'
            break
        dice2.roll(r)
    else:
        dice2.roll(j)
        continue
    break
print(ans)

Submission status: Runtime Error

Solution code:

class Dice:
	
	def __init__(self, faces):
		self.t = faces[0]
		self.s = faces[1]
		self.e = faces[2]
		self.w = faces[3]
		self.n = faces[4]
		self.b = faces[5]

	def roll(self, drct):
		t_ = self.t
		s_ = self.s
		e_ = self.e
		w_ = self.w
		n_ = self.n
		b_ = self.b
		if drct == 'S':
			self.t = 	def set_top(self, face):
		if self.t == face:
			return
		elif self.s == face:
			self.roll('N')
		elif self.e == face:
			self.roll('W')
		elif self.w == face:
			self.roll('E')
		elif self.n == face:
			self.roll('S')
		else
			self.roll('N')
			self.roll('N')_
			self.s = t_
			self.n = b_
			self.b = s_
		elif drct == 'N':
			self.t = s_
			self.s = b_
			self.n = t_
			self.b = n_
		elif drct == 'E':
			self.t = w_
			self.e = t_
			self.w = b_
			self.b = e_
		elif drct == 'W':
			self.t = e_
			self.e = b_
			self.w = t_
			self.b = w_
		else:
			return
	
	def set_top(self, face):
		if self.t == face:
			return
		elif self.s == face:
			self.roll('N')
		elif self.e == face:
			self.roll('W')
		elif self.w == face:
			self.roll('E')
		elif self.n == face:
			self.roll('S')
		else:
			self.roll('N')
			self.roll('N')
			
	def get_right_face(self, f):
		if self.s == f:
			return self.e
		elif self.e == f:
			return self.n
		elif self.w == f:
			return self.s
		else:
			return self.w
	
faces = list(map(int, input().split()))
dice = Dice(faces)

n = int(input())
for i in range(n):
	t, f = map(int, input().split())
	dice.set_top(t)
	print(dice.get_right_face(f))