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):
class Dice(object):
 
    def __init__(self, d):

        self.rows = [d[0], d[4], d[5], d[1]]
        self.cols = [d[0], d[2], d[5], d[3]]
 
    def __move_next(self, x, y):
        temp = y.pop(0)
        y.append(temp)
        x[0] = y[0]
        x[2] = y[2]
 
    def __move_prev(self, x, y):
        temp = y.pop(3)
        y.insert(0, temp)
        x[0] = y[0]
        x[2] = y[2]
 
    def execute(self, c):
        for i in c:
            self.__move(i, self.rows, self.cols)
 
    def __move(self, com, x, y):
        if com == "N":
            self.__move_prev(y, x)
        elif com == "S":
            self.__move_next(y, x)
        elif com == "E":
            self.__move_prev(x, y)
        elif com == "W":
            self.__move_next(x, y)
 
    def print_top(self):
        print(self.rows[0])
    
    def execute2(self, a, b):
        self.__rot(a)
        if a == self.rows[0] or a == self.rows[2]:
            self.__move_prev(self.cols, self.rows)    
        
        self.__rot(b)
        
        while a != self.rows[0]:
            self.__move_prev(self.cols, self.rows)    
        
        if b == self.rows[1]:
            print(self.cols[3])
        elif b == self.rows[3]:
            print(self.cols[1])
        
    def __rot(self, z):
        i = 0
        while z not in self.rows:
            self.__move_next(self.rows, self.cols)
            if i > 3:
                self.__move_next(self.cols, self.rows)
                i = 0
            i+=1

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

for i in range(c):
    a, b = map(int, input().split(" "))
    dice.execute2(a,b)

Solution (Python):
class Daise:
    def __init__(self, info_list):
        self.T = info_list[0]
        self.S = info_list[1]
        self.E = info_list[2]
        self.W = info_list[3]
        self.N = info_list[4]
        self.B = info_list[5]
    
    def change(self, axis):
        if axis == 'S':
            self.T, self.B, self.S, self.N = self.N, self.S, self.T, self.B
        
        elif axis == 'E':
            self.T, self.B, self.E, self.W = self.W, self.E, self.T, self.B
        
        elif axis == 'W':
            self.T, self.B, self.W, self.E = self.E, self.W, self.T, self.B
        
        elif axis == 'N':
            self.T, self.B, self.N, self.S = self.S, self.N, self.T, self.B
        
        elif axis == 'Turn':
            self.S, self.E, self.N, self.W = self.E, self.N, self.W, self.S


if __name__ == '__main__':
    info = list(map(str, input().split()))
    n_input = int(input())

    for _ in range(n_input):
        obj = Daise(info)
        operation = list(map(str, input().split()))
        
        if operation[1] in (obj.T, obj.B):
            obj.change("S")
            
        while obj.S != operation[1]:
            obj.change('Turn')

        while obj.T != operation[0]:
            obj.change('E')

        print(obj.E)

Solution (Python):
class Dice:

    def __init__(self):
        
        
        self.t = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.b = 6
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def __init__(self, t, s, e, w, n, b):
        
        self.t = t
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.b = b
        self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3}

    def rot(self, way):
        if way == 0:
            self.t, self.s, self.e, self.w, self.n, self.b = self.n, self.t, self.e, self.w, self.b, self.s
        elif way == 1:
            self.t, self.s, self.e, self.w, self.n, self.b = self.s, self.b, self.e, self.w, self.t, self.n
        elif way == 2:
            self.t, self.s, self.e, self.w, self.n, self.b = self.w, self.s, self.t, self.b, self.n, self.e
        elif way == 3:
            self.t, self.s, self.e, self.w, self.n, self.b = self.e, self.s, self.b, self.t, self.n, self.w
        
        
def main():
    import random

    t,s,e,w,n,b = map(int, input().split())
    dice2 = Dice(t,s,e,w,n,b)
    q = int(input())
    for _ in range(q):
        top, front = map(int, input().split())
        while True:
            if dice2.t == top and dice2.s == front:
                break
            else:
                seed = random.randint(0, 3)
                dice2.rot(seed)
        print(dice2.e)



if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    def __init__(self, dice: list):
        self.top = dice[0]
        self.bottom = dice[5]
        self.front = dice[1]
        self.behind = dice[4]
        self.right = dice[2]
        self.left = dice[3]

    def roll(self, direction: str):
        buffer = self.top
        if direction == 'E':
            self.top = self.left
            self.left = self.bottom
            self.bottom = self.right
            self.right = buffer
        elif direction == 'N':
            self.top = self.front
            self.front = self.bottom
            self.bottom = self.behind
            self.behind = buffer
        elif direction == 'S':
            self.top = self.behind
            self.behind = self.bottom
            self.bottom = self.front
            self.front = buffer
        else:
            self.top = self.right
            self.right = self.bottom
            self.bottom = self.left
            self.left = buffer

    def turn(self):
        buffer = self.front
        self.front = self.right
        self.right = self.behind
        self.behind = self.left
        self.left = buffer


