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:
from sys import stdin
from copy import deepcopy
import queue

class Dice:
    def __init__(self, nums):
        self.labels = [None] + [ nums[i] for i in range(6) ]
        self.pos = {
            "E" : 3,
            "W" : 4,
            "S" : 2,
            "N" : 5,
            "T" : 1,
            "B" : 6
        }

    def rolled(dice, queries):
        d = deepcopy(dice)
        for q in queries:
            if q == "E":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["W"], d.pos["T"], d.pos["E"], d.pos["B"]
            elif q == "W":
                d.pos["T"], d.pos["E"], d.pos["B"], d.pos["W"] = d.pos["E"], d.pos["B"], d.pos["W"], d.pos["T"]
            elif q == "S":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["N"], d.pos["T"], d.pos["S"], d.pos["B"]
            elif q == "N":
                d.pos["T"], d.pos["S"], d.pos["B"], d.pos["N"] = d.pos["S"], d.pos["B"], d.pos["N"], d.pos["T"]
        else:
            return d

nums = [int(x) for x in stdin.readline().rstrip().split()]
q = int(stdin.readline().rstrip())
dice = Dice(nums)

# TとSに対応するクエリを記憶し, resをすぐに呼び出せるようにする
memo = [[False] * 7 for i in range(7)]
memo[dice.pos["T"]][dice.pos["S"]] = ""

# クエリとさいころの東面を記憶
res = { "" : dice.pos["E"] }

# BFSで探索, 解を求めたらreturn Trueで抜け出す
# diceの中身をいじってはならない
def solve(T, S):
	que = queue.Queue()
	que.put(dice)
	sol_q = ["E", "N", "S", "W"]
	
	while not que.empty():
		d = que.get()
		if d.pos["T"] == T and d.pos["S"] == S:
			break
		else:
			for i in sol_q:
				d_next = Dice.rolled(d, i)
				que.put(d_next)
				memo[d_next.pos["T"]][d_next.pos["S"]] = memo[d.pos["T"]][d.pos["S"]] + i
				res[memo[d_next.pos["T"]][d_next.pos["S"]]] = d_next.pos["E"]
	else:
		return memo[T][S]

for i in range(q):
    ts = [int(x) for x in stdin.readline().rstrip().split()]
    T = dice.labels.index(ts[0])
    S = dice.labels.index(ts[1])
    
    if solve(T, S) != False:
        print(res[memo[T][S]])

Submission status: Wrong Answer

Solution code:
class Dice:
  def make_dice(self, value):
    self.face = value
  def move(self, direc):
    if direc == "N":
      self.face = [self.face[1], self.face[5], self.face[2], self.face[3], self.face[0], self.face[4]]
      return self.face
    elif direc == "E":
      self.face = [self.face[3], self.face[1], self.face[0], self.face[5], self.face[4], self.face[2]]
      return self.face
    elif direc == "S":
      self.face = [self.face[4], self.face[0], self.face[2], self.face[3], self.face[5], self.face[1]]
      return self.face
    elif direc == "W":
      self.face = [self.face[2], self.face[1], self.face[5], self.face[0], self.face[4], self.face[3]]
      return self.face
  def get_face(self, top):
    if top == self.face[0]:
      return self.face
    elif top == self.face[1]:
      return dice.move("N")
    elif top == self.face[2]:
      return dice.move("W")
    elif top == self.face[3]:
      return dice.move("E")
    elif top == self.face[4]:
      return dice.move("S")
    elif top == self.face[5]:
      dice.move("N")
      return dice.move("N")
  def right_face(self, face1, face2):
    if face1 == self.face[0]:
      if face2 == self.face[1]:
        return self.face[2]
      elif face2 == self.face[2]:
        return self.face[4]
      elif face2 == self.face[4]:
        return self.face[3]

num = list(map(int, input().split()))
q = int(input())
dice = Dice()
dice.make_dice(num)
for i in range(q):
  f1, f2 = map(int,input().split())
  dice.get_face(f1)
  print(dice.right_face(f1,f2))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# coding: utf-8

