output_description: For each question, print the integer on the right side face.
input_description: 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.
attempt: class Dice:
      def __init__(self, num):
          self.top = num[0]
          self.front = num[1]
          self.right = num[2]
          self.left = num[3]
          self.back = num[4]
          self.bottom = num[5]
  
      def south_direction(self):
          front = self.top
          bottom = self.front
          back = self.bottom
          top = self.back
          right = self.right
          left = self.left
  
          self.top = top
          self.front = front
          self.bottom = bottom
          self.back = back
          self.right = right
          self.left = left
  
      def north_direction(self):
          back = self.top
          top = self.front
          front = self.bottom
          bottom = self.back
          right = self.right
          left = self.left
  
          self.top = top
          self.front = front
          self.bottom = bottom
          self.back = back
          self.right = right
          self.left = left
  
      def east_direction(self):
          right = self.top
          front = self.front
          left = self.bottom
          back = self.back
          bottom = self.right
          top = self.left
  
          self.top = top
          self.front = front
          self.bottom = bottom
          self.back = back
          self.right = right
          self.left = left
  
      def west_direction(self):
          left = self.top
          front = self.front
          right = self.bottom
          back = self.back
          top = self.right
          bottom = self.left
  
          self.top = top
          self.front = front
          self.bottom = bottom
          self.back = back
          self.right = right
          self.left = left
  
      def clockwise_rotate(self):
          top = self.top
          left = self.front
          bottom = self.bottom
          right = self.back
          front = self.right
          back = self.left
  
          self.top = top
          self.front = front
          self.bottom = bottom
          self.back = back
          self.right = right
          self.left = left
  
      def print_top(self):
          print(self.top)
  
      def judge_right(self, top, front):
          while True:
              if self.top == top and self.front == front:
                  print(self.right)
                  break
              elif top == self.front:
                  self.north_direction()
              elif top == self.left:
                  self.east_direction()
              elif top == self.back:
                  self.south_direction()
              elif top == self.right:
                  self.west_direction()
              elif top == self.bottom:
                  self.north_direction()
                  self.north_direction()
  
              elif front == self.front:
                  pass
              elif front == self.left:
                  self.clockwise_rotate()
                  self.clockwise_rotate()
                  self.clockwise_rotate()
              elif front == self.back:
                  self.clockwise_rotate()
                  self.clockwise_rotate()
              elif front == self.right:
                  self.clockwise_rotate()
  
  
  num = list(map(int, input().split()))
  rep = int(input())
  d = Dice(num)
  
  for i in range(rep):
      top, front = map(int, input().split())
      d.judge_right(top, front)
  
problem_description: 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.
  
    
  ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_11_B)
samples: [{"input": "2 3 4 5 6\n    3\n    6 5\n    1 3\n    3 2", "output": "5\n    6"}]