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):
n=list(map(int,input().split()))
p=['2354','3146','2651','1562','1364','2453']
for _ in range(int(input())):
    t,m=map(int,input().split())
    t=n.index(t)
    m=str(n.index(m)+1)
    print(n[int(p[t][(p[t].index(m)+1)%4])-1])

Solution (Python):
class Dice :
    def __init__(self, pane):
        self.pane = pane
    
    def roll_W(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[2]
        self.pane[2] = self.pane[5]
        self.pane[5] = self.pane[3]
        self.pane[3] = temp

    def roll_S(self):
        temp = self.pane[0]
        self.pane[0] = self.pane[4]
        self.pane[4] = self.pane[5]
        self.pane[5] = self.pane[1]
        self.pane[1] = temp
    
dice = Dice(input().split())
n = int(input())
result = []

for i in range(0, n):
    str_in = input().split()
    t = str_in[0]
    f = str_in[1]
    while True:
        if (dice.pane[0] == f or dice.pane[4] == f):
            dice.roll_S()
        if (dice.pane[0] == t and dice.pane[1] == f):
            break
        dice.roll_W()

    result.append(dice.pane[2])

for i in result:
    print(i)

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'

    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 i in range(6):
            self.work[i] = self.number[i]

        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 query(self,top_num,front_num):

        self.save_data = [i for i in range(6)]
        
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

        
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]

        return ret;




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

num_query = int(input())
for loop in range(num_query):
    top_num,front_num = map(int,input().split())
    print("%d"%(dice.query(top_num, front_num)))

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

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

for _ in range(n):
    t, f = map(int, input().split())
    for j in "EEENEEENEEESEEESEEENEEEN":
        if d.pip[0] == t and d.pip[1] == f:
            break
        d.move(j)
    print(d.pip[2])

Solution (Python):
class Dice:
  def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6):
    self.d = {"TOP":top, "FRONT":front, "LEFT":left, "RIGHT":right, "BACK":back, "BOTTOM":bottom}

  def roll_x(self):
    self._roll("TOP", "FRONT", "BOTTOM", "BACK")
  
  def roll_y(self):
    self._roll("FRONT", "LEFT", "BACK", "RIGHT")
  
  def roll_z(self):
    self._roll("TOP", "LEFT", "BOTTOM", "RIGHT")
  
  def _roll(self, a, b, c, d):
    self.d[a], self.d[b], self.d[c], self.d[d] = \
    self.d[b], self.d[c], self.d[d], self.d[a]

  def all_rolls(self):
      ret = []
      for i in range(6):
        if i%2:
          self.roll_x()
        else:
          self.roll_y()
        for j in range(4):
          self.roll_z()
          t = self.d.copy()
          ret.append(t)
      return ret

d = list(map(int, input().split()))
dd = Dice(d[0], d[1], d[3], d[2], d[4], d[5])
l = dd.all_rolls()
q = int(input())
for i in range(q):
  t, f = list(map(int, input().split()))
  for ele in l:
    if ele["TOP"]==t and ele["FRONT"]==f:
      print(ele["RIGHT"])
      break

Solution (Python):
class Dice:
	
	def __init__(self, nums):
		self.cU = nums[0]
		self.cS = nums[1]
		self.cE = nums[2]
		self.cW = nums[3]
		self.cN = nums[4]
		self.cD = nums[5]
	def goN(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pS,pD,pU,pN
	def goE(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pW,pU,pD,pE
	def goW(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pE,pD,pU,pW
	def goS(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pN,pU,pD,pS
	def toU(self, num):
		if self.cD == num:
			for _ in range(2): self.goN()
		elif self.cN == num: self.goS()
		elif self.cE == num: self.goW()
		elif self.cW == num: self.goE()
		elif self.cS == num: self.goN()
	def right(self, num):
		if self.cN == num: return self.cW
		elif self.cE == num: return self.cN
		elif self.cW == num: return self.cS
		elif self.cS == num: return self.cE
		else: raise 
nums = [int(i) for i in input().split(' ')]
di = Dice(nums)
q = int(input())
for _ in range(q):
	u,f = map(int, tuple(input().split(' ')))
	di.toU(u)
	print(di.right(f))