class Dice() :
    rightlist = ((-1,3,1,4,2,-1),
                 (2,-1,5,0,-1,3),
                 (4,0,-1,-1,5,2),
                 (1,5,-1,-1,0,4),
                 (3,-1,0,5,-1,2),
                 (-1,2,4,1,3,-1))

    def __init__(self, data):
        self.label = data

    def get_up(self):
        return self.label[0]

    def get_rightdata(self, up, front):
        upidx = self.label.index(up);
        fridx = self.label.index(front)
        return self.label[self.rightlist[fridx][upidx]]


dicedata = input().split()
count = int(input())
queslist = []
[queslist.append(input().split()) for i in range(count)]

newdice = Dice(dicedata)

[print(newdice.get_rightdata(queslist[i][0], queslist[i][1])) for i in range(count)]

Submission status: Wrong Answer

Solution code:
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice = Dice(s1, s2, s3, s4, s5, s6)
q = int(input())
for i in range(q):
    t, f = map(int, input().split())
    for j in range(4):
        for k in range(4):
            if dice.top() == t and dice.front() == f:
                break
            dice.east()
        dice.north()

    print(dice.right())

Submission status: Wrong Answer

Solution code:
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def rotate(self):
        prev_s2 = self.s2
        self.s2 = self.s4
        self.s4 = self.s5
        self.s5 = self.s3
        self.s3 = prev_s2
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice = Dice(s1, s2, s3, s4, s5, s6)
q = int(input())
for i in range(q):
    t, f = map(int, input().split())
    flag = False
    for j in range(6):
        dice.north()
        for k in range(4):
            dice.rotate()
            if dice.top() == t and dice.front() == f:
                flag = True
                break
        if flag:
            break
    print(dice.right())

Submission status: Wrong Answer

Solution code:
def R(U,S):
  PAT=["12431","03520","01540","04510","02530","13421"]
  it="".join(map(str,[U-1,S-1]))
  for i in range(6):
    if PAT[i].find(it)>=0: return i+1

dice = map(int,raw_input().split())
for _ in raw_input():
  U,S=map(int,raw_input().split())
  print R(U,S)

Submission status: Wrong Answer

Solution code:
def R(U,S):
  PAT=["12431","03520","01540","04510","02530","13421"]
  it="".join(map(str,[U-1,S-1]))
  for i in range(6):
    if PAT[i].find(it)>=0: return dice[i]

dice = map(int,raw_input().split())
for _ in [0]*int(raw_input()):
  U,S=map(int,raw_input().split())
  print R(U,S)

Submission status: Wrong Answer

Solution code:
IDX_TABLE=\
{1:[4,2,3,5],
 2:[1,4,6,3],
 3:[1,2,6,5],
 4:[1,2,6,3],
 5:[1,4,6,3],
 6:[3,2,4,5]}

nums = ["dummy"] + [int(x) for x in raw_input().split(" ")]
n = int(raw_input())

for i in range(n):
    up, front = tuple([int(x) for x in raw_input().split(" ")])
    up_idx = nums.index(up)
    front_idx = nums.index(front)
    ring_list = IDX_TABLE[up_idx]
    ring_idx = ring_list.index(front_idx)

    print ring_list[(ring_idx+1) % 4]

Submission status: Wrong Answer

Solution code:
IDX_TABLE=\
{1:[4,2,3,5],
 2:[1,4,6,3],
 3:[1,2,6,5],
 4:[1,2,6,3],
 5:[1,4,6,3],
 6:[3,2,4,5]}

nums = ["dummy"] + [int(x) for x in raw_input().split(" ")]
n = int(raw_input())

for i in range(n):
    up, front = tuple([int(x) for x in raw_input().split(" ")])
    up_idx = nums.index(up)
    front_idx = nums.index(front)
    ring_list = IDX_TABLE[up_idx]
    ring_idx = ring_list.index(front_idx)

    print nums[ring_list[(ring_idx+1) % 4]]

Submission status: Wrong Answer

Solution code:
IDX_TABLE=\
{1:[4,2,3,5],
 2:[1,4,6,3],
 3:[1,2,6,5],
 4:[1,5,6,2],
 5:[1,4,6,3],
 6:[3,2,4,5]}

nums = ["dummy"] + [int(x) for x in raw_input().split(" ")]
n = int(raw_input())

