#include <iostream>
using namespace std;
class Dice {
private:
    void shift(int i, int j, int k, int l) {
        // i<-j<-k<-l<-i
        int t=a[i];a[i]=a[j];a[j]=a[k];a[k]=a[l];a[l]=t;
    }
public:
    int a[7]={0};
    void move(char d) {
        if(d=='N') shift(1,2,6,5);
        else if(d=='E') shift(1,4,6,3);
        else if(d=='W') shift(1,3,6,4);
        else if(d=='S') shift(1,5,6,2);
    }
};
int main() {
    Dice d; int n;
    for(int i = 1; i <= 6; ++i) cin >> d.a[i];
    cin >> n;
    string r[2][7] = {
        // 1<-1,2,3,4,5,6(2fix)
        {"","","","W","E","","WW"},
        // 2<-1,2,3,4,5,6
        {"","S","","WS","ES","SS","N"}
    };
    for(int i = 0, x, y, p, q; i < n; ++i) {
        cin >> x >> y;
        for(int j = 1; j <= 6; ++j) if(d.a[j]==y) {q=j;break;}
        for(int j = 0; j < r[1][q].length(); ++j) d.move(r[1][q][j]);
        for(int j = 1; j <= 6; ++j) if(d.a[j]==x) {p=j;break;}
        for(int j = 0; j < r[0][p].length(); ++j) d.move(r[0][p][j]);
        cout << d.a[3] << endl;
    }
    return 0;
}
