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):
dice = list(map(int, input().split()))
num = int(input())
for i in range(num):
    a = list(map(int, input().split()))
    if a in [[dice[1],dice[2]],[dice[2],dice[4]],[dice[3],dice[1]],[dice[4],dice[3]]]:
        print(dice[0])
    elif a in [[dice[0],dice[3]],[dice[2],dice[0]],[dice[3],dice[5]],[dice[5],dice[2]]]:
        print(dice[1])
    elif a in [[dice[0],dice[1]],[dice[1],dice[5]],[dice[4],dice[0]],[dice[5],dice[4]]]:
        print(dice[2])
    elif a in [[dice[0],dice[4]],[dice[1],dice[0]],[dice[4],dice[5]],[dice[5],dice[1]]]:
        print(dice[3])
    elif a in [[dice[0],dice[2]],[dice[2],dice[5]],[dice[3],dice[0]],[dice[5],dice[3]]]:
        print(dice[4])
    else:
        print(dice[5])

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

    def roll(self, axis, count=1):
        while count < 0:
            count += 4
        if axis == "X":
            for _ in range(count):
                self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif axis == "Y":
            for _ in range(count):
                self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif axis == "Z":
            for _ in range(count):
                self.front, self.left, self.back, self.right = self.right, self.front, self.left, self.back
        elif axis == "N":
            self.roll("X", 1)
        elif axis == "W":
            self.roll("Y", -1)
        elif axis == "S":
            self.roll("X", -1)
        elif axis == "E":
            self.roll("Y", 1)


def solve(d, top, front):
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Z")
    d.roll("X")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Y")
    d.roll("X")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Z")
    d.roll("X")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("Y")
    d.roll("X")
    d.roll("Y")
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("X")
    d.roll("Y", 2)
    for _ in range(4):
        if d.top == top and d.front == front:
            return d.right
        d.roll("X")


labels = [int(c) for c in input().split()]
d = Dice(labels)
q = int(input())
for _ in range(q):
    top, front = map(int, input().split())
    print(solve(d, top, front))

Solution (Python):
class Dice():
  def __init__ (self):
    
    self.position = [0,0,0,0,0,0]
    self.search_result = []
  
  def setNumber (self, num):
    for i,x in enumerate(num):
      self.position[i] = x
    
      
  def roll(self, roll):
    for i in range(len(roll)):
      s = roll[i:i+1]
      p = self.position
      if s == 'E':
        self.setNumber([p[3], p[1], p[0], p[5], p[4], p[2]])
      elif s == 'W':
        self.setNumber([p[2], p[1], p[5], p[0], p[4], p[3]])
      elif s == 'S':
        self.setNumber([p[4], p[0], p[2], p[3], p[5], p[1]])
      elif s == 'N':
        self.setNumber([p[1], p[5], p[2], p[3], p[0], p[4]])

  def printTop(self):
    print(self.position[0])

  def searchRight(self, a, b):
    i1 = self.position.index(a)
    i2 = self.position.index(b)
    
    
    
    if (i1 == 1 and i2 == 2) or (i1 == 2 and i2 == 4) or (i1 == 4 and i2 == 3) or (i1 == 3 and i2 == 1):
      self.search_result.append(self.position[0])
    
    elif (i1 == 0 and i2 == 3) or (i1 == 3 and i2 == 5) or (i1 == 5 and i2 == 2) or (i1 == 2 and i2 == 0):
      self.search_result.append(self.position[1])
    
    elif (i1 == 0 and i2 == 1) or (i1 == 1 and i2 == 5) or (i1 == 5 and i2 == 4) or (i1 == 4 and i2 == 0):
      self.search_result.append(self.position[2])
    
    elif (i1 == 1 and i2 == 0) or (i1 == 0 and i2 == 4) or (i1 == 4 and i2 == 5) or (i1 == 5 and i2 == 1):
      self.search_result.append(self.position[3])
    
    elif (i1 == 0 and i2 == 2) or (i1 == 2 and i2 == 5) or (i1 == 5 and i2 == 3) or (i1 == 3 and i2 == 0):
      self.search_result.append(self.position[4])
    
    elif (i1 == 2 and i2 == 1) or (i1 == 1 and i2 == 3) or (i1 == 3 and i2 == 4) or (i1 == 4 and i2 == 2):
      self.search_result.append(self.position[5])
    
  def printResult(self):
    for i in self.search_result:
      print (i)