for i in range(n):
    up, front = tuple([int(x) for x in raw_input().split(" ")])
    up_idx = nums.index(up)
    front_idx = nums.index(front)
    ring_list = IDX_TABLE[up_idx]
    ring_idx = ring_list.index(front_idx)

    print nums[ring_list[(ring_idx+1) % 4]]

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,ls):
        self.a = ls[1-1] # top
        self.b = ls[2-1] # front
        self.c = ls[3-1] # right
        self.d = ls[4-1] # left
        self.e = ls[5-1] # back
        self.f = ls[6-1] # bottom
    
    def E(self):
        self.a, self.c, self.f, self.d = self.d, self.a, self.c, self.f
    def W(self):
        self.a, self.c, self.f, self.d = self.c, self.f, self.d, self.a
    def S(self):
        self.a, self.b, self.f, self.e = self.e, self.a, self.b, self.f
    def N(self):
        self.a, self.b, self.f, self.e = self.b, self.f, self.e, self.a
    
ls = map(int,raw_input().split())
q = int(raw_input())
for i in range(q):
    dice = Dice(ls)
    a,b = map(int,raw_input().split())
    while dice.a == a and dice.b == b:
        dice.E() or dice.W() or dice.S() or dice.N()
    else:
        print dice.c

Submission status: Wrong Answer

Solution code:
import sys

class Dice(object):
	def __init__(self, data):
		self.dice=data
	def roll_n(self):
		self.dice=(self.dice[1],self.dice[5],self.dice[2],
					self.dice[3],self.dice[0],self.dice[4])
	def roll_e(self):
		self.dice=(self.dice[3],self.dice[1],self.dice[0],
					self.dice[5],self.dice[4],self.dice[2])
	def roll_w(self):
		self.dice=(self.dice[2],self.dice[1],self.dice[5],
					self.dice[0],self.dice[4],self.dice[3])				
	def roll_s(self):
		self.dice=(self.dice[4],self.dice[0],self.dice[2],
					self.dice[3],self.dice[5],self.dice[1])
	def get_top(self, id):
 		return self.dice[id-1]

data=Dice([int(i) for i in sys.stdin.readline().split()])
order=sys.stdin.readline().strip()
for i in order:
	if i=='N':
		data.roll_n()
	elif i=='E':
		data.roll_e()
	elif i=='S':
		data.roll_s()
	elif i=='W':
		data.roll_w()
print(data.get_top(1))

Submission status: Wrong Answer

Solution code:
axis_1 = '0154' * 2  # 2 -> 3
axis_2 = '0253' * 2  # 4 -> 1
axis_3 = '3124' * 2  # 0 -> 5

right = [axis_3, axis_2[::2], axis_1, axis_1[::-1], axis_2, axis_3[::-1], ]
a = list(map(int, input().split()))
n = int(input())
for _ in range(n):
    top, front = map(a.index, map(int, input().split()))
    x = '%d%d' % (top, front)
    for i, axis in enumerate(right):
        if x in axis:
            print(a[i])

Submission status: Wrong Answer

Solution code:
import copy

class Dice(object):
	def __init__(self,List):
		self.face=List
		
	def n_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[1]
		List[1]=List[5]
		List[5]=List[4]
		List[4]=temp
		return List
		
 	def s_spin(self,a_list):
 		List=copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[4]
 		List[4]=List[5]
		List[5]=List[1]
		List[1]=temp
		return List
		
	def e_spin(self,a_list):
		List=copy.copy(a_list)
		temp=List[0]
		List[0]=List[3]
		List[3]=List[5]
		List[5]=List[2]
		List[2]=temp
		return List
		
 	def w_spin(self,a_list):
 		List = copy.copy(a_list)
 		temp=List[0]
 		List[0]=List[2]
 		List[2]=List[5]
		List[5]=List[3]
		List[3]=temp
		return List

