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: Wrong Answer

Solution code:
# coding: utf-8
# ?????????????????¨????????????
class Dice(object):
	def __init__(self):
		# ????????¶???
		self.dice = (2, 5), (3, 4), (1, 6) # x, y, z
		self.ax = [[0, False], [1, False], [2, False]]
		self.axmap = [0, 1, 2]
		self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (1, 0)}

	def rotate(self, dir):
		def rot(k, r):
			t = self.axmap[r]
			self.axmap[k], self.axmap[r] = t, self.axmap[k]
			self.ax[t][1] = not self.ax[t][1]

		rot(*self.mm[dir])

	def front(self): return self.value(0, True)
	def rear(self): return self.value(0, False)
	def right(self): return self.value(1, True)
	def right(self): return self.value(1, False)
	def top(self): return self.value(2, True)
	def bottom(self): return self.value(2, False)
	def value(self, ax, d):
		a = self.ax[self.axmap[ax]]
		return self.dice[a[0]][a[1] if d else not a[1]]

if __name__=="__main__":
	dice = Dice()
	labels = input().split()
	q = int(input())
	def tf(p, f, d):
		for _ in range(4):
			if p==f(): break
			dice.rotate(d)

	for _ in range(q):
		a, b = input().split()
		p = labels.index(a) + 1
		f = dice.top
		tf(p, f, "N")
		tf(p, f, "E")
		
		p = labels.index(b) + 1
		f = dice.front
		tf(p, f, "R")

		print(labels[dice.right()-1])

Submission status: Wrong Answer

Solution code:
def whatIsRight(u,f):	
    r = 0
    if u == 1:
        if f == 2:
            r = 3
        elif f == 3:
            r = 5
        elif f == 4:
            r = 2
        elif f == 5:
            r = 4
    
    if u == 2:
        if f == 6:
            r = 3
        elif f == 3:
            r = 1
        elif f == 1:
            r = 4
        elif f == 4:
            r = 6
	
    if u == 3:
        if f == 5:
            r = 1
        elif f == 1:
            r = 2
        elif f == 2:
            r = 6
        elif f == 6:
            r = 3
		
    if u == 4:
        if f == 6:
            r = 2
        elif f == 2:
            r = 1
        elif f == 1:
            r = 5
        elif f == 5:
            r = 6
			
    if u == 5:
        if f == 3:
            r = 6
        elif f == 6:
            r = 4
        elif f == 4:
            r = 1
        elif f == 1:
            r = 3
			
    if u == 6:
        if f == 5:
            r = 3
        elif f == 3:
            r = 2
        elif f == 2:
            r = 4
        elif f == 4:
            r = 5
    return r
			
n = list(map(int,input().split()))
N = int(input())
for i in range(N):
    m = list(map(int,input().split()))
    print(n[whatIsRight(m[0],m[1]) -1])

Submission status: Wrong Answer

Solution code:
def whatIsRight(u,f):	
    r = 0
    if u == 1:
        if f == 2:
            r = 3
        elif f == 3:
            r = 5
        elif f == 4:
            r = 2
        elif f == 5:
            r = 4
	
    elif u == 2:
        if f == 6:
            r = 3
        elif f == 3:
            r = 1
        elif f == 1:
            r = 4
        elif f == 4:
            r = 6

    elif u == 3:
        if f == 5:
            r = 1
        elif f == 1:
            r = 2
        elif f == 2:
            r = 6
        elif f == 6:
            r = 3
			
    elif u == 4:
        if f == 6:
            r = 2
        elif f == 2:
            r = 1
        elif f == 1:
            r = 5
        elif f == 5:
            r = 6 
			
    elif u == 5:
        if f == 3:
            r = 6
        elif f == 6:
            r = 4
        elif f == 4:
            r = 1
        elif f == 1:
            r = 3
		
    elif u == 6:
        if f == 5:
            r = 3
        elif f == 3:
            r = 2
        elif f == 2:
            r = 4
        elif f == 4:
            r = 5
    return r
			
n = list(map(int,input().split()))
N = int(input())

for i in range(N):
    m = list(map(int,input().split()))
    num = []

    for j in range(len(m)):
        for k in range(len(n)):
            if m[j] == n[k]:
                num.append(k+1)
                break
	
    print(n[whatIsRight(num[0],num[1]) -1])

Submission status: Wrong Answer

Solution code:
dice = map(int, raw_input().split())
n = int(raw_input())
temp = [0 for i in range(2)]