d = Dice()

n = list(int(x) for x in input().split())
d.setNumber(n)

q = int(input())
for i in range(q):
  a,b = (int(x) for x in input().split())
  d.searchRight(a,b)

d.printResult()

Solution (Python):
class Dice:
    def __init__(self,my_label):
        self.top,self.front,self.right,self.left,self.back,self.bottom = [int(x) for x in my_label]

    def Roll(self,i):
        if i == 0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.right, self.front, self.bottom, self.top, self.back, self.left
        
        if i == 1:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.left, self.front, self.top, self.bottom, self.back, self.right
        
        if i == 2:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.back, self.top, self.right, self.left, self.bottom, self.front
            
        if i == 3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.front, self.bottom, self.right, self.left, self.top, self.back

    def Open(self):
        print(self.top)


def CheckData(data,top,front):
    for i in range(len(data)):
        if(data[i][0] == top and data[i][1] == front):
            print(data[i][2])
            break

def MakeData(dice):
    num_data = 4 * len(my_label)-1
    
    dataset = list()
    data = [dice.top, dice.front, dice.right]

    dataset.append(data)
    
    isOnly = True
    
    while 0 < num_data:
        data = [dice.top, dice.front, dice.right]

        isOnly = True
        for i in range (len(dataset)):
            if(data == dataset[i]):
                isOnly = False
                break
        if isOnly == True:
            dataset.append(data)
            dataset.sort()
            num_data -= 1
        
        dice.Roll(int(random.random() * 4))
        
    
        
    return dataset


import random
my_label = [int(x) for x in input().split(" ")]
dice = Dice(my_label)
data = MakeData(dice)


q = int(input())
while q > 0:
    n_top,n_front = [int(x) for x in input().split(" ")]
    
    CheckData(data,n_top,n_front)
    
    q -= 1

Solution (Python):
import random

class dice:
    def __init__(self, t, S, E):
        self.dice = list(map(int, input().split()))
        self.t = t
        self.S = S
        self.E = E
        self.now_dice()
    
    def roll(self, order):
        if order == 'E':
            self.t, self.E = self.W, self.t
        elif order == 'N':
            self.t, self.S = self.S, self.g
        elif order == 'S':
            self.t, self.S = self.N, self.t
        elif order == 'W':
            self.t, self.E = self.E, self.g
        self.now_dice()
    
    def now_dice(self):
        self.N = 7 - self.S
        self.g = 7 - self.t
        self.W = 7 - self.E
        self.now = [self.t, self.S, self.E, self.N, self.W, self.g]
        return self.now

if __name__ == '__main__':
    dice = dice(1, 2, 3)
    x = int(input())
    for _ in range(x):
        a, b = map(int, input().split())
        while 1:
            direc = ['N', 'E', 'W']
            random.shuffle(direc)
            dice.roll(direc[0])
            if dice.dice[dice.t-1] == a and dice.dice[dice.S-1] == b:
                print(dice.dice[dice.E-1])
                break

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):
def sgn(a, b):
    return int(a*b/abs(a*b))

numbers = list(map(int, input().split()))
numbers_dict = {1:numbers[0], 2:numbers[1], 3:numbers[2], -3:numbers[3], -2:numbers[4], -1:numbers[5]}
numbers_ver_dict = {numbers[0]:1, numbers[1]:2,numbers[2]:3,numbers[3]:-3, numbers[4]:-2,numbers[5]:-1}
n = int(input())
for _ in range(n):
    a, b = map(int, input().split())
    var_a = numbers_ver_dict[a]
    var_b = numbers_ver_dict[b]
    if abs(var_a) == 1:
        if abs(var_b) == 2:
            print(numbers_dict[sgn(var_a,var_b)*3])
        else:
            print(numbers_dict[-sgn(var_a,var_b)*2])
    elif abs(var_a) == 2:
        if abs(var_b) == 1:
            print(numbers_dict[-sgn(var_a, var_b)*3])
        else:
            print(numbers_dict[sgn(var_a,var_b)])
    else:
        if abs(var_b) == 1:
            print(numbers_dict[sgn(var_a, var_b)*2])
        else:
            print(numbers_dict[-sgn(var_a,var_b)])