dice=Dice(map(int,raw_input().split()))
emer=copy.copy(dice.face)
face_storage=[]
face_storage.append(emer)
q=input()
for a in range(q):
	question=map(int,raw_input().split())
	for a in range(16):
		face_storage.append(dice.n_spin(face_storage[a]))
		face_storage.append(dice.s_spin(face_storage[a]))
		face_storage.append(dice.e_spin(face_storage[a]))
		face_storage.append(dice.w_spin(face_storage[a]))
	for c in face_storage:
		if c[0]==question[0] and c[1]==question[1]:
			print(c[2])
			break

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self, num_list):
        self.faces = num_list

    def find_rf(self, top, front):
        tf = str(self.faces.index(top)) + str(self.faces.index(front))
        if tf in '12431':
            return 1
        elif tf in '03520':
            return 2
        elif tf in '01540':
            return 3
        elif tf in '04519':
            return 4
        elif tf in '02530':
            return 5
        else:
            return 6

num_list = tuple(map(int, input().split()))

dice = Dice(num_list)

q = int(input())

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

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self, num_list):
        self.faces = num_list

    def find_rf(self, top, front):
        tf = str(self.faces.index(top)) + str(self.faces.index(front))
        if tf in '12431':
            return self.faces[0]
        elif tf in '03520':
            return self.faces[1]
        elif tf in '01540':
            return self.faces[2]
        elif tf in '04519':
            return self.faces[3]
        elif tf in '02530':
            return self.faces[4]
        else:
            return self.faces[5]

num_list = tuple(map(int, input().split()))

dice = Dice(num_list)