def main():
    dice = Dice(list(map(int, input().split())))
    for _ in range(int(input())):
        top, front = map(int, input().split())
        while True:
            if dice.right != top and dice.left != top:
                break
            dice.turn()
        while dice.top != top:
            dice.roll('N')
        while dice.front != front:
            dice.turn()
        print(dice.right)


if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    def __init__(self,num):
        self.num = num.copy()
        
    def east(self):
        temp = self.num.copy()
        self.num[1-1] = temp[4-1]
        self.num[4-1] = temp[6-1]
        self.num[6-1] = temp[3-1]
        self.num[3-1] = temp[1-1]

    def north(self):
        temp = self.num.copy()
        self.num[1-1] = temp[2-1]
        self.num[2-1] = temp[6-1]
        self.num[6-1] = temp[5-1]
        self.num[5-1] = temp[1-1]

    def south(self):
        temp = self.num.copy()
        self.num[1-1] = temp[5-1]
        self.num[5-1] = temp[6-1]
        self.num[6-1] = temp[2-1]
        self.num[2-1] = temp[1-1]

    def west(self):
        temp = self.num.copy()
        self.num[1-1] = temp[3-1]
        self.num[3-1] = temp[6-1]
        self.num[6-1] = temp[4-1]
        self.num[4-1] = temp[1-1]

    def right(self):
        temp = self.num.copy()
        self.num[2-1] = temp[4-1]
        self.num[4-1] = temp[5-1]
        self.num[5-1] = temp[3-1]
        self.num[3-1] = temp[2-1]

num = list(map(int,input().split()))
dice = Dice(num)
q = int(input())
for _ in range(q):
    top,front = map(int,input().split())
    while not (top == dice.num[0] or front == dice.num[1]): dice.north()
    while top != dice.num[0]: dice.east()
    while front != dice.num[1]: dice.right()
    print(dice.num[2])

Solution (Python):
c=[int(i) for i in input().split()]
Q=int(input())
inp=[map(int,input().split()) for i in range(Q)]
d=[(0,0,1),(-1,0,0),(0,1,0),(0,-1,0),(1,0,0),(0,0,-1)]
def north(r):
    res=[]
    for p in r:
        res.append((p[2],p[1],-p[0]))
    return res
def south(r):
    res=[]
    for p in r:
        res.append((-p[2],p[1],p[0]))
    return res
def east(r):
    res=[]
    for p in r:
        res.append((p[0],p[2],-p[1]))
    return res
def west(r):
    res=[]
    for p in r:
        res.append((p[0],-p[2],p[1]))
    return res
for k in range(Q):
    x=(0,0,0)
    y=(0,0,0)
    a,b=inp[k]
    for i in range(6):
        if a==c[i]:
            x=d[i]
        if b==c[i]:
            y=d[i]
    z=(y[1]*x[2]-y[2]*x[1],y[2]*x[0]-y[0]*x[2],y[0]*x[1]-y[1]*x[0])
    for i in range(6):
        if d[i]==z:
            print(c[i])

Solution (Python):
from typing import List


class Dice:

    sur = [i for i in range(6)]

    def __init__(self, s: List[int]):
        self.s = s  

        
        self.sur[0] = [1, 2, 4, 3]
        self.sur[1] = [0, 3, 5, 2]
        self.sur[2] = [1, 5, 4, 0]
        self.sur[3] = [1, 0, 4, 5]
        self.sur[4] = [0, 2, 5, 3]
        self.sur[5] = [1, 3, 4, 2]

    def get_right_face_index(self, upper: int, front: int) -> int:
        for i, num in enumerate(self.sur[upper]):
            if num == front:
                return self.sur[upper][(i + 1) % 4]
        else:
            raise ValueError('get_right_faceの来てはいけない箇所')

    def get_num(self, index) -> int:
        return self.s[index]

    def get_sur_index(self, num) -> int:
        for i in range(len(self.s)):
            if num == self.s[i]:
                return i
        else:
            raise ValueError('get_sur_indexの来てはいけない箇所')



data = [int(i) for i in input().split()]
N = int(input())
dice = Dice(data)
for _i in range(N):
    upper_num, right_num = map(int, input().split())
    upper_index = dice.get_sur_index(upper_num)
    right_index = dice.get_sur_index(right_num)
    ans_index = dice.get_right_face_index(upper_index, right_index)
    print(dice.get_num(ans_index))

