def whatIsRight(u,f):	

    r = 0

    if u == 1:

        if f == 2:

            r = 3

        elif f == 3:

            r = 5

        elif f == 4:

            r = 2

        elif f == 5:

            r = 4

	

    elif u == 2:

        if f == 6:

            r = 3

        elif f == 3:

            r = 1

        elif f == 1:

            r = 4

        elif f == 4:

            r = 6



    elif u == 3:

        if f == 5:

            r = 1

        elif f == 1:

            r = 2

        elif f == 2:

            r = 6

        elif f == 6:

            r = 5

			

    elif u == 4:

        if f == 6:

            r = 2

        elif f == 2:

            r = 1

        elif f == 1:

            r = 5

        elif f == 5:

            r = 6 

			

    elif u == 5:

        if f == 3:

            r = 6

        elif f == 6:

            r = 4

        elif f == 4:

            r = 1

        elif f == 1:

            r = 3

		

    elif u == 6:

        if f == 5:

            r = 3

        elif f == 3:

            r = 2

        elif f == 2:

            r = 4

        elif f == 4:

            r = 5

    return r

			

n = list(map(int,input().split()))

N = int(eval(input()))



for i in range(N):

    m = list(map(int,input().split()))

    num = []



    for j in range(len(m)):

        for k in range(len(n)):

            if m[j] == n[k]:

                num.append(k+1)

                break

	

    print((n[whatIsRight(num[0],num[1]) -1]))
def move(up,bottom,right,left,front,back,direction):

    if direction == "N":

        return (front,back,right,left,bottom,up)

    elif direction == "S":

        return (back,front,right,left,up,bottom)

    elif direction == "E":

        return (left,right,up,bottom,front,back)

    elif direction == "W":

        return (right,left,bottom,up,front,back)

    

def check(up,bottom,right,left,front,back,up_current,front_current):

    if front_current == front and up_current == up:

        print(right)     

    elif front_current == front:

        if left == up_current:

            print(up)

        elif bottom == up_current:

            print(left)

        elif right == up_current:

            print(bottom)

    elif up_current == up:

        if right == front_current:

            print(back)

        elif back == front_current:

            print(left)

        elif left == front_current:

            print(front)

    else:

      

        up,bottom,right,left,front,back = move(up,bottom,right,left,front,back,"S")

        check(up,bottom,right,left,front,back,up_current,front_current)

                

                

                

                

up,front,right,left,back,bottom = input().split()

n = int(eval(input()))



for i in range(n):

    up_current,front_current = input().split()

    check(up,bottom,right,left,front,back,up_current,front_current)

    
def whatIsRight(u, f):
    r = 0
    if u == 1:
        if f == 2:
            r = 3
        elif f == 3:
            r = 5
        elif f == 4:
            r = 2
        elif f == 5:
            r = 4
    elif u == 2:
        if f == 6:
            r = 3
        elif f == 3:
            r = 1
        elif f == 1:
            r = 4
        elif f == 4:
            r = 6
    elif u == 3:
        if f == 5:
            r = 1
        elif f == 1:
            r = 2
        elif f == 2:
            r = 6
        elif f == 6:
            r = 5
    elif u == 4:
        if f == 6:
            r = 2
        elif f == 2:
            r = 1
        elif f == 1:
            r = 5
        elif f == 5:
            r = 6
    elif u == 5:
        if f == 3:
            r = 6
        elif f == 6:
            r = 4
        elif f == 4:
            r = 1
        elif f == 1:
            r = 3
    elif u == 6:
        if f == 5:
            r = 3
        elif f == 3:
            r = 2
        elif f == 2:
            r = 4
        elif f == 4:
            r = 5
    return r


n = list(map(int, input().split()))
N = int(eval(input()))
for i in range(N):
    m = list(map(int, input().split()))
    num = []
    for j in range(len(m)):
        for k in range(len(n)):
            if m[j] == n[k]:
                num.append(k + 1)
                break
    print((n[whatIsRight(num[0], num[1]) - 1]))

def move(up, bottom, right, left, front, back, direction):
    if direction == "N":
        return (front, back, right, left, bottom, up)
    elif direction == "S":
        return (back, front, right, left, up, bottom)
    elif direction == "E":
        return (left, right, up, bottom, front, back)
    elif direction == "W":
        return (right, left, bottom, up, front, back)


def check(up, bottom, right, left, front, back, up_current, front_current):
    if front_current == front and up_current == up:
        print(right)
    elif front_current == front:
        if left == up_current:
            print(up)
        elif bottom == up_current:
            print(left)
        elif right == up_current:
            print(bottom)
    elif up_current == up:
        if right == front_current:
            print(back)
        elif back == front_current:
            print(left)
        elif left == front_current:
            print(front)
    else:
        up, bottom, right, left, front, back = move(
            up, bottom, right, left, front, back, "S"
        )
        check(up, bottom, right, left, front, back, up_current, front_current)


up, front, right, left, back, bottom = input().split()
n = int(eval(input()))
for i in range(n):
    up_current, front_current = input().split()
    check(up, bottom, right, left, front, back, up_current, front_current)

-def whatIsRight(u, f): -    r = 0 -    if u == 1: -        if f == 2: -            r = 3 -        elif f == 3: -            r = 5 -        elif f == 4: -            r = 2 -        elif f == 5: -            r = 4 -    elif u == 2: -        if f == 6: -            r = 3 -        elif f == 3: -            r = 1 -        elif f == 1: -            r = 4 -        elif f == 4: -            r = 6 -    elif u == 3: -        if f == 5: -            r = 1 -        elif f == 1: -            r = 2 -        elif f == 2: -            r = 6 -        elif f == 6: -            r = 5 -    elif u == 4: -        if f == 6: -            r = 2 -        elif f == 2: -            r = 1 -        elif f == 1: -            r = 5 -        elif f == 5: -            r = 6 -    elif u == 5: -        if f == 3: -            r = 6 -        elif f == 6: -            r = 4 -        elif f == 4: -            r = 1 -        elif f == 1: -            r = 3 -    elif u == 6: -        if f == 5: -            r = 3 -        elif f == 3: -            r = 2 -        elif f == 2: -            r = 4 -        elif f == 4: -            r = 5 -    return r +def move(up, bottom, right, left, front, back, direction): +    if direction == "N": +        return (front, back, right, left, bottom, up) +    elif direction == "S": +        return (back, front, right, left, up, bottom) +    elif direction == "E": +        return (left, right, up, bottom, front, back) +    elif direction == "W": +        return (right, left, bottom, up, front, back) -n = list(map(int, input().split())) -N = int(eval(input())) -for i in range(N): -    m = list(map(int, input().split())) -    num = [] -    for j in range(len(m)): -        for k in range(len(n)): -            if m[j] == n[k]: -                num.append(k + 1) -                break -    print((n[whatIsRight(num[0], num[1]) - 1])) +def check(up, bottom, right, left, front, back, up_current, front_current): +    if front_current == front and up_current == up: +        print(right) +    elif front_current == front: +        if left == up_current: +            print(up) +        elif bottom == up_current: +            print(left) +        elif right == up_current: +            print(bottom) +    elif up_current == up: +        if right == front_current: +            print(back) +        elif back == front_current: +            print(left) +        elif left == front_current: +            print(front) +    else: +        up, bottom, right, left, front, back = move( +            up, bottom, right, left, front, back, "S" +        ) +        check(up, bottom, right, left, front, back, up_current, front_current) + + +up, front, right, left, back, bottom = input().split() +n = int(eval(input())) +for i in range(n): +    up_current, front_current = input().split() +    check(up, bottom, right, left, front, back, up_current, front_current)