for i in range(n):
    hint = map(int, raw_input().split())
    
    for j in range(len(dice)):
        if hint[0] == dice[j]:
            temp[0] = j
        elif hint[1] == dice[j]:
            temp[1] = j
    
    if (temp[0] == 1 and temp[1] == 2) or (temp[0] == 2 and temp[1] == 4) or (temp[0] == 4 and temp[1] == 3) or (temp[0] == 3 and temp[1] == 1):
        print 1
    elif (temp[0] == 0 and temp[1] == 3) or (temp[0] == 3 and temp[1] == 5) or (temp[0] == 5 and temp[1] == 2) or (temp[0] == 2 and temp[1] == 0):
        print 2
    elif (temp[0] == 0 and temp[1] == 1) or (temp[0] == 1 and temp[1] == 5) or (temp[0] == 5 and temp[1] == 4) or (temp[0] == 4 and temp[1] == 0):
        print 3
    elif (temp[0] == 0 and temp[1] == 4) or (temp[0] == 4 and temp[1] == 5) or (temp[0] == 5 and temp[1] == 1) or (temp[0] == 1 and temp[1] == 0):
        print 4
    elif (temp[0] == 0 and temp[1] == 2) or (temp[0] == 2 and temp[1] == 5) or (temp[0] == 5 and temp[1] == 3) or (temp[0] == 3 and temp[1] == 0):
        print 5
    else:
        print 6

Submission status: Wrong Answer

Solution code:
class Dice(object):
    """Dice Class

    """

    def __init__(self, numbers):
        """

        Args:
            numbers:
        """
        self.numbers_inverse = {numbers[0]: 1, numbers[1]: 2, numbers[2]: 3, numbers[3]: 4, numbers[4]: 5,
                                numbers[5]: 6}
        self.numbers = {1: numbers[0], 2: numbers[1], 3: numbers[2], 4: numbers[3], 5: numbers[4], 6: numbers[5]}

        self.vertical = [self.numbers[1], self.numbers[2], self.numbers[6], self.numbers[5]]
        self.horizontal = [self.numbers[4], self.numbers[1], self.numbers[3], self.numbers[6]]

    def move_dice(self, s):
        """

        Args:
            s: move direction

        Returns:

        """
        if s == 'N':
            self.move_north()
        elif s == 'S':
            self.move_south()
        elif s == 'W':
            self.move_west()
        elif s == 'E':
            self.move_east()

    def move_south(self):
        """move this dice towered north
        """
        self.vertical = (self.vertical * 2)[3:7]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]

    def move_north(self):
        """move this dice towered south
        """
        self.vertical = (self.vertical * 2)[1:5]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]

    def move_east(self):
        """move this dice towered east
        """
        self.horizontal = (self.horizontal * 2)[3:7]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]

    def move_west(self):
        """move this dice towered west
        """
        self.horizontal = (self.horizontal * 2)[1:5]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]

    def get_top(self):
        return self.vertical[0]


dice = Dice([int(x) for x in raw_input().split()])
number_of_questions = int(raw_input())
counter = 0
while counter < number_of_questions:
    [top, front] = [int(x) for x in raw_input().split()]
    decision_list = "".join([str(x) for x in [dice.numbers_inverse[top], dice.numbers_inverse[front]]])
    if decision_list in "1265" * 2:
        print(dice.numbers[3])
    elif decision_list in "6521" * 2:
        print(dice.numbers[4])
    elif decision_list in "4235" * 2:
        print(dice.numbers[1])
    elif decision_list in "5324" * 2:
        print(dice.numbers[6])
    elif decision_list in "1364" * 2:
        print(dice.numbers[5])
    elif decision_list in "4531" * 2:
        print(dice.numbers[2])
    counter += 1

Submission status: Wrong Answer

Solution code:
label = input().split()

right = {
           "12651":3,
           "15621":4,
           "13641":5,
           "14631":2,
           "23542":1,
           "24532":6,
           }

q = int(input())
for i in range(q):
    s = input().split()
    s = ''.join(s)
    for pattern in right:
        if s in pattern:
            print(label[right[pattern]-1])

Submission status: Wrong Answer

Solution code:
pattern = {
           "12651":3,
           "15621":4,
           "13641":5,
           "14631":2,
           "23542":1,
           "24532":6,
          }

label = input().split()
l2d = {label[i]:str(i+1) for i in range(6)}
print(l2d)

