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):
import random

class dice:
  def __init__(self,dice_number_list):
    self.top,self.front,self.right,self.left,self.rear,self.bottom = dice_number_list
    
  def roll(self,op):
    if   op=='N': 
      self.top, self.front, self.bottom, self.rear = \
      self.front, self.bottom, self.rear , self.top
    elif op=='E':
      self.top, self.left , self.bottom, self.right = \
      self.left , self.bottom, self.right, self.top
    elif op=='W': 
      self.top, self.right, self.bottom, self.left = \
      self.right, self.bottom, self.left , self.top
    elif op=='S': 
      self.top, self.rear , self.bottom, self.front = \
      self.rear , self.bottom, self.front, self.top
           
  def print_top(self):
    print(self.top)
  def print_right(self):
    print(self.right)
    
  def get_label(self):
    return([self.top, self.front, self.right, self.left, self.rear, self.bottom])
    
dice_number_list = list(map(int,input().split()))
d = dice(dice_number_list)


all_dice_number_list=[]
for i in range(10000):
  d.roll(random.choice("NEWS"))
  if d.get_label() not in all_dice_number_list:
    all_dice_number_list.append(d.get_label())
  if len(all_dice_number_list) == 24:
    break



n=int(input())
for i in range(n):
  top,front = list(map(int,input().split()))
  for dice_list in all_dice_number_list:
    
    if dice_list[0]==top and dice_list[1]==front:
      print(dice_list[2])

Solution (Python):

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

Solution (Python):
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):
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,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]

label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)

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

Solution (Python):
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):
s = list(map(int,input().split()))
q = int(input())

while q > 0:
  top, front = map(int,input().split())
  
  if s.index(top) == 1:
    ORDER = 'N'
  elif s.index(top) == 2:
    ORDER = 'W'
  elif s.index(top) == 3:
    ORDER = 'E'
  elif s.index(top) == 4:
    ORDER = 'S'
  elif s.index(top) == 5:
    ORDER = 'SS'
  else:
    ORDER = 'R'
  
  order = list(ORDER)
  
  for i in order:
    if i == 'E':
      s[0], s[3] = s[3], s[0]
      s[3], s[5] = s[5], s[3]
      s[5], s[2] = s[2], s[5]
    elif i == 'N':
      s[0], s[1] = s[1], s[0]
      s[1], s[5] = s[5], s[1]
      s[5], s[4] = s[4], s[5]
    elif i == 'S':
      s[0], s[4] = s[4], s[0]
      s[4], s[5] = s[5], s[4]
      s[5], s[1] = s[1], s[5] 
    elif i == 'W':
      s[0], s[2] = s[2], s[0]
      s[2], s[5] = s[5], s[2]
      s[5], s[3] = s[3], s[5]
    else:
      pass
    
  if s.index(front) == 1:
    print(s[2])
  if s.index(front) == 2:  
    print(s[4])
  if s.index(front) == 3:  
    print(s[1])
  if s.index(front) == 4:
    print(s[3])
    
  q = q-1

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

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

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

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

Solution (Python):
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):
a,b,c,d,e,f = map(int,input().split())

num = int(input())

def dice1(x):
  if x == b:
    return c
  elif x == c:
    return e
  elif x == d:
    return b
  else:
    return d
  
def dice2(x):
  if x == a:
    return d
  elif x == c:
    return a
  elif x == d:
    return f
  else:
    return c
  
def dice3(x):
  if x == a:
    return b
  elif x == b:
    return f
  elif x == e:
    return a
  else:
    return e

def dice4(x):
  if x == a:
    return e
  elif x == b:
    return a
  elif x == e:
    return f
  else:
    return b

def dice5(x):
  if x == a:
    return c
  elif x == c:
    return f
  elif x == d:
    return a
  else:
    return d
  
def dice6(x):
  if x == b:
    return d
  elif x == c:
    return b
  elif x == d:
    return e
  else:
    return c
  
for i in range(num):
  j,k=map(int,input().split())
  if j == a:
    print(dice1(k))
  elif j == b:
    print(dice2(k))
  elif j == c:
    print(dice3(k))
  elif j == d:
    print(dice4(k))
  elif j == e:
    print(dice5(k))
  else:
    print(dice6(k))

Solution (Python):
class Dice:
    
    def __init__(self, n0, n1, n2, n3, n4, n5):
        self.faces = [n0, n1, n2, n3, n4, n5]

    def move(self, op):
        tmp = self.faces[0]
        if op == 'E':
            self.faces[0] = self.faces[3]
            self.faces[3] = self.faces[5]
            self.faces[5] = self.faces[2]
            self.faces[2] = tmp
        elif op == 'N':
            self.faces[0] = self.faces[1]
            self.faces[1] = self.faces[5]
            self.faces[5] = self.faces[4]
            self.faces[4] = tmp
        elif op == 'S':
            self.faces[0] = self.faces[4]
            self.faces[4] = self.faces[5]
            self.faces[5] = self.faces[1]
            self.faces[1] = tmp
        elif op == 'W':
            self.faces[0] = self.faces[2]
            self.faces[2] = self.faces[5]
            self.faces[5] = self.faces[3]
            self.faces[3] = tmp

    def spin_horizontally(self):
        tmp = self.faces[1]
        self.faces[1] = self.faces[2]
        self.faces[2] = self.faces[4]
        self.faces[4] = self.faces[3]
        self.faces[3] = tmp

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

    def front(self):
        return self.faces[1]

    def right(self):
        return self.faces[2]

