Problem:
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 (Python):
from enum import IntEnum

class Face(IntEnum):
    One=1
    Two=2
    Three=3
    Four=4
    Five=5
    Six=6


class Dice:
    def __init__(self):
        self.top=Face.One
        self.bottom=Face.Six
        self.back=Face.Two
        self.front=Face.Five
        self.left=Face.Four
        self.right=Face.Three
    
    def roll(self,command):
        if command=="E":
            
            temp=self.top
            self.top=self.left
            self.left=self.bottom
            self.bottom=self.right
            self.right=temp
            
        elif command=="N":
            
            temp=self.top
            self.top=self.back
            self.back=self.bottom
            self.bottom=self.front
            self.front=temp
            
        elif command=="S":
            
            temp=self.top
            self.top=self.front
            self.front=self.bottom
            self.bottom=self.back
            self.back=temp
            
        elif command=="W":
            
            temp=self.top
            self.top=self.right
            self.right=self.bottom
            self.bottom=self.left
            self.left=temp
      
def num_pattern_match(num_list,pattern):
    for i,x in enumerate(num_list):
        is_match=True
        for j,y in enumerate(pattern):
            if num_list[(i+j) % len(num_list)] == pattern[j]:
                pass
            else:
                is_match=False
        if is_match:
            return True
            
    return False      

def build_dice(top,back):
    
    dice=Dice()
    dice.top=top
    dice.back=back
    
    dice.bottom=Face(7-int(dice.top))
    dice.front=Face(7-int(dice.back))

    
    
    exist_dice_list=[int(dice.top),
    int(dice.bottom),
    int(dice.front),
    int(dice.back)]
    
    left_face_num=set([i+1 for i in range(6)]) - set(exist_dice_list)
    
    
    
    face_list=[int(dice.top),int(dice.front),int(dice.bottom),int(dice.back)]

    
    if 1 in left_face_num:
        
        pattern=[2,3,5,4]
        if num_pattern_match(face_list,pattern):
            
            
            dice.right=Face.Six
            dice.left=Face.One
        else:
            dice.right=Face.One
            dice.left=Face.Six
            
    elif 2 in left_face_num:
        pattern=[1,4,6,3]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Five
            dice.left=Face.Two
        else:
            dice.right=Face.Two
            dice.left=Face.Five
            
    elif 3 in left_face_num:
        pattern=[2,6,5,1]
        if num_pattern_match(face_list,pattern):
            dice.right=Face.Four
            dice.left=Face.Three
        else:
            dice.right=Face.Three
            dice.left=Face.Four           
        
    return dice

def run():
    dice_score_ls=list(map(int,input().split()))
    
    dice_score_dict={i+1:score for i,score in enumerate(dice_score_ls)}
    d_inv={v:k for k,v in dice_score_dict.items()}
    
    query_num=int(input())

    for i in range(query_num):
        top,back=tuple(map(int,input().split()))
        top=d_inv[top]
        back=d_inv[back]
        
        dice=build_dice(top,back)
        
        
        print(dice_score_dict[int(dice.right)])
        


run()