qn = int(input())
for i in range(qn):
    top, front = input().split()
    tf = l2d[top]+l2d[front]

    for p in pattern:
        if tf in p:
            print(label[pattern[p]-1])

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        return die.pips[2]


def main():
    die = init_die()
    print(question_rightside(die))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

d = dice(list(map(int,input().split())))
n = int(input())

for i in range(n):
    
    top, front = map(int,input().split())
    
    for op in "EEENEEENEEESEEESEEENEEEN":
        d.move(op)
        if d.pip[0] == top and d.pip[1] == front:
            break
    
    print(d.pip[2])

Submission status: Wrong Answer

Solution code:
inp = [i for i in input().split()]
n = int(input())
array = [[i for i in input().split()] for i in range(n)]
fuck = []
love = []
for i2 in range(n):
    for i in range(1,33):
        if (i<=20 and i%5==0) or i==22 or i==27 or i==28:
            s = "N"
        else:
            s = "E"
        if s == "E":
            a = []
            a.append(inp[3])
            a.append(inp[1])
            a.append(inp[0])
            a.append(inp[5])
            a.append(inp[4])
            a.append(inp[2])
            inp = a
            if inp[0] == array[i2][0] and inp[1] == array[i2][1]:
                fuck.append(inp[2])
        elif s == "N":
            a = []
            a.append(inp[1])
            a.append(inp[5])
            a.append(inp[2])
            a.append(inp[3])
            a.append(inp[0])
            a.append(inp[4])
            inp = a
            if inp[0] == array[i2][0] and inp[1] == array[i2][1]:
                fuck.append(inp[2])
for i in fuck:
    if i not in love:
        love.append(i)