q = int(input())

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

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'front', 'right',
                               'left', 'back', 'bottom'], face_vals.split()))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['front'], self.faces['bottom'], \
            self.faces['back'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['back'], self.faces['top'], \
            self.faces['front'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['left'], self.faces['top'], \
            self.faces['right'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['right'], self.faces['bottom'], \
            self.faces['left'], self.faces['top']

    def _revolve(self, direction):
        if direction == 'R':
            self.faces['front'], self.faces['left'], self.faces['back'], \
            self.faces['right'] = self.faces['right'], self.faces['front'], \
            self.faces['left'], self.faces['back']
        else:
            self.faces['front'], self.faces['left'], self.faces['back'], \
            self.faces['right'] = self.faces['left'], self.faces['back'], \
            self.faces['right'], self.faces['front']
            
    def show_right_face(self, top, front):
        if front == self.faces['back']:
            if top == self.faces['top']:
                self._revolve('R')
                self._revolve('R')
            else:
                self.roll('S')
                self.roll('S')
        elif front == self.faces['right']:
            self._revolve('R')
        elif front == self.faces['left']:
            self._revolve('L')
        elif front == self.faces['bottom']:
            self.roll('N')
        if top == self.faces['bottom']:
            self.roll('E')
            self.roll('E')
        elif top == self.faces['right']:
            self.roll('W')
        elif top == self.faces['left']:
            self.roll('E')
        print(self.faces['right'])


import sys

face_vals = sys.stdin.readline()

dice = Dice(face_vals)

n = int(sys.stdin.readline())

for i in range(n):
    top, front = sys.stdin.readline().split()
    dice.show_right_face(top, front)

Submission status: Wrong Answer

Solution code:
# 24-Structure_and_Class-Dice_II.py

# ???????????? II
# Dice I ??¨????§????????????§?????\??????????????°????????????????????????????????????????????????
# ????????????????????? Dice I ???????????§?????¢????????????????????¢??¨?????¢?????°??????
# ????????¨??????????????????????????§????????´?????¢?????°???????????????????????°????????????????????????????????????

# Input
# ?????????????????¢?????°???????????????????????????????????????????????§?????????????????????
# ???????????????????????° qq ????????????????????????
# ?¶???? qq ???????????????????????????????????????????????§????????¢??¨?????¢?????°????????¨??????????????´??°????????????????????§??????????????????????????????

# Output
# ??????????????¨??????????????????????????´?????¢?????°??????????????????????????????????????????
	
# Constraints
# 0???0??? ??\?????????????????????????????¢?????°??? ???100???100
# ??\?????????????????????????????¢?????°?????????????????°??????
# 1???q???241???q???24

# Sample Input
# 1 2 3 4 5 6
# 3
# 6 5
# 1 3
# 3 2
# Sample Output
# 3
# 5
# 6

class Dice:
	def __init__(self, dice_num):
		self.side_top=1
		self.side_bot=6
		self.side_Nor=5
		self.side_Eas=3
		self.side_Sau=2
		self.side_Wes=4
		self.dice_num = dice_num

	def op_N(self):
		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
		self.side_Sau, self.side_Nor, self.side_top, self.side_bot

	def op_E(self):
		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
		self.side_Wes, self.side_Eas, self.side_top, self.side_bot

	def op_S(self):
		self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\
		self.side_Nor, self.side_Sau, self.side_bot, self.side_top

	def op_W(self):
		self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\
		self.side_Eas, self.side_Wes, self.side_bot, self.side_top

	def print_side_top(self):
		print( dice_num[self.side_top-1] )

	def print_side_all(self):
		print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )

	def get_num_side_Eas(self, side_top, side_Sau):
		if (side_top, side_Sau)==(1, 2): return self.dice_num[ 3-1 ]
		elif  (side_top, side_Sau)==(1, 3): return self.dice_num[ 5-1 ]
		elif  (side_top, side_Sau)==(1, 4): return self.dice_num[ 2-1 ]
		elif  (side_top, side_Sau)==(1, 5): return self.dice_num[ 4-1 ]
		elif  (side_top, side_Sau)==(2, 1): return self.dice_num[ 4-1 ]
		elif  (side_top, side_Sau)==(2, 3): return self.dice_num[ 1-1 ]
		elif  (side_top, side_Sau)==(2, 4): return self.dice_num[ 6-1 ]
		elif  (side_top, side_Sau)==(2, 6): return self.dice_num[ 3-1 ]
		elif  (side_top, side_Sau)==(3, 1): return self.dice_num[ 2-1 ]
		elif  (side_top, side_Sau)==(3, 2): return self.dice_num[ 6-1 ]
		elif  (side_top, side_Sau)==(3, 5): return self.dice_num[ 1-1 ]
		elif  (side_top, side_Sau)==(3, 6): return self.dice_num[ 5-1 ]
		elif  (side_top, side_Sau)==(4, 1): return self.dice_num[ 5-1 ]
		elif  (side_top, side_Sau)==(4, 2): return self.dice_num[ 1-1 ]
		elif  (side_top, side_Sau)==(4, 5): return self.dice_num[ 6-1 ]
		elif  (side_top, side_Sau)==(5, 1): return self.dice_num[ 3-1 ]
		elif  (side_top, side_Sau)==(5, 3): return self.dice_num[ 6-1 ]
		elif  (side_top, side_Sau)==(5, 4): return self.dice_num[ 1-1 ]
		elif  (side_top, side_Sau)==(5, 6): return self.dice_num[ 4-1 ]
		elif  (side_top, side_Sau)==(6, 2): return self.dice_num[ 4-1 ]
		elif  (side_top, side_Sau)==(6, 3): return self.dice_num[ 2-1 ]
		elif  (side_top, side_Sau)==(6, 4): return self.dice_num[ 5-1 ]
		elif  (side_top, side_Sau)==(6, 5): return self.dice_num[ 3-1 ]

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

for i in range( int(input()) ):
	print( dice_roll.get_num_side_Eas( *list(map(int, input().split() )) ) )

Submission status: Wrong Answer

Solution code:
# 24-Structure_and_Class-Dice_II.py

# ???????????? II
# Dice I ??¨????§????????????§?????\??????????????°????????????????????????????????????????????????
# ????????????????????? Dice I ???????????§?????¢????????????????????¢??¨?????¢?????°??????
# ????????¨??????????????????????????§????????´?????¢?????°???????????????????????°????????????????????????????????????

# Input
# ?????????????????¢?????°???????????????????????????????????????????????§?????????????????????
# ???????????????????????° qq ????????????????????????
# ?¶???? qq ???????????????????????????????????????????????§????????¢??¨?????¢?????°????????¨??????????????´??°????????????????????§??????????????????????????????

# Output
# ??????????????¨??????????????????????????´?????¢?????°??????????????????????????????????????????
	
# Constraints
# 0???0??? ??\?????????????????????????????¢?????°??? ???100???100
# ??\?????????????????????????????¢?????°?????????????????°??????
# 1???q???241???q???24

# Sample Input
# 1 2 3 4 5 6
# 3
# 6 5
# 1 3
# 3 2
# Sample Output
# 3
# 5
# 6

class Dice:
	def __init__(self, dice_num):	  # 1    2    3    4    5    6
		self.dice_state=[1,6,5,3,2,4] #[top, bot, nor, eas, sau, wes]
		self.dice_num = dice_num

	def op_N(self):
		self.dice_state = [ self.dice_state[i-1] for i in [5,3,1,4,2,6] ]

	def op_E(self):
		self.dice_state = [ self.dice_state[i-1] for i in [6,4,3,1,5,2] ]

	def op_S(self):
		self.dice_state = [ self.dice_state[i-1] for i in [3,5,2,4,1,6] ]

	def op_W(self):
		self.dice_state = [ self.dice_state[i-1] for i in [4,6,3,2,5,1] ]

	def get_state_top(self):
		# print("dice_roll.get_state_top", self.dice_state[0])
		return self.dice_state[0]

	def get_num_top(self):
		return self.dice_num[self.dice_state[0]-1]

	def print_side_top(self):
		print( self.dice_num[self.dice_state[0]-1] )

	def print_side_all(self):
		print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) )