Solution (Python):
class Dice:
    def __init__(self, numbers):
        self.dice = {"上" :numbers[0],
                     "下":numbers[5], 
                     "前":numbers[1],
                     "後":numbers[4],
                     "左":numbers[3],
                     "右":numbers[2]
                    }
    
    def order(self, order_seq):
        for _, order in enumerate(order_seq):
            if order == "N":
                self.north()
            elif order == "E":
                self.east()
            elif order == "W":
                self.west()
            elif order == "S":
                self.south()
        
        return self.dice["上"]

    def north(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = F
        self.dice["前"] = D
        self.dice["下"] = B
        self.dice["後"] = U

    def east(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = L
        self.dice["下"] = R
        self.dice["左"] = D
        self.dice["右"] = U

    def west(self):
        U, D, L, R = [self.dice["上"], self.dice["下"], self.dice["左"], self.dice["右"]]
        self.dice["上"] = R
        self.dice["下"] = L
        self.dice["左"] = U
        self.dice["右"] = D

    def south(self):
        U, D, F, B = [self.dice["上"], self.dice["下"], self.dice["前"], self.dice["後"]]
        self.dice["上"] = B
        self.dice["前"] = U
        self.dice["下"] = F
        self.dice["後"] = D   

    def set_position(self, n, position_seq):
        self.ans = []
        for i in range(n):
            self.up = position_seq[i][0]
            self.front = position_seq[i][1]
            
            self.search()
            self.west()
            self.search()
            self.west()
            self.search()
            self.north()
            self.search()
            self.west()
            self.search()
            self.west()
            self.search()
        
        return self.ans
    
    def search(self):
        
        if self.dice["上"] == self.up:
            for _ in range(4):
                
                if self.dice["前"] == self.front:
                    break
                self.rotate()
            self.ans.append(self.dice["右"])

    def rotate(self):
        F, R, B, L = [self.dice["前"], self.dice["右"], self.dice["後"], self.dice["左"]]
        self.dice["前"] = R
        self.dice["右"] = B
        self.dice["後"] = L
        self.dice["左"] = F
        
numbers = list(map(int, input().split()))
n = int(input())
pos_seq = []
for _ in range(n):
    pos_seq.append(list(map(int, input().split())))

dice = Dice(numbers)
ans = dice.set_position(n, position_seq = pos_seq)
for i in range(n):
    print(ans[i])

Solution (Python):
ls = list(map(int,input().split()))
q = int(input())
a = [[ls[1],ls[2]],[ls[2],ls[4]],[ls[4],ls[3]],[ls[3],ls[1]]]
b = [[ls[5],ls[2]],[ls[3],ls[5]],[ls[0],ls[3]],[ls[2],ls[0]]]
c = [[ls[5],ls[4]],[ls[1],ls[5]],[ls[0],ls[1]],[ls[4],ls[0]]]
d = [[ls[5],ls[1]],[ls[4],ls[5]],[ls[0],ls[4]],[ls[1],ls[0]]]
e = [[ls[2],ls[5]],[ls[0],ls[2]],[ls[3],ls[0]],[ls[5],ls[3]]]
f = [[ls[2],ls[1]],[ls[4],ls[2]],[ls[3],ls[4]],[ls[1],ls[3]]]
for i in range(q):
    K = list(map(int,input().split()))
    if K in  a:
        print(ls[0])
    elif K in b:
        print(ls[1])
    elif K in c:
        print(ls[2])
    elif K in d:
        print(ls[3])
    elif K in e:
        print(ls[4])
    elif K in f:
        print(ls[5])

Solution (Python):
num = list(map(int, input().split()))
class Dice:
    def __init__(self, num):
        self.state = {}
        for i in range(1,6+1):
            self.state[i] = num[i-1]

        self.reversed_state = {}
        for key,val in zip(self.state.keys(), self.state.values()):
            self.reversed_state[val] = key
        
    def search_side(self, x,y):
        a = self.reversed_state[x]
        b = self.reversed_state[y]
        if str(a)+str(b) in '12651':
            side = self.state[3]
        elif str(b)+str(a) in '12651':
            side = self.state[4]
        elif str(a)+str(b) in '13641':
            side = self.state[5]
        elif str(b)+str(a) in '13641':
            side = self.state[2]
        elif str(a)+str(b) in '23542':
            side = self.state[1]
        elif str(b)+str(a) in '23542':
            side = self.state[6]
        return side
        
dice = Dice(num)
q = int(input())
for _ in range(q):
    x,y = map(int, input().split())
    ans = dice.search_side(x,y)
    print(ans)

Solution (Python):
a = [int(i) for i in input().split()]
n = int(input())

class Dise:
    def __init__(self,a):
        self.dise = [0 for i in range(len(a))]
        for i in range(len(a)):
            self.dise[i] = a[i]

    def roll(self,dir):
        for self.pop_str in dir:
            if self.pop_str == "N":
                self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[1],self.dise[5],self.dise[0],self.dise[4]
            elif self.pop_str == "S":
                self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[4],self.dise[0],self.dise[5],self.dise[1]
            elif self.pop_str == "E":
                self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[3],self.dise[0],self.dise[5],self.dise[2]
            elif self.pop_str == "W":
                self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[2],self.dise[5],self.dise[0],self.dise[3]

    def N(self):
        self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[1],self.dise[5],self.dise[0],self.dise[4]

    def S(self):
        self.dise[0],self.dise[1],self.dise[4],self.dise[5] = self.dise[4],self.dise[0],self.dise[5],self.dise[1]

    def E(self):
        self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[3],self.dise[0],self.dise[5],self.dise[2]

    def W(self):
        self.dise[0],self.dise[2],self.dise[3],self.dise[5] = self.dise[2],self.dise[5],self.dise[0],self.dise[3]

    def R(self):
        self.dise[1],self.dise[2],self.dise[3],self.dise[4] = self.dise[3],self.dise[1],self.dise[4],self.dise[2]

    def L(self):
        self.dise[1],self.dise[2],self.dise[3],self.dise[4] = self.dise[2],self.dise[4],self.dise[1],self.dise[3]

    
    def output(self):
        print(self.dise[2])


for i in range(n):
    X = Dise(a)
    count = 0
    top,front = [int(i) for i in input().split()]

    while X.dise[0] != top and X.dise[1] != front:
        X.N()
        count += 1
        if count >= 4:
            X.E()
            count += 1
            if count >= 8:
                X.R()

    if X.dise[0] == top:
        while X.dise[1] != front:
            X.R()
    elif X.dise[1] == front:
        while X.dise[0] != top:
            X.E()
    X.output()

Solution (Python):
class Dice(object):
    def __init__(self, nums):
        from collections import deque
        self.ns = deque([nums[4], nums[0], nums[1]])
        self.we = deque([nums[3], nums[0], nums[2]])
        self.bk = deque([nums[5]])

    def __str__(self):
        return str({"ns": self.ns, "we": self.we, "bk": self.bk})

    def operation(self, o):
        if o == "N":
            self.n()
        elif o == "S":
            self.s()
        elif o == "W":
            self.w()
        elif o == "E":
            self.e()
        else:
            raise BaseException("invalid", o)

    def n(self):
        self.ns.append(self.bk.popleft())
        self.bk.append(self.ns.popleft())
        self.we[1] = self.ns[1]

    def s(self):
        self.ns.appendleft(self.bk.pop())
        self.bk.appendleft(self.ns.pop())
        self.we[1] = self.ns[1]

    def w(self):
        self.we.append(self.bk.popleft())
        self.bk.append(self.we.popleft())
        self.ns[1] = self.we[1]

    def e(self):
        self.we.appendleft(self.bk.pop())
        self.bk.appendleft(self.we.pop())
        self.ns[1] = self.we[1]

    def rotate_right(self):
        tmp = self.ns
        tmp.reverse()
        self.ns = self.we
        self.we = tmp

    def fit_top_s(self, top, s):
        while self.get_top() != top:
            if top in self.ns:
                self.n()
            elif top in self.we:
                self.w()
            else:
                self.n()
                self.n()
        while self.get_s() != s:
            self.rotate_right()

    def get_top(self):
        return self.ns[1]

    def get_s(self):
        return self.ns[2]

    def get_e(self):
        return self.we[2]


def resolve():
    nums = [int(i) for i in input().split()]
    dc = Dice(nums)
    q = int(input())
    for _ in range(q):
        top, s = [int(i) for i in input().split()]
        dc.fit_top_s(top, s)
        print(dc.get_e())


resolve()

Solution (Python):
class Dice:
    def __init__(self, top, front, right, left, rear, bottom):
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.rear = rear
        self.bottom = bottom
    def print(self):
        '''print top of dice'''
        print(self.top)
    def north(self):
        self.top, self.front, self.bottom, self.rear = \
            self.front, self.bottom, self.rear, self.top
    def south(self):
        self.top, self.front, self.bottom, self.rear = \
            self.rear, self.top, self.front, self.bottom
    def east(self):
        self.top, self.right, self.bottom, self.left = \
            self.left, self.top, self.right, self.bottom
    def west(self):
        self.top, self.right, self.bottom, self.left = \
            self.right, self.bottom, self.left, self.top
    def find_right(self, top, front):
        if top == self.top:
            pass
        elif top == self.front:
            self.north()
        elif top == self.rear:
            self.south()
        elif top == self.right:
            self.west()
        elif top == self.left:
            self.east()
        elif top == self.bottom:
            self.north()
            self.north()
        else:
            return -1
        if front == self.front:
            return self.right
        elif front == self.right:
            return self.rear
        elif front == self.rear:
            return self.left
        elif front == self.left:
            return self.front
        else:
            return -1

d = list(map(int, input().split()))
dice = Dice(d[0], d[1], d[2], d[3], d[4], d[5])
q = int(input())

for i in range(q):
    top, front = map(int, input().split())
    right = dice.find_right(top, front)
    print(right)

Solution (Python):
class Dice():
    directions = "EEENEEENEEESEEESEEENEEEN"

    def __init__(self, lst):
        self.top = lst[0]
        self.front = lst[1]
        self.right = lst[2]
        self.left = lst[3]
        self.back = lst[4]
        self.bottom = lst[5]

    def rotate(self, direction):
        if direction == "E":
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        if direction == "N":
            self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        if direction == "S":
            self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom
        if direction == "W":
            self.top, self.left, self.bottom, self.right = self.right, self.top, self.left, self.bottom

    def fit_top_front(self, num_top, num_front):
        for direction in Dice.directions:
            if self.top == num_top and self.front == num_front:
                break
            self.rotate(direction)


def main():
    dice_nums = list(map(int, input().split()))
    dice = Dice(dice_nums)

    num_questions = int(input())

    for _ in range(num_questions):
        nums = list(map(int, input().split()))
        dice.fit_top_front(nums[0], nums[1])
        print(dice.right)


if __name__ == "__main__":
    main()

Solution (Python):
dice=input().split()
q=int(input())

do = [(2,3,5,4), (6,3,1,4), (2,6,5,1), (2,1,5,6), (1,3,6,4), (2,4,5,3)]

def check(top, front):
    top_index=dice.index(top)
    front_index=dice.index(front)+1
    tmp=do[top_index]
    tmp_index=tmp.index(front_index)
   
    i = 0
    if tmp_index == 3:
        i = tmp[0]
    else:
        i = tmp[tmp_index+1]
    print(dice[i-1])


for i in range(q):
    top,front=input().split()
    check(top,front)

Solution (Python):
class Dice:
    
    def __init__(self, nums):
        self.nums = list(nums)
        
    @property
    def top(self):
        return self.nums[0]
        
    def _shift(self, *pairs):
        for pair in pairs:
            num = self.nums[pair[0]]
            self.nums[pair[0]] = self.nums[pair[1]]
            self.nums[pair[1]] = num
            
    def go(self, opes:str):
        for ope in opes:
            if ope == "N":
                self.go_north()
            elif ope == "E":
                self.go_east()
            elif ope == "W":
                self.go_west()
            else:
                self.go_south()
                
    def go_top(self, num):
        i = self.nums.index(num)
        
        if i == 1:
            self.go_north()
        elif i == 2:
            self.go_west()
        elif i == 3:
            self.go_east()
        elif i == 4:
            self.go_south()
        elif i == 5:
            self.go_north()
            self.go_north()
            
    def go_ahead(self, num):
        i = self.nums.index(num)
        
        if i == 2:
            self.go_cw()
        elif i == 4:
            self.go_cw()
            self.go_cw()
        elif i == 3:
            self.go_ccw()
            
        
    def go_north(self):
        self._shift((0, 1), (1, 5), (5, 4))
        
    def go_east(self):
        self._shift((0, 3), (3, 5), (5, 2))
        
    def go_west(self):
        self._shift((0, 2), (2, 5), (5, 3))
        
    def go_south(self):
        self._shift((0, 4), (4, 5), (5, 1))
        
    def go_ccw(self):
        self._shift((3, 4), (4, 2), (2, 1))
        
    def go_cw(self):
        self._shift((3, 1), (1, 2), (2, 4))
        

dice = Dice(map(int, input().split()))

for _ in range(int(input())):
    top, ahead = map(int, input().split())
    dice.go_top(top)
    dice.go_ahead(ahead)
    print(dice.nums[2])

Solution (Python):
class Dice():
    def __init__(self):
        self.nums = list(range(6))
        self.work = list(range(6))

    def set_nums(self, n0, n1, n2, n3, n4, n5):
        self.nums[0] = n0
        self.nums[1] = n1
        self.nums[2] = n2
        self.nums[3] = n3
        self.nums[4] = n4
        self.nums[5] = n5

    def rotate(self, cmd):
        for i in range(6):
            
            self.work[i] = self.nums[i]

        if cmd == 'N':
            self.set_nums(self.work[1], self.work[5], self.work[2], self.work[3], self.work[0], self.work[4])
        elif cmd == 'S':
            self.set_nums(self.work[4], self.work[0], self.work[2], self.work[3], self.work[5], self.work[1]),
        elif cmd == 'E':
            self.set_nums(self.work[3], self.work[1], self.work[0], self.work[5], self.work[4], self.work[2])
        else:
            self.set_nums(self.work[2], self.work[1], self.work[5], self.work[0], self.work[4], self.work[3])

    def top(self):
        return self.nums[0]

    def right(self, top, front):
        
        if top == 1:
            return [3,5,2,4][front-2]
        elif top == 6:
            return [4,2,5,3][front-2]
        elif top == 2:
            
            return [4,0,1,6,0,3][front-1]
        elif top == 5:
            
            return [3,0,6,1,0,4][front-1]
        elif top == 3:
            
            return [2,6,0,0,1,5][front-1]
        elif top == 4:
            
            return [5,1,0,0,6,2][front-1]
        else:
            pass

nums = [int(arg) for arg in input().split()]
d = Dice()
d.set_nums(*nums)
for _ in range(int(input())):
    top, front = [int(arg) for arg in input().split()]
    right_id = d.right(nums.index(top)+1, nums.index(front)+1)
    print(nums[right_id-1])

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

	def throw(self, direction):
		
		if direction == 'N':
			self.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t
		elif direction == 'S':
			self.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b
		elif direction == 'W':
			self.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t
		elif direction == 'E':
			self.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b


arrinput = list(map(int, input().split()))
dirinput = 'WWWWSWWWWSWWWWSWWWWWSWWWWSSWWWW'
dicresult = []

dice = diceClass(arrinput)
for s in dirinput:
	dice.throw(s)
	if dicresult.count([[dice.t, dice.s], dice.e]) == 0:
		dicresult.append([[dice.t, dice.s], dice.e])

q = int(input())
for i in range(0, q):
	a, b = map(int, input().split())
	for j in dicresult:
		if a == j[0][0] and b == j[0][1]:
			print(j[1])

Solution (Python):
class Dice:
    def __init__(self,d1,d2,d3,d4,d5,d6):
        self.dice = [d1,d2,d3,d4,d5,d6]
    def turn(self,dir):
        if dir == 'S':
            self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
        if dir == 'N':
            self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
        if dir == 'W':
            self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
        if dir == 'E':
            self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]


def check(m):
    for b in range(4):
        m.turn('N')
        if m.dice[0] == a[0] and m.dice[1] == a[1]:
            return(m.dice[2])

dice_num = input().split()
q = int(input())
conditions = []
for a in range(q):
    temp = input().split()
    conditions.append(temp)

init_Dice = Dice(dice_num[0],dice_num[1],dice_num[2],dice_num[3],dice_num[4],dice_num[5])

kaitou = []
for a in conditions:
    if check(init_Dice):
        print(check(init_Dice))
        continue
    init_Dice.turn('E')
    if check(init_Dice):
        print(check(init_Dice))
        continue
    init_Dice.turn('E')
    if check(init_Dice):
        print(check(init_Dice))
        continue
    init_Dice.turn('E')
    if check(init_Dice):
        print(check(init_Dice))
        continue

    init_Dice.turn('W')
    init_Dice.turn('N')
    init_Dice.turn('E')

    if check(init_Dice):
        print(check(init_Dice))
        continue
    init_Dice.turn('E')
    if check(init_Dice):
        print(check(init_Dice))
        continue
    init_Dice.turn('E')
    if check(init_Dice):
        print(check(init_Dice))
        continue
    init_Dice.turn('E')
    if check(init_Dice):
        print(check(init_Dice))
        continue

Solution (Python):
class Dice:
  __table =[[0,1,2,3,4,5],[0,2,4,1,4,5],[0,4,3,2,1,5],[0,3,1,4,2,5],
            [1,5,2,3,0,4],[1,2,0,5,3,4],[1,0,3,2,5,4],[1,3,5,0,2,4],
            [2,5,4,1,0,3],[2,4,0,5,1,3],[2,0,1,4,5,3],[2,1,5,0,4,3],
            [3,5,1,4,0,2],[3,1,0,5,4,2],[3,0,4,1,5,2],[3,4,5,0,1,2],
            [4,2,5,0,3,1],[4,5,3,2,0,1],[4,3,0,5,2,1],[4,0,2,3,5,1],
            [5,1,3,2,4,0],[5,3,4,1,2,0],[5,4,2,3,1,0],[5,2,1,4,3,0]]
  __another = []
  def __init__(self,dice):
    self.dice = dice
    for t in self.__table:
      a = []
      for k,v in enumerate(t):
        a.append(dice[v])      
      self.__another.append(a)
      
  def output(self):
    print(self.dice[0])
    
  def right_dise(self,a,b):
    for t in self.__another:
      if t[0] == a and t[1] == b:
        return t[2]

  def move(self,str):
    if str == 'N':
      temp = self.dice[0]
      self.dice[0] = self.dice[1]
      self.dice[1] = self.dice[5]
      self.dice[5] = self.dice[4]
      self.dice[4] = temp
    elif str == 'S':
      temp = self.dice[0]
      self.dice[0] = self.dice[4]
      self.dice[4] = self.dice[5]
      self.dice[5] = self.dice[1]
      self.dice[1] = temp

    elif str == 'E':
      temp = self.dice[0]
      self.dice[0] = self.dice[3]
      self.dice[3] = self.dice[5]
      self.dice[5] = self.dice[2]
      self.dice[2] = temp
      
    elif str == 'W':
      temp = self.dice[0]
      self.dice[0] = self.dice[2]
      self.dice[2] = self.dice[5]
      self.dice[5] = self.dice[3]
      self.dice[3] = temp      
  
      
di = list(map(int,input().split()))
di = Dice(di)
num = int(input())

while num > 0:
  v1,v2 = map(int,input().split())
  re = di.right_dise(v1,v2)
  print(re)
  num -= 1

Solution (Python):
class Dice:
    def __init__(self,label):
        self.W = label[3]
        self.S = label[1]
        self.E = label[2]
        self.N = label[4]
        self.u = label[0]
        self.l = label[5]
    def rotate(self,direction):
        if direction =='S':
            dummy = self.S
            self.S = self.u
            self.u = self.N
            self.N = self.l
            self.l = dummy
        elif direction == 'N':
            dummy = self.S
            self.S = self.l
            self.l = self.N
            self.N = self.u
            self.u = dummy
        elif direction == 'W':
            dummy = self.W
            self.W = self.u
            self.u = self.E
            self.E = self.l
            self.l = dummy
        else:
            dummy = self.W
            self.W = self.l
            self.l = self.E
            self.E = self.u
            self.u = dummy
    def rot(self):
            dummy = self.W
            self.W = self.S
            self.S = self.E
            self.E = self.N
            self.N = dummy

l = input().split()
D = Dice(l)
n = int(input())
for i in range(n):
    a,b = input().split()
    if a == D.u:
        c = 1
    elif a == D.N:
        D.rotate('S')
    elif a == D.W:
        D.rotate('E')
    elif a == D.E:
        D.rotate('W')
    elif a == D.S:
        D.rotate('N')
    else:
        D.rotate('S')
        D.rotate('S')
    for i in range(4):
        D.rot()
        if (D.S == b)+(D.S == str(b)):
            break
    print(D.E)
    D = Dice(l)

Solution (Python):
import math
import itertools
import sys

class Dice:
  numbers = []
  faces = {
    'top': None,
    'back': None,    
    'right': None,    
    'left': None,    
    'front': None,    
    'bottom': None,
  }

  def __init__(self, int_array):
    self.numbers = int_array
    self.faces['top'] = self.numbers[0]
    self.faces['back'] = self.numbers[1]
    self.faces['right'] = self.numbers[2]
    self.faces['left'] = self.numbers[3]
    self.faces['front'] = self.numbers[4]
    self.faces['bottom'] = self.numbers[5]

  def getNum(self, n):
    return self.numbers[n-1]

  def getFace(self, f):
    return self.faces[f]

  def getRightFace(self, t, b):
    top = self.faces['top']
    back = self.faces['back']
    right = self.faces['right']
    left = self.faces['left']
    front = self.faces['front']
    bottom = self.faces['bottom']

    if t == self.getNum(2):
      self.rotate('N')

    elif t == self.getNum(4):
      self.rotate('E')

    elif t == self.getNum(5):
      self.rotate('S')

    elif t == self.getNum(3):
      self.rotate('W')

    elif t == self.getNum(6):
      for _ in range(2):
        self.rotate('N')

    while self.getFace('back') != b:
      self.rotate('R')

    result = self.getFace('right')
      
    self.faces['top'] = top
    self.faces['back'] = back
    self.faces['right'] = right
    self.faces['left'] = left
    self.faces['front'] = front
    self.faces['bottom'] = bottom

    return result

  def rotate(self, direction):
    if direction == 'N': 
      top = self.getFace('top') 

      self.faces['top'] = self.faces['back']
      self.faces['back'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['front']
      self.faces['front'] = top
      
    elif direction == 'E': 
      top = self.faces['top'] 

      self.faces['top'] = self.faces['left']
      self.faces['left'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['right']
      self.faces['right'] = top
      
    elif direction == 'S': 
      top = self.faces['top'] 

      self.faces['top'] = self.faces['front']
      self.faces['front'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['back']
      self.faces['back'] = top
      
    elif direction == 'W': 
      top = self.faces['top'] 

      self.faces['top'] = self.faces['right']
      self.faces['right'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['left']
      self.faces['left'] = top
      
    elif direction == 'R': 
      back = self.faces['back'] 

      self.faces['back'] = self.faces['left']
      self.faces['left'] = self.faces['front']
      self.faces['front'] = self.faces['right']
      self.faces['right'] = back
      
    else: 
      back = self.faces['back'] 

      self.faces['back'] = self.faces['right']
      self.faces['right'] = self.faces['front']
      self.faces['front'] = self.faces['left']
      self.faces['left'] = back
      
def main():
  number = list(map(int, input().split()))
  q = int(input())

  dice = Dice(number)

  for _ in range(q):
    t, b = map(int, input().split())
    print(dice.getRightFace(t,b))

if __name__ == '__main__':
  main()

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

Solution (Python):
S = [
    (1, 2, 4, 3), 
    (0, 3, 5, 2), 
    (0, 1, 5, 4), 
    (0, 4, 5, 1), 
    (0, 2, 5, 3), 
    (1, 3, 4, 2), 
]

*L, = map(int, input().split())
q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    for i in range(6):
        if L[i] == a:
            for k in range(4):
                if L[S[i][k]] == b:
                    print(L[S[i][k-3]])

Solution (Python):
d = input().split()
n = int(input())
r_list = []
i = 0

while n > i:
    t, f = map(str, input().split())
    tf = str(d.index(t)) + str(d.index(f))

    if tf == "12" or tf == "24" or tf == "43" or tf == "31":
        r_list.append(1)
    elif tf == "20" or tf == "03" or tf == "35" or tf == "52":
        r_list.append(2)
    elif tf == "01" or tf == "15" or tf == "54" or tf == "40":
        r_list.append(3)
    elif tf == "10" or tf == "51" or tf == "45" or tf == "04":
        r_list.append(4)
    elif tf == "02" or tf == "30" or tf == "53" or tf == "25":
        r_list.append(5)
    elif tf == "21" or tf == "42" or tf == "34" or tf == "13":
        r_list.append(6)

    i += 1

for r in r_list:
    print(d[r-1])

Solution (Python):
dice = list(map(int,input().split()))

def move(x):
    if x == "N":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[1],d[5],d[2],d[3],d[0],d[4]

    elif x == "W":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[2],d[1],d[5],d[0],d[4],d[3]

    elif x == "E":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[3],d[1],d[0],d[5],d[4],d[2]

    elif x == "S":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[4],d[0],d[2],d[3],d[5],d[1]

q = int(input())

for i in range(q):
    a,b = map(int,input().split())
    d = dice

    if a == dice[1]:
        move("N")
    if a == dice[2]:
        move("W")
    if a == dice[3]:
        move("E")
    if a == dice[4]:
        move("N")
    if a == dice[5]:
        move("S")
        move("S")

    if b == d[1]:
        print(d[2])
    if b ==  d[2]:
        print(d[4])
    if b ==  d[3]:
        print(d[1])
    if b ==  d[4]:
        print(d[3])