Solution (Python):
buff = "NNNNWNNNWNNNENNNENNNWNNN"

class Dice:
        num =[ -1 for x in range(6) ]
        def roll(self, d):
                if   d == "N":
                        b = self.num[0]
                        self.num[0] = self.num[1]
                        self.num[1] = self.num[5]
                        self.num[5] = self.num[4]
                        self.num[4] = b
                elif d == "S":
                        b = self.num[0]
                        self.num[0] = self.num[4]
                        self.num[4] = self.num[5]
                        self.num[5] = self.num[1]
                        self.num[1] = b
                elif d == "W":
                        b = self.num[3]
                        self.num[3] = self.num[0]
                        self.num[0] = self.num[2]
                        self.num[2] = self.num[5]
                        self.num[5] = b
                elif d == "E":
                        b = self.num[3]
                        self.num[3] = self.num[5]
                        self.num[5] = self.num[2]
                        self.num[2] = self.num[0]
                        self.num[0] = b
        
        def __init__(self, lst):
                self.num = lst
        
        def print_num(self, m):
                
                return self.num[m]

lst = [ int(i) for i in input().split() ]
q = int(input())

qst = []
for p in range(q):
        qst.append([ int(i) for i in input().split() ])


dice = Dice(lst)

for c in qst:
        for d in buff:
                dice.roll(d)
                if dice.print_num(0) == c[0] and dice.print_num(1) == c[1]:
                        print(dice.print_num(2))

Solution (Python):
d=input().split()
mawari=[[1,2,4,3,1],[5,2,0,3,5],[5,4,0,1,5],[5,1,0,4,5],[5,3,0,2,5],[4,2,1,3,4]]

for _ in range(int(input())):
    a,b=[d.index(i) for i in input().split()]
    n=mawari[a]
    print(d[n[n.index(b)+1]])

Solution (Python):
l=input().split()
for _ in[0]*int(input()):
	t,f=[l.index(s)for s in input().split()]
	g=lambda i:i if t<3else 5-i
	print(l[g(int(['_2413_','3_05_2','15__04'][g(t)][f]))])

Solution (Python):
class Dice:
    def __init__(self, labels):
        self.labels = labels
        
    def __str__(self):
        return str(self.labels[0])
    
    def roll_south(self):
        self.labels[0], self.labels[1], self.labels[5], self.labels[4] = self.labels[4], self.labels[0], self.labels[1], self.labels[5]
            
    def roll_east(self):
        self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5]
    
    def roll_west(self):
        self.labels[0], self.labels[3], self.labels[5], self.labels[2] = self.labels[2], self.labels[0], self.labels[3], self.labels[5]
    
    def roll_north(self):
        self.labels[0], self.labels[4], self.labels[5], self.labels[1] = self.labels[1], self.labels[0], self.labels[4], self.labels[5]
        
    def get_faces(self):
        return self.labels
        
def main():
    labels = list(map(int, input().split()))
    d = Dice(labels)
    n = int(input())
    for i in range(n):
        faces = list(map(int, input().split()))
        ind0 = labels.index(faces[0])
        ind1 = labels.index(faces[1])
        if ind0 == 1:
            d.roll_north()
        elif ind0 == 4:
            d.roll_south()
        else:
            while d.get_faces()[0] != faces[0]:
                d.roll_east()
        while d.get_faces()[1] != faces[1]:
            d.roll_east()
            d.roll_south()
            d.roll_west()
        print(d.get_faces()[2])
        
main()

Solution (Python):
import random

class Dice:
    def __init__(self):
        self.u = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.d = 6
        self.dic = {"W":0, "S":1, "E":2, "N":3}

    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
        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


ans = []

u1, s1, e1, w1, n1, d1 = map(int, input().split())
dice1 = Dice(u1, s1, e1, w1, n1, d1)
q = int(input())

for i in range(q):
    a, b = map(int, input().split())

    while True:
        dice1.rot(random.randint(0,3))
        if dice1.u == a and dice1.s == b:
            ans.append(dice1.e)
            break

