class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def get_face(self, face):
        if face == 'top':
            return self.top
        elif face == 'south':
            return self.south
        elif face == 'east':
            return self.east
        elif face == 'west':
            return self.west
        elif face == 'north':
            return self.north
        elif face == 'bottom':
            return self.bottom
        

    def rotate(self, directions):
        for direction in directions:
            if direction == 'S':
                self.prev_top = self.top
                self.top = self.north
                self.north = self.bottom
                self.bottom = self.south
                self.south = self.prev_top
            elif direction == 'E':
                self.prev_top = self.top
                self.top = self.west
                self.west = self.bottom
                self.bottom = self.east
                self.east = self.prev_top
            elif direction == 'W':
                self.prev_top = self.top
                self.top = self.east
                self.east = self.bottom
                self.bottom = self.west
                self.west = self.prev_top
            elif direction == 'N':
                self.prev_top = self.top
                self.top = self.south
                self.south = self.bottom
                self.bottom = self.north
                self.north = self.prev_top

dice = Dice(*map(int,input().split()))
n = input()
for _ in range(n):
  top, south = map(int, input().split())
  # find top face
  for direction in 'NNNEEE':
    if dice.get_face('top') == top:
        break
    dice.rotate(direction)

  # find south face
  for direction in 'NES'*3:
    if dice.get_face('south') == south:
        break

  print(dice.get_face('east'))

### FIXED CODE ###

class Dice:
    def __init__(self, top: str, front: str, right: str, left: str, back: str, bottom: str) -> None:
        self.top = top
        self.front = front
        self.right = right
        self.left = left
        self.back = back
        self.bottom = bottom

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

    def print_right(self):
        print(self.right)

    def roll(self, direction: str) -> None:
        if direction == 'S':
            self.south()
        elif direction == 'N':
            self.north()
        elif direction == 'E':
            self.east()
        elif direction == 'W':
            self.west()

    def north(self):
        [self.top, self.back, self.bottom, self.front] = [self.front, self.top, self.back, self.bottom]

    def south(self):
        [self.top, self.back, self.bottom, self.front] = [self.back, self.bottom, self.front, self.top]

    def east(self):
        [self.top, self.right, self.bottom, self.left] = [self.left, self.top, self.right, self.bottom]

    def west(self):
        [self.top, self.right, self.bottom, self.left] = [self.right, self.bottom, self.left, self.top]

    def rotate_right(self) -> None:
        for direction in 'SWN':
            dice.roll(direction)


def solve(dice: Dice, top: str, front: str) -> None:
    # find top
    found = False
    for direction in 'SSSS':
        dice.roll(direction)
        if dice.top == top:
            found = True
            break
    if not found:
        for direction in 'EEE':
            dice.roll(direction)
            if dice.top == top:
                break

    # find front
    for _ in range(4):
        dice.rotate_right()
        if dice.front == front:
            break

    # answer right
    dice.print_right()


labels = input().split()
dice = Dice(*labels)
n = int(input())
for i in range(n):
    top, front = input().split()
    solve(dice, top, front)