Solution (Python):
from typing import List


class Dice:

    sur = [i for i in range(6)]

    def __init__(self, s: List[int]):
        self.s = s  

        
        self.sur[0] = [1, 2, 4, 3]
        self.sur[1] = [0, 3, 5, 2]
        self.sur[2] = [1, 5, 4, 0]
        self.sur[3] = [1, 0, 4, 5]
        self.sur[4] = [0, 2, 5, 3]
        self.sur[5] = [1, 3, 4, 2]

    def get_right_face_num(self, upper_num: int, front_num: int) -> int:
        for i, value in enumerate(self.sur[upper_num]):
            if value == front_num:
                return self.sur[upper_num][(i + 1) % 4]
        else:
            raise ValueError('get_right_faceの来てはいけない箇所')

    def get_value(self, face_num) -> int:
        return self.s[face_num]

    def get_face_num(self, value) -> int:
        for i in range(len(self.s)):
            if value == self.s[i]:
                return i
        else:
            raise ValueError('get_sur_indexの来てはいけない箇所')



data = [int(i) for i in input().split()]
N = int(input())
dice = Dice(data)
for _i in range(N):
    upper_value, front_value = map(int, input().split())
    upper_num = dice.get_face_num(upper_value)
    front_num = dice.get_face_num(front_value)
    ans_num = dice.get_right_face_num(upper_num, front_num)
    print(dice.get_value(ans_num))

Solution (Python):
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)


memo = [[False] * 7 for i in range(7)]
memo[dice.pos["T"]][dice.pos["S"]] = ""


res = { "" : dice.labels[dice.pos["E"]] }



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.labels[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]])

Solution (Python):
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)


memo = [[False] * 7 for i in range(7)]
memo[dice.pos["T"]][dice.pos["S"]] = ""


res = { "" : dice.labels[dice.pos["E"]] }



def solve(T, S):
	if isinstance(memo[T][S], str):
		return memo[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.labels[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]])

Solution (Python):
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)


memo = [[False] * 7 for i in range(7)]
memo[dice.pos["T"]][dice.pos["S"]] = ""


res = { "" : dice.labels[dice.pos["E"]] }



def solve(T, S):
    if isinstance(memo[T][S], str):
        return memo[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)
                if memo[d_next.pos["T"]][d_next.pos["S"]] == False:
                    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.labels[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]])

Solution (Python):
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 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]
    elif face2 == self.face[3]:
      return self.face[1]

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

Solution (Python):


import random

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    dice = Dice(*map(int, raw_input().split()))

    ref = dict()
    while len(ref)<24:
        ref[(dice.top, dice.s)] = dice.e
        dice.rotate('NSEW'[random.randint(0,3)])

    for _ in range(input()):
        top, s = map(int, raw_input().split())
        print ref[(top, s)]

Solution (Python):
d=list(map(int,input().split()))
for i in range(int(input())):
	o=list(map(int,input().split()))

	for i in range(4):
		 d[0],d[1],d[4],d[5]=d[1],d[5],d[0],d[4]
		 if d[0]==o[0]:
		 	break
	if d[0]!=o[0]:
		for i in range(4):
			d[0],d[3],d[5],d[2]=d[3],d[5],d[2],d[0]
			if d[0]==o[0]:
				break
	for i in range(4):
		d[1],d[3],d[4],d[2]=d[3],d[4],d[2],d[1]
		if d[1]==o[1]:
			break
	print(d[2])

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

Solution (Python):
import random


class Cube:
    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d

    def rotate(self, dic):
        if dic == "N":
            tmp = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = tmp
        elif dic == "E":
            tmp = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = tmp
        elif dic == "W":
            tmp = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = tmp
        else:
            tmp = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = tmp


def main():
    u, s, e, w, n, d = map(int, input().split())
    cube = Cube(u, s, e, w, n, d)
    q = int(input())
    for i in range(q):
        upper, front = map(int, input().split())
        while True:
            cube.rotate(random.choice("NWES"))
            if upper == cube.u and front == cube.s:
                print(cube.e)
                break


if __name__ == '__main__':
    main()

Solution (Python):



class Dice() :
    rightlist = ((-1,3,1,4,2,-1),
                 (2,-1,5,0,-1,3),
                 (4,0,-1,-1,5,1),
                 (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)]