for i in range(q):
    print(ans[i])

Solution (Python):
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 set(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 kaiten(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
 
        if loc == 'E':
            self.set(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.set(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.set(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.set(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
 
 
    def tansaku(self,top_num,front_num):
 
        self.save = [i for i in range(6)]
        for i in range(len(self.number)):
            self.save[i] = self.number[i]
 
        ret = -1;
 
        for i in range(len(self.order)):
            self.kaiten(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[i]
 
        return ret;
 
 
 
 
dice = Dice()
table = list(map(int,input().split()))
dice.set(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.tansaku(top_num, front_num)))

Solution (Python):
class Dice():

    patterns = {"N":[1,5,2,3,0,4],"S":[4,0,2,3,5,1],"W":[2,1,5,0,4,3],"E":[3,1,0,5,4,2]}

    def __init__(self):
        self.number = [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,command,int):
        for i in command:
            self.number = [self.number[j] for j in self.patterns[i]]
        return self.number[int]


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

command1 = ["S","S","S","S","E","E","E"] 
command2 = ["S","E","N","S","E","N","S","E","N","S","E","N"] 


for i in range(q_num): 
    right = nums[2]
    top,front = map(int,input().split())
    for j in command1:
        if top == dice.roll(j,0):
            for k in command2:
                if front == dice.roll(k,1):
                    right = dice.number[2]
    print(right)

Solution (Python):
a = list(map(int, input().split()))
s = ['402351', '152304', '310542', '215043']   
for _ in range(int(input())):
    b, c = map(int, input().split())
    t = []
    t.append(a)
    i = 0; j = 0
    while True:
        if t[i][0] == b and t[i][1] == c:
            print(t[i][2])
            break
        if i == len(t)-1: 
            for h in range(len(s)):
                t.append([ t[j][int(k)] for k in list(s[h]) ])
            j+=1
        i+=1

Solution (Python):
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]

p = [ int(n) for n in input().split()]

q = int(input())
qq = []
for i in range(0, q):
    qq.append([int(n) for n in input().split()])


for (a, b) in qq:
    
    dice = Dice(p)

    
    for _ in range(0, 4):
        if dice.num(1) == a:
            break;
        dice.roll('x')
    for _ in range(0, 4):
        if dice.num(1) == a:
            break;
        dice.roll('y')
   
    for _ in range(0, 4):
        if dice.num(2) == b:
            break;
        dice.roll('z')
    print(dice.num(3))

Solution (Python):
class Dice():
    def __init__(self, ls = [0 for i in range(6)]):
        self.ls = ls
        
    def now(self):
        return ls
    
    def S(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[4]
        n_ls[1] = ls[0]
        n_ls[2] = ls[2]
        n_ls[3] = ls[3]
        n_ls[4] = ls[5]
        n_ls[5] = ls[1]
        
        return Dice(n_ls)
    
    def N(self):
        ls = self.S().S().S().ls
        return Dice(ls)
        
    def E(self):
        ls = self.ls
        n_ls = [0 for i in range(6)]
        n_ls[0] = ls[3]
        n_ls[1] = ls[1]
        n_ls[2] = ls[0]
        n_ls[3] = ls[5]
        n_ls[4] = ls[4]
        n_ls[5] = ls[2]
        return Dice(n_ls)
    
    
    def W(self):
        ls = self.E().E().E().ls
        return Dice(ls)
        
        
        
    def R_rot(self):
        return self.E().S().W()
        
    def rot(self, num):
        for _ in range(num):
            self = self.R_rot()
        return self
    
ls = list(map(int, input().split()))
q = int(input())

a = Dice(ls)

me = [a, a.N(), a.W(), a.E(), a.S(), a.S().S()]


for _ in range(q):
    n, m = map(int, input().split())



    B= Dice()
    for i in me:
        if i.ls[0] == n:
            B = i

    Rot = [B.rot(i) for i in range(4)]
    for i in Rot:
        if i.ls[1] == m:
            print(i.ls[2])

Solution (Python):
n = list(map(int,input().split()))
q = int(input())
l = [[3,5,2,4],[4,1,6,3],[2,6,1,5],[5,1,6,2],[3,6,1,4],[4,2,5,3]]
for i in range(q):
    a, b = map(int,input().split())
    for j in range(6):
        if a == n[j]:
            c = j
        if b == n[j]:
            d = j
    e = d
    if c < d:
        e -= 1
    if c + d > 5:
        e -= 1
    print(n[l[c][e]-1])

Solution (Python):
import random
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  
    def printRight(self):
        print(self.surface[2])

surfaceNum = [int(i) for i in input().split()]
commandNum = int(input())
rollCommandList = ["E", "W", "S", "N"]
Dice = Dice(surfaceNum)
rightNum = [0]*commandNum

for i in range(commandNum):
    topFront = [int(data) for data in input().split()]
    while Dice.surface[0] != topFront[0] or Dice.surface[1] != topFront[1]:
        rollCommand = random.choice(rollCommandList)
        if rollCommand == "E":
            Dice.east()
        if rollCommand == "W":
            Dice.west()
        if rollCommand == "S":
            Dice.south()
        if rollCommand == "N":
            Dice.north()
    rightNum[i] = Dice.surface[2]
for i in range(commandNum):
    print(rightNum[i])

Solution (Python):
dice = [int(_) for _ in input().split()]
num = int(input())
dire = {"N": [2,6,3,4,1,5],"S":[5,1,3,4,6,2],
      "E":[4,2,1,6,5,3],"W":[3,2,6,1,5,4]}
z_dire = [1,4,2,5,3,6]

for i in range(num):
    dis = [int(_) for _ in input().split()]
    count = 0
    while dice[0] != dis[0]:
        em = dice[:]
        for j in range(len(dice)):
            if count % 2 == 0:
                em[j] = dice[dire["N"][j]-1]
            else:
                em[j] = dice[dire["E"][j]-1]
        else:
            del dice[:]
            dice = em[:]
        count += 1

    while dice[1] != dis[1]:
        em = dice[:]
        for j in range(len(dice)):
            em[j] = dice[z_dire[j]-1]
        else:
            del dice[:]
            dice = em[:]
    print(dice[2])

Solution (Python):
class Dice:
    def __init__(self, p):
        self.y = [p[0], p[1], p[5], p[4]]
        self.x = [p[0], p[2], p[5], p[3]]
        self.z = [p[1], p[2], p[4], p[3]]
    def roll(self, c):
        if c == 'y':
            self.y.append(self.y.pop(0))
            self.x[0] = self.y[0]
            self.x[2] = self.y[2]
            self.z[0] = self.y[1]
            self.z[2] = self.y[3]
        elif c == 'x':
            self.x.append(self.x.pop(0))
            self.y[0] = self.x[0]
            self.y[2] = self.x[2]
            self.z[1] = self.x[1]
            self.z[3] = self.x[3]
        elif c == 'z':
            self.z.append(self.z.pop(0))
            self.x[1] = self.z[1]
            self.x[3] = self.z[3]
            self.y[1] = self.z[0]
            self.y[3] = self.z[2]
    def num(self, n):
        n = n - 1;
        pos_y = [0, 1, 5, 4]
        pos_x = [0, 2, 5, 3]
        if n in pos_y:
            return self.y[pos_y.index(n)]
        else:
            return self.x[pos_x.index(n)]

p = [ int(n) for n in input().split()]
q = int(input())
qq = []
for i in range(0, q):
    qq.append([int(n) for n in input().split()])

for (a, b) in qq:
    dice = Dice(p)
    for _ in range(0, 4):
        if dice.num(1) == a:
            break;
        dice.roll('x')
    for _ in range(0, 4):
        if dice.num(1) == a:
            break;
        dice.roll('y')
    for _ in range(0, 4):
        if dice.num(2) == b:
            break;
        dice.roll('z')
    print(dice.num(3))

Solution (Python):
num = list(map(int, input().split()))
q = int(input())
anslist = []

for i in range(q):
    top, front = map(int, input().split())
    if top == num[0]:
        order = ''
    elif top == num[1]:
        order = 'N'
    elif top == num[2]:
        order = 'W'
    elif top == num[3]:
        order = 'E'
    elif top == num[4]:
        order = 'S'
    elif top == num[5]:
        order = 'NN'


    for o in order:
        if o == 'N':
            next = '263415'
        elif o == 'W':
            next = '326154'
        elif o == 'S':
            next = '513462'
        else:
            next = '421653'

        temp = [0]*6
        for i,n in enumerate(next):
            temp[i] = num[int(n)-1]

        num = temp

    if front == num[1]:
        ans = num[2]
    elif front == num[2]:
        ans = num[4]
    elif front == num[3]:
        ans = num[1]
    elif front == num[4]:
        ans = num[3]

    anslist.append(ans)

for ans in anslist:
    print(ans)

Solution (Python):
dice_ = [int(i) for i in input().split()]
dice = {
    (0,0,1):dice_[0],
    (0,-1,0):dice_[1],
    (1,0,0):dice_[2],
    (-1,0,0):dice_[3],
    (0,1,0):dice_[4],
    (0,0,-1):dice_[5]
}
rdice = {
    dice_[0]:(0,0,1),
    dice_[1]:(0,-1,0),
    dice_[2]:(1,0,0),
    dice_[3]:(-1,0,0),
    dice_[4]:(0,1,0),
    dice_[5]:(0,0,-1)
}

def cross(a,b):
	return(a[1]*b[2]-a[2]*b[1], a[2]*b[0]-a[0]*b[2], a[0]*b[1]-a[1]*b[0])
n = int(input())
for _ in range(n):
	a_,b_ = [int(i) for i in input().split()]
	a = rdice[a_]
	b = rdice[b_]
	print(dice[cross(a,b)])

Solution (Python):

class Dice:
    
    def __init__(self):
        self.data = {"bottom":5, "west": 3, "north" : 4,
                "east": 2, "south" : 1,"top" : 0}
    
    def moveOne(self, direction):
        if direction == "W":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["west"]
            self.data["west"] = self.data["top"]
            self.data["top"] = self.data["east"]
            self.data["east"] = temp
        elif direction == "E":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["east"]
            self.data["east"] = self.data["top"]
            self.data["top"] = self.data["west"]
            self.data["west"] = temp
        elif direction == "N":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["north"]
            self.data["north"] = self.data["top"]
            self.data["top"] = self.data["south"]
            self.data["south"] = temp
        elif direction == "S":
            temp = self.data["bottom"]
            self.data["bottom"] = self.data["south"]
            self.data["south"] = self.data["top"]
            self.data["top"] = self.data["north"]
            self.data["north"] = temp

    def movePart(self, directions):
        for direction in directions:
            self.moveOne(direction)
            
    def setDiceII(self, a, b):
        if self.data["east"] == a:
            self.moveOne("W")
        elif self.data["north"] == a:
            self.moveOne("S")
        elif self.data["west"] == a:
            self.moveOne("E")
        elif self.data["south"] == a:
            self.moveOne("N")
        elif self.data["bottom"] == a:
            self.movePart("WW")

        if self.data["north"] == b:
            self.rotateRight()
            self.rotateRight()
        elif self.data["east"] == b:
            self.rotateRight()
        elif self.data["west"] == b:
            self.rotateLeft()
            
        
    
    def rotateRight(self):
        temp = self.data["east"]
        self.data["east"] = self.data["north"]
        self.data["north"] = self.data["west"]
        self.data["west"] = self.data["south"]
        self.data["south"] = temp
    
    def rotateLeft(self):
        temp = self.data["west"]
        self.data["west"] = self.data["north"]
        self.data["north"] = self.data["east"]
        self.data["east"] = self.data["south"]
        self.data["south"] = temp
      
    def getSurface(self):
        return self.data["top"]
    
    def getEast(self):
        return self.data["east"]
        
    def printDice(self):
        print(self.data["north"])
        print(str(self.data["west"]) + " " + str(self.data["bottom"]) + " " + str(self.data["east"]) )
        print(self.data["south"])
        print(self.data["top"])


num = list(map(int,input().rstrip().split()))
n = int(input().rstrip())
dice = Dice()
for i in range(n):
    top, south = map(int,input().rstrip().split())
    dice.setDiceII(num.index(top),num.index(south))
    print(num[dice.getEast()])