n = list(map(int, input().split()))
dice = Dice(n[0], n[1], n[2], n[3], n[4], n[5])
q = int(input())
for _ in range(q):
    t, f = map(int, input().split())

    for i in range(5):
        if dice.top() == t:
            break
        if i % 2 == 0:
            dice.move('S')
        else:
            dice.move('E')

    for i in range(3):
        if dice.front() == f:
            break
        dice.spin_horizontally()

    print(dice.right())

Solution (Python):

start = [0,1,2,4,3,5]
s = []

def N():
    start[0],start[1],start[3],start[5] = \
    start[1],start[5],start[0],start[3]
    
def S():
    start[0],start[1],start[3],start[5] = \
    start[3],start[0],start[5],start[1]
    
def W():
    start[0],start[2],start[4],start[5] = \
    start[2],start[5],start[0],start[4]

def E():
    start[0],start[2],start[4],start[5] = \
    start[4],start[0],start[5],start[2]    



def roll():
    start[1],start[2],start[3],start[4] = \
    start[4],start[1],start[2],start[3]          

def get_top():
    return s[start[0]]

def get_zhengMian():
    return s[start[1]]

def get_right():
    return s[start[2]]

def get_left():
    return s[start[4]]

if __name__=='__main__':
    s = list(map(int,input().split()))
    num = int(input())
    for i in range(num):
        a,b = map(int,input().split())
        if a!=get_top():
            right =get_right()
            left = get_left()
            top = get_top()
            if(a==right):
                W()
            elif a==left:
                E()
            while a!=top:
                S()
                top = get_top()
        zhengmian = get_zhengMian()
        right = get_right()
        if b!=zhengmian:
            while b!=zhengmian:
                roll()
                zhengmian = get_zhengMian()
        print(get_right())

Solution (Python):
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
     
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}
 
    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]
 
        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else :
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c
 
import random
u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    while True:
        dice.rot(random.randint(0,3))
        if(dice.u==a and dice.s==b):
            print(dice.e)
            break

Solution (Python):
d = list(map(int, input().split()))
q = int(input())
for i in range(q):
    right = 0
    top, front = map(int, input().split())

    if top == d[0]:
        if front == d[1]:
            print(d[2])
        elif front == d[2]:
            print(d[4])
        elif front == d[3]:
            print(d[1])
        elif front == d[4]:
            print(d[3])
    elif top == d[1]:
        if front == d[0]:
            print(d[3])
        elif front == d[2]:
            print(d[0])
        elif front == d[3]:
            print(d[5])
        elif front == d[5]:
            print(d[2])
    elif top == d[2]:
        if front == d[0]:
            print(d[1])
        elif front == d[1]:
            print(d[5])
        elif front == d[4]:
            print(d[0])
        elif front == d[5]:
            print(d[4])
    elif top == d[3]:
        if front == d[0]:
            print(d[4])
        elif front == d[1]:
            print(d[0])
        elif front == d[4]:
            print(d[5])
        elif front == d[5]:
            print(d[1])
    elif top == d[4]:
        if front == d[0]:
            print(d[2])
        elif front == d[2]:
            print(d[5])
        elif front == d[3]:
            print(d[0])
        elif front == d[5]:
            print(d[3])
    elif top == d[5]:
        if front == d[1]:
            print(d[3])
        elif front == d[2]:
            print(d[1])
        elif front == d[3]:
            print(d[4])
        elif front == d[4]:
            print(d[2])
    else:
        break

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








def zenten():
	dai0 = dai[0]
	dai[0] = dai[4]
	dai[4] = dai[5]
	dai[5] = dai[1]
	dai[1] = dai0

def tokei():
	dai1 = dai[1]
	dai[1] = dai[2]
	dai[2] = dai[4]
	dai[4] = dai[3]
	dai[3] = dai1
	
n=int(input())

def check():
	for j in range(4):
		if a == dai[0] and b == dai[1]:
			print(dai[2])
			return True
		tokei()
	return False

for m in range(n):
	a,b=map(int,input().split())
	
	
	if not check():
		zenten()
		if not check(): 
			zenten()
			if not check(): 
				zenten()
				if not check(): 
					tokei()
					zenten()
					if not check(): 
						zenten()
						zenten()
						if not check(): 
							print("ERROR")

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

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


class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]  
        self.work = [i for i 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 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 roll_2(self, top, front):  
        directions = ["N", "E", "W", "S"]
        while True:
            i = random.randint(0, 3)
            self.roll(directions[i])
            if top == self.number[0] and front == self.number[1]:
                break
        return self.number[2]

    def get_Top(self):
        return self.number[0]

num = list(map(int, input().split()))
dice = Dice()
dice.setNumber(num[0], num[1], num[2], num[3], num[4], num[5])
q = int(input())  
for i in range(q):
    top, front = map(int, input().split())
    print(dice.roll_2(top, front))

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
   
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
   
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
   
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
    
label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
   
label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)

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

Solution (Python):
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice
 
def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice
 
dice = list(map(int, input().split()))
q = int(input())
for i in range(q):
  up, front = map(int, input().split())
  cnt = 0
  while (dice[0] != up and cnt <= 3):
    dice = move(dice, "E")
    cnt += 1
  while dice[0] != up:
    dice = move(dice, "N")
  while dice[1] != front:
    dice = roll(dice)
  print(dice[2])

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
   
label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
   
label = list(map(int,input().split()))
d = dice(label)
q = int(input())
for _ in range(q):
    top_front = [int(x) for x in input().split()]
    for op in 'EEENEEENEEESEEESEEENEEEN':
        if d.get_label()[:2] == top_front:
            d.print_right()
            break
        d.roll(op)