Solution (Python):
class Dice():
	def __init__(self):
		self.number = [_ for _ in range(6)]
		self.work = [_ for _ in range(6)]

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

	def roll(self,loc):
		for _ in range(6):
			self.work[_] = self.number[_]
		if loc == "E":
			self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
		elif loc == "N":
			self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
		elif loc == "S":
			self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
		elif loc == "W":
			self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
	def get_top(self):
		return self.number[0]
	def get_right(self,n1,n2):
		if(n1 == self.number[0]):
			if(n2 == self.number[1]): print(self.number[2])
			elif(n2 == self.number[2]): print(self.number[4])
			elif(n2 == self.number[3]): print(self.number[1])
			elif(n2 == self.number[4]): print(self.number[3])
		elif(n1 == self.number[1]):
                        if(n2 == self.number[0]): print(self.number[3])
                        elif(n2 == self.number[2]): print(self.number[0])
                        elif(n2 == self.number[3]): print(self.number[5])
                        elif(n2 == self.number[5]): print(self.number[2])
		elif(n1 == self.number[2]):
                        if(n2 == self.number[0]): print(self.number[1])
                        elif(n2 == self.number[1]): print(self.number[5])
                        elif(n2 == self.number[4]): print(self.number[0])
                        elif(n2 == self.number[5]): print(self.number[4])
		elif(n1 == self.number[3]):
                        if(n2 == self.number[0]): print(self.number[4])
                        elif(n2 == self.number[1]): print(self.number[0])
                        elif(n2 == self.number[4]): print(self.number[5])
                        elif(n2 == self.number[5]): print(self.number[1])
		elif(n1 == self.number[4]):
                        if(n2 == self.number[0]): print(self.number[2])
                        elif(n2 == self.number[2]): print(self.number[5])
                        elif(n2 == self.number[3]): print(self.number[0])
                        elif(n2 == self.number[5]): print(self.number[3])
		elif(n1 == self.number[5]):
                        if(n2 == self.number[1]): print(self.number[3])
                        elif(n2 == self.number[2]): print(self.number[1])
                        elif(n2 == self.number[3]): print(self.number[4])
                        elif(n2 == self.number[4]): print(self.number[2])

data = list(map(int,input().split()))
q = int(input())

mydice = Dice()

mydice.setNumber(data[0],data[1],data[2],data[3],data[4],data[5])
for _ in range(q):
	flat = list(map(int,input().split()))
	mydice.get_right(flat[0],flat[1])

Solution (Python):
def roll(l, command):
    '''
    return rolled list

    l : string list
    command: string
    '''
    res = []
    i = -1
    if command =='N':
        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
    if command =='S':
        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
    if command =='E':
        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
    if command =='W':
        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]

    return res

def spin(l):
    '''
    return right sppined list

    l : string list
    '''

    i = -1
    res = [l[i+1], l[i+3], l[i+5], l[i+2], l[i+4], l[i+6]]

    return res

def check_all(upper, front, faces):
    orig_faces = faces[:]

    
    for i in range(6):
        if 1 <= i <= 3:
            faces = roll(faces, "N")
        elif i == 4:
            pass
            faces = orig_faces[:]
            faces = roll(faces, "W")
        elif i == 5:
            faces = orig_faces[:]
            faces = roll(faces, "E")


        
        for _ in range(4): 
            faces = spin(faces)
            if (faces[0] == upper and (faces[1] == front)):
                return faces[2]

if __name__ == "__main__":
    faces = input().split()
    n = int(input())

    for _ in range(n):

        question = list(input().split())
        answer = check_all(question[0], question[1], faces)

        print(answer)

Solution (Python):
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):
        if j % 2 == 0:
            dice.north()
        else:
            dice.west()

        for k in range(4):
            dice.rotate()
            if dice.top() == t and dice.front() == f:
                flag = True
                break
        if flag:
            break
    print(dice.right())

Solution (Python):
def R(dice,U,S):
  def f(x): return str(dice.index(x))
  PAT=["12431","03520","01540","04510","02530","13421"]
  it=f(U)+f(S)
  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(dice,U,S)

Solution (Python):
IDX_TABLE=\
{1:[4,2,3,5],
 2:[1,4,6,3],
 3:[1,2,6,5],
 4:[1,5,6,2],
 5:[4,1,3,6],
 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]]

Solution (Python):
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]

TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM = mask[0]

def set_top(dice, top):
    return [dice[i] for i in mask[top]]

def set_front(dice, front):
    twist = (0, 3, 1, 4, 2, 5)
    while dice[FRONT] != front:
        dice = [dice[i] for i in twist]
    return dice
        
label = input().split()
q = int(input())
for _ in range(q):
    top, front = map(label.index, input().split())
    dice = set_top(mask[0], top)
    dice = set_front(dice, front)
    print(label[dice[RIGHT]])