dice_roll = Dice(  list( map(int, input().split()))  ) 
Func_set = {'N': dice_roll.op_N, 'W': dice_roll.op_W, 'E': dice_roll.op_E, 'S': dice_roll.op_S}

for i in range( int(input()) ):
	top, south = map(int,input().split())

	for j in "NNNEEE":
		if dice_roll.get_state_top() == top:
			break;
		Func_set[j]()
	
	Func_set["N"]()

	for j in "EEE":
		if dice_roll.get_state_top() == south:
			break;
		Func_set[j]()
	
	Func_set["W"]()

	print( dice_roll.get_num_top() )

Submission status: Wrong Answer

Solution code:
class dice:
    def __init__(self,label):
        self.d = label
    def roll(self,op):
        d = self.d
        if   op=='N': self.d = [d[1],d[5],d[2],d[3],d[0],d[4]]
        elif op=='E': self.d = [d[3],d[1],d[0],d[5],d[4],d[2]]
        elif op=='W': self.d = [d[2],d[1],d[5],d[0],d[4],d[3]]
        elif op=='S': self.d = [d[4],d[0],d[2],d[3],d[5],d[1]]
    def print(self):
        print(self.d[0])
    def print_r_side(self,t,f):
        d = self.d
        if   (t,f)==(d[0],d[1]): print(d[2])
        elif (t,f)==(d[0],d[2]): print(d[4])
        elif (t,f)==(d[0],d[3]): print(d[1])
        elif (t,f)==(d[0],d[4]): print(d[3])
        elif (t,f)==(d[1],d[0]): print(d[4])
        elif (t,f)==(d[1],d[2]): print(d[0])
        elif (t,f)==(d[1],d[3]): print(d[5])
        elif (t,f)==(d[1],d[5]): print(d[2])
        elif (t,f)==(d[2],d[0]): print(d[1])
        elif (t,f)==(d[2],d[1]): print(d[5])
        elif (t,f)==(d[2],d[4]): print(d[0])
        elif (t,f)==(d[2],d[5]): print(d[4])
        elif (t,f)==(d[3],d[0]): print(d[5])
        elif (t,f)==(d[3],d[1]): print(d[0])
        elif (t,f)==(d[3],d[4]): print(d[5])
        elif (t,f)==(d[3],d[5]): print(d[1])
        elif (t,f)==(d[4],d[0]): print(d[2])
        elif (t,f)==(d[4],d[2]): print(d[5])
        elif (t,f)==(d[4],d[3]): print(d[1])
        elif (t,f)==(d[4],d[5]): print(d[3])
        elif (t,f)==(d[5],d[1]): print(d[3])
        elif (t,f)==(d[5],d[2]): print(d[1])
        elif (t,f)==(d[5],d[3]): print(d[4])
        elif (t,f)==(d[5],d[4]): print(d[2])