for i in range(len(love)):
    print(love[i])

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self):
        self.front = '1'
        self.back = '6'
        self.top = '5'
        self.bottom = '2'
        self. right = '3'
        self.left = '4'
    def turnRight(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self.top
    def turnLeft(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self.top
    def turnFront(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self.top
    def turnBack(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self.top
 
mydice = Dice()
mydice.top, mydice.front, mydice.right, mydice.left, mydice.back, mydice.bottom = input().split()
 
n = int(input())
for q in range(n):
    top, front = input().split()
 
    for rotate in range(3):
        mydice.turnFront()
        if mydice.top == front:
            break
        mydice.turnRight()
        if mydice.top == front:
            break
    mydice.turnBack()
    while top != mydice.top:
        mydice.turnRight()
    print(mydice.right)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
???????????? I

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""

class Dice:
    T = 0
    S = 1
    E = 2
    W = 3
    N = 4
    B = 5

    """ ????????????????????? """
    def __init__(self): # ?????????????????????
        self.side = [1, 2, 3, 4, 5, 6]
        self.top = 0

    def setDice(self, arr):  # ??¢??????????????????
        self.side = arr[0:6]

    def Turn(self, dir): # ?????????????????¢??????
        s = self.side

        if dir == "N":     # ????????¢??????
            #    Top 0     South 1   East 2    West 3    North 4   Bottom 5
            t = [s[Dice.S],s[Dice.B],s[Dice.E],s[Dice.W],s[Dice.T],s[Dice.N]]
        elif dir == "S": # ????????¢??????
            t = [s[Dice.N],s[Dice.T],s[Dice.E],s[Dice.W],s[Dice.B],s[Dice.S]]
        elif dir == "E": # ??±?????¢??????
            t = [s[Dice.W],s[Dice.S],s[Dice.T],s[Dice.B],s[Dice.N],s[Dice.E]]
        elif dir == "W": # ?\??????¢??????
            t = [s[Dice.E],s[Dice.S],s[Dice.B],s[Dice.T],s[Dice.N],s[Dice.W]]
        elif dir == "L": # ???????????¢
            t = [s[Dice.T],s[Dice.W],s[Dice.S],s[Dice.N],s[Dice.E],s[Dice.B]]
        elif dir == "R": # ???????????¢
            t = [s[Dice.T],s[Dice.E],s[Dice.N],s[Dice.S],s[Dice.W],s[Dice.B]]

        self.side = t
#        print("{0} T0:{1} S1:{2} W2:{3} E3:{4} N4:{5} B5:{6} ".format(dir, self.side[0],self.side[1], self.side[2],self.side[3], self.side[4],self.side[5]))

    def Search(self, tval, sval, dir): # ?????¢??¨?????¢???????????????????????????????????¢???????????????
        for i in range(3): # ?????¢?????????????????????????????§????????¢??????
            if self.side[Dice.T] == tval:
                break
            self.Turn("N")
        
        for i in range(3): # ?????¢?????????????????????????????§????????????
            if self.side[Dice.S] == sval:
                break
            self.Turn("L")
            
        return self.side[dir]

dnum = list(map(int,input().strip().split()))
d = Dice()
d.setDice(dnum)
cnum = int(input().strip())
for c in range(cnum):
    cmd = list(map(int,input().strip().split()))
    val = d.Search(cmd[0], cmd[1], Dice.E)
    print(val)

Submission status: Wrong Answer

Solution code:
class dice2():
    def __init__(self,men1,men2,men3,men4,men5,men6):
        self.men=[men1,men2,men3,men4,men5,men6]
        
    def find_num_rside(self,top,front):
        if [top,front] in [[1,2],[2,6],[6,5],[5,1]]:
            return self.men[3-1]#3
        elif  [top,front] in [[5,6],[6,2],[2,1],[1,5]]:
            return self.men[4-1]#4
        elif [top,front] in [[4,2],[2,3],[3,5],[5,4]]:
            return self.men[1-1]#1
        elif  [top,front] in [[5,3],[3,2],[2,4],[4,5]]:
            return self.men[6-1]#6
        elif  [top,front] in [[1,3],[3,6],[6,4],[4,1]]:
            return self.men[5-1]#5
        elif  [top,front] in [[4,6],[6,3],[3,1],[1,4]]:
            return self.men[2-1]#2
        
mn=list(map(int,input().split()))
q=int(input())

d=dice2(*mn)

for i in range(q):
    top, front=list(map(int,input().split()))
    ans=d.find_num_rside(top, front)
    print(ans)

Submission status: Wrong Answer

Solution code:
class Dice:
    __slots__ = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6']

    def __init__(self, n_tup):

        self.n1 = n_tup[0]
        self.n2 = n_tup[1]
        self.n3 = n_tup[2]
        self.n4 = n_tup[3]
        self.n5 = n_tup[4]
        self.n6 = n_tup[5]

    def roll(self, direction):
        if direction == "N":
            self.n1, self.n2, self.n6, self.n5 \
                = self.n2, self.n6, self.n5, self.n1
        elif direction == "E":
            self.n1, self.n3, self.n6, self.n4 \
                = self.n4, self.n1, self.n3, self.n6
        if direction == "S":
            self.n1, self.n2, self.n6, self.n5 \
                = self.n5, self.n1, self.n2, self.n6
        if direction == "W":
            self.n1, self.n3, self.n6, self.n4 \
                = self.n3, self.n6, self.n4, self.n1

    def right_num(self, top, forward):
        n3_list = [self.n2, self.n6, self.n5, self.n1]
        if top in n3_list and forward in n3_list:
            return self.n3
        n5_list = [self.n1, self.n3, self.n6, self.n4]
        if top in n5_list and forward in n5_list:
            return self.n5
        n6_list = [self.n2, self.n4, self.n3, self.n5]
        if top in n6_list and forward in n6_list:
            return self.n6


dice = Dice([int(x) for x in input().split()])
cnt = int(input())

for i in range(cnt):
    a, b = (int(x) for x in input().split())
    print(dice.right_num(a, b))

Submission status: Wrong Answer

Solution code:
class Dice:
    __slots__ = ['n_list', 'pair_list']

    def __init__(self, n_tup):
        self.n_list = list(n_tup)
        self.pair_list = [self.return_dice_round_pair(2, 3, 5, 4),
                          self.return_dice_round_pair(1, 4, 6, 3),
                          self.return_dice_round_pair(1, 2, 6, 5),
                          self.return_dice_round_pair(1, 5, 6, 2),
                          self.return_dice_round_pair(1, 3, 6, 4),
                          self.return_dice_round_pair(2, 4, 5, 3)
                          ]

    @staticmethod
    def roll_switch(n_list, from_idx_list, to_idx_list):
        n_list[from_idx_list[0] - 1], \
        n_list[from_idx_list[1] - 1], \
        n_list[from_idx_list[2] - 1], \
        n_list[from_idx_list[3] - 1] \
            = n_list[to_idx_list[0] - 1], \
              n_list[to_idx_list[1] - 1], \
              n_list[to_idx_list[2] - 1], \
              n_list[to_idx_list[3] - 1]
        return n_list

    def roll(self, direction):
        if direction == "N":
            self.n_list = self.roll_switch(self.n_list, [1, 2, 6, 5], [2, 6, 5, 1])

        elif direction == "E":
            self.n_list = self.roll_switch(self.n_list, [1, 3, 6, 4], [4, 1, 3, 6])

        if direction == "S":
            self.n_list = self.roll_switch(self.n_list, [1, 2, 6, 5], [5, 1, 2, 6])

        if direction == "W":
            self.n_list = self.roll_switch(self.n_list, [1, 3, 6, 4], [3, 6, 4, 1])

    @staticmethod
    def return_dice_round_pair(a, b, c, d):
        return [(a, b), (b, c), (c, d), (d, a)]

    def return_right_num(self, top, forward):
        for i in range(6):
            if (top, forward) in self.pair_list[i]:
                return self.n_list[i]


dice = Dice([int(x) for x in input().split()])
cmd_cnt = int(input())

for i in range(cmd_cnt):
    top, forward = (int(x) for x in input().split())
    print(dice.return_right_num(top, forward))

Submission status: Wrong Answer

Solution code:
d=input().split()
for _ in range(int(input())):
 t,f=[d.index(s) for s in 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)}[int(t)]
 print(n[n.index(int(f))+1]+1)

Submission status: Wrong Answer

Solution code:
def north(list):
    List = []
    List.append(list[1])
    List.append(list[5])
    List.append(list[2])
    List.append(list[3])
    List.append(list[0])
    List.append(list[4])
    return List

def west(list):
    List = []
    List.append(list[2])
    List.append(list[1])
    List.append(list[5])
    List.append(list[0])
    List.append(list[4])
    List.append(list[3])
    return List
    
def south(list):
    List = []
    List.append(list[4])
    List.append(list[0])
    List.append(list[2])
    List.append(list[3])
    List.append(list[5])
    List.append(list[1])
    return List

def east(list):
    List = []
    List.append(list[3])
    List.append(list[1])
    List.append(list[0])
    List.append(list[5])
    List.append(list[4])
    List.append(list[2])
    return List
dice = list(map(int, input().split()))
D = [dice]
for i in range(0, 3):
    D.append(north(D[i]))
D.append(south(west(D[0])))
D.append(south(east(D[0])))
for i in range(6):
    for j in range(3):
        if j == 0:
            D.append(east(D[i + j]))
        else:
            D.append(east(D[5 + j]))

x = int(input())
for i in range(x):
    a, b = map(int, input().split())
    for i in range(len(D)):
        if a == D[i][0] and b == D[i][1]:
            print(D[i][2])
            break

Submission status: Wrong Answer

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

    def clockwise(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[2], self.labels[5]

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

for n in range(int(input())):
    foward, top = map(int, input().split())
    if foward+top == 7:
      print("not found")
      break
    south_cnt = 0

    while True:
        if foward == dice.labels[5] and top == dice.labels[1]:
            break
        if foward == dice.labels[5]:
            dice.east()
        elif top == dice.labels[1]:
            dice.clockwise()
        else:
            if south_cnt == 3:
                dice.east()
            else:
                dice.south()
                south_cnt += 1
    print(dice.labels[2])

Submission status: Wrong Answer

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

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

for n in range(int(input())):
    top, foward = map(int, input().split())
    south_cnt = 0

    while True:
        #print(dice.labels[0], dice.labels[1], dice.labels[2], dice.labels[4], dice.labels[3])
        if foward == dice.labels[1] and top == dice.labels[0]:
            break
        if foward == dice.labels[1]:
            dice.east()
            print(dice.labels[0])
        elif top == dice.labels[0]:
            dice.south()
            dice.east()
            dice.north()
        else:
            if south_cnt == 3:
                dice.east()
            else:
                dice.south()
                south_cnt += 1
    print(dice.labels[2])

Submission status: Wrong Answer

Solution code:
class Saikoro:

    def sai(self,one,two,three,four,five,six):
        self.s1=int(one)
        self.s2=int(two)
        self.s3=int(three)
        self.s4=int(four)
        self.s5=int(five)
        self.s6=int(six)

    def turnE(self):
        e=[self.s4,self.s2,self.s1,self.s6,self.s5,self.s3]
        self.s1=e[0]
        self.s2=e[1]
        self.s3=e[2]
        self.s4=e[3]
        self.s5=e[4]
        self.s6=e[5]

    def turnN(self):
        n=[self.s2,self.s6,self.s3,self.s4,self.s1,self.s5]
        self.s1=n[0]
        self.s2=n[1]
        self.s3=n[2]
        self.s4=n[3]
        self.s5=n[4]
        self.s6=n[5]


l=input().split()

sai1=Saikoro()
sai1.sai(l[0],l[1],l[2],l[3],l[4],l[5])

q=int(input())

i=0
Ans=[]
while i<q:
    m=input().split()
    ichi=int(m[0])
    ni=int(m[1])

    p=0
    while p<4:
        if ichi==1 and ni==3 or ichi==3 and ni==6 or ichi==6 and ni==4 or ichi==4 and ni==1 :
            Ans.append(5)
            break
        w=0
        sai1.turnE()
        while w<4:
            sai1.turnN()
            if sai1.s1==ichi and sai1.s2==ni:
                Ans.append(sai1.s3)
                break  
            else:
                pass
            w+=1
        p+=1
    i+=1

for A in Ans:
    print(A)

Submission status: Wrong Answer

Solution code:
class Saikoro:

    def sai(self,one,two,three,four,five,six):
        self.s1=int(one)
        self.s2=int(two)
        self.s3=int(three)
        self.s4=int(four)
        self.s5=int(five)
        self.s6=int(six)

    def turnE(self):
        e=[self.s4,self.s2,self.s1,self.s6,self.s5,self.s3]
        self.s1=e[0]
        self.s2=e[1]
        self.s3=e[2]
        self.s4=e[3]
        self.s5=e[4]
        self.s6=e[5]

    def turnN(self):
        n=[self.s2,self.s6,self.s3,self.s4,self.s1,self.s5]
        self.s1=n[0]
        self.s2=n[1]
        self.s3=n[2]
        self.s4=n[3]
        self.s5=n[4]
        self.s6=n[5]


l=input().split()

sai1=Saikoro()
sai1.sai(l[0],l[1],l[2],l[3],l[4],l[5])

q=int(input())

i=0
Ans=[]
while i<q:
    m=input().split()
    ichi=int(m[0])
    ni=int(m[1])

    p=0
    while p<4:
        if ichi==sai1.s1 and ni==sai1.s3 or ichi==sai1.s3 and ni==sai1.s6 or ichi==sai1.s6 and ni==sai1.s4 or ichi==sai1.s4 and ni==sai1.s1 :
            Ans.append(5)
            break
        w=0
        sai1.turnE()
        while w<4:
            sai1.turnN()
            if sai1.s1==ichi and sai1.s2==ni:
                Ans.append(sai1.s3)
                break
            else:
                pass
            w+=1
        p+=1
    i+=1

for A in Ans:
    print(A)

Submission status: Wrong Answer

Solution code:
class Saikoro:

    def sai(self,one,two,three,four,five,six):
        self.s1=int(one)
        self.s2=int(two)
        self.s3=int(three)
        self.s4=int(four)
        self.s5=int(five)
        self.s6=int(six)

    def turnE(self):
        e=[self.s4,self.s2,self.s1,self.s6,self.s5,self.s3]
        self.s1=e[0]
        self.s2=e[1]
        self.s3=e[2]
        self.s4=e[3]
        self.s5=e[4]
        self.s6=e[5]

    def turnN(self):
        n=[self.s2,self.s6,self.s3,self.s4,self.s1,self.s5]
        self.s1=n[0]
        self.s2=n[1]
        self.s3=n[2]
        self.s4=n[3]
        self.s5=n[4]
        self.s6=n[5]


l=input().split()

sai1=Saikoro()
sai1.sai(l[0],l[1],l[2],l[3],l[4],l[5])

q=int(input())

i=0
Ans=[]
while i<q:
    m=input().split()
    ichi=int(m[0])
    ni=int(m[1])

    p=0
    while p<4:
        if ichi==int(l[0]) and ni==int(l[2]) or ichi==int(l[2]) and ni==int(l[5]) or ichi==int(l[5]) and ni==int(l[3]) or ichi==int(l[3]) and ni==int(l[0]) :
            Ans.append(int(l[4]))
            break
        w=0
        sai1.turnE()
        while w<4:
            sai1.turnN()
            if sai1.s1==ichi and sai1.s2==ni:
                Ans.append(sai1.s3)
                break
            else:
                pass
            w+=1
        p+=1
    i+=1

for A in Ans:
    print(A)