#include <stdio.h>
#include <string.h>

typedef struct {
    int num[6], temp;
} dice_struct;
dice_struct dice;

void setting(int d[]) {
    for (int i = 0; i < 6; i++) {
        dice.num[i] = d[i];
    }
}

int right(int top, int front) {
    int zero = dice.num[0];
    int one = dice.num[1];
    int two = dice.num[2];
    int three = dice.num[3];
    int four = dice.num[4];
    int five = dice.num[5];


    if (top == zero) {
        if (front == one) {
            return two;
        } else if (front == two) {
            return four;
        } else if (front == four) {
            return three;
        } else if (front == three) {
            return one;
        }
    } else if (top == one) {
        if (front == two) {
            return zero;
        } else if (front == zero) {
            return three;
        } else if (front == three) {
            return five;
        } else if (front == five) {
            return two;
        }
    } else if (top == two) {
        if (front == zero) {
            return one;
        } else if (front == one) {
            return five;
        } else if (front == five) {
            return four;
        } else if (front == four) {
            return zero;
        }
    } else if (top == three) {
        if (front == zero) {
            return four;
        } else if (front == four) {
            return five;
        } else if (front == five) {
            return one;
        } else if (front == one) {
            return zero;
        }
    } else if (top == four) {
        if (front == zero) {
            return two;
        } else if (front == two) {
            return five;
        } else if (front == five) {
            return three;
        } else if (front == three) {
            return zero;
        }
    } else if (top == five) {
        if (front == one) {
            return three;
        } else if (front == three) {
            return four;
        } else if (front == four) {
            return two;
        } else if (front == two) {
            return one;
        }
    }
}



/*
    switch (top) {
        case zero:
            switch (front) {
                case one:
                    return two;
                case two:
                    return four;
                case four:
                    return three;
                case three:
                    return one;
            }
        case one:
            switch (front) {
                case two:
                    return zero;
                case zero:
                    return three;
                case three:
                    return five;
                case five:
                    return two;
            }
        case two:
            switch (front) {
                case zero:
                    return one;
                case one:
                    return five;
                case five:
                    return four;
                case four:
                    return zero;
            }
        case three:
            switch (front) {
                case zero:
                    return four;
                case four:
                    return five;
                case five:
                    return one;
                case one:
                    return zero;
            }
        case four:
            switch (front) {
                case zero:
                    return two;
                case two:
                    return five;
                case five:
                    return three;
                case three:
                    return zero;
            }
        case five:
            switch (front) {
                case one:
                    return three;
                case three:
                    return four;
                case four:
                    return two;
                case two:
                    return one;
            }
    }
*/


int main(int argc, char const *argv[]) {
    
    int number[6];
    for (int i = 0; i < 6; i++) {
        scanf("%d", &number[i]);
    }
    setting(number);

    int q;
    scanf("%d", &q);

    int t, f, r;

    for (int i = 0; i < q; i++) {
        scanf("%d %d", &t, &f);
        r = right(t, f);
        printf("%d\n", r);
    }   
       
    return 0;


}


Measured memory_bytes: 2040