label = list(map(int,input().split()))
q = int(input())
d0 = dice(label)
for _ in range(q):
    t,f = list(map(int,input().split()))
    d0.print_r_side(t,f)

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self, numbers):
        # top, front, right, left, back, bottom
        self.numbers = numbers
    
    @property
    def top(self):
        return self.numbers[0]
    
    @property
    def front(self):
        return self.numbers[1]
        
    @property
    def right(self):
        return self.numbers[2]
        
    @property
    def left(self):
        return self.numbers[3]
    
    @property
    def back(self):
        return self.numbers[4]
        
    @property
    def bottom(self):
        return self.numbers[5]

    def roll(self, direction):
        if direction == "N":
            before_inds = [0, 1, 5, 4]
            after_inds  = [1, 5, 4, 0]
        elif direction == "S":
            before_inds = [0, 1, 5, 4]
            after_inds  = [4, 0, 1, 5]
        elif direction == "E":
            before_inds = [0, 2, 5, 3]
            after_inds  = [3, 0, 2, 5]
        elif direction == "W":
            before_inds = [0, 2, 5, 3]
            after_inds  = [2, 5, 3, 0]
        elif direction == "C":
            before_inds = [1, 2, 4, 3]
            after_inds  = [2, 4, 3, 1]
        else:
            return False
        changed = [self.numbers[i] for i in after_inds]
        for c_i, n_i in enumerate(before_inds):
            self.numbers[n_i] = changed[c_i]
        return True
        
    def comb(self):
        rolled = [self]
        dice_copy = self.copy()
        for d in "NNN":
            dice_copy = dice_copy.copy()
            dice_copy.roll(d)
            rolled.append(dice_copy)
            
        dice_copy = self.copy()
        for d in "EEE":
            dice_copy = dice_copy.copy()
            dice_copy.roll(d)
            rolled.append(dice_copy)
            
        dice_copy = self.copy()
        for d in "CCC":
            dice_copy = dice_copy.copy()
            dice_copy.roll(d)
            rolled.append(dice_copy)
            
        return rolled
        
    def copy(self):
        return Dice(list(self.numbers))

dice = Dice(map(int, raw_input().split()))
rolled_dices = dice.comb()

N = input()
for i in range(N):
    top, front = map(int, raw_input().split())
    for cnd in rolled_dices:
        if cnd.top == top and cnd.front == front:
            print cnd.right
            break

Submission status: Wrong Answer

Solution code:
class Dice:
    def __init__(self,pips):
        self.top = pips[0]
        self.south = pips[1]
        self.east = pips[2]
        self.west = pips[3]
        self.north =pips[4]
        self.bottom=pips[5]
    def n(self):
        self.top,self.south,self.bottom,self.north = \
        self.south,self.bottom,self.north,self.top
    def s(self):
        self.top,self.north,self.bottom,self.south = \
        self.north,self.bottom,self.south,self.top
    def e(self):
        self.top,self.west,self.bottom,self.east = \
        self.west,self.bottom,self.east,self.top
    def w(self):
        self.top,self.east,self.bottom,self.west = \
        self.east,self.bottom,self.west,self.top
    def r(self):
        self.north,self.east,self.south,self.west = \
        self.east,self.south,self.west,self.north
    def set(self,t,s):
        for i in range(3):
            if self.top != t:
                if self.east == t | self.west == t:
                    self.e()
                else:
                    self.n()
        for i in range(3):
            if self.south != s:
                self.r()

pips = [int(x) for x in input().split()]
a = Dice(pips)

n = int(input())
for i in range(n):
    t,s = map(int,input().split())
    a.set(t,s)
    print(a.east)

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):
			# 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 top(self):
		z = self.ax[self.axmap[2]]
		return self.dice[z[0]][z[1]]
	
	def right(self):
		y = self.ax[self.axmap[1]]
		return self.dice[y[0]][y[1]]

	def front(self):
		x = self.ax[self.axmap[0]]
		return self.dice[x[0]][x[1]]

if __name__=="__main__":
	dice = Dice()
	labels = input().split()
	q = int(input())
	for _ in range(q):
		a, b = input().split()
		p = labels.index(a) + 1
		for _ in range(4):
			if p==dice.top():
				break
			dice.rotate("N")
		for _ in range(4):
			if p==dice.top():
				break
			dice.rotate("E")
		
		p = labels.index(b) + 1
		for _ in range(4):
			if p==dice.front():
				break;
			dice.rotate("R")

		print(dice.right())