#include<iostream>
#include<string>
using namespace std;

class Dice {
    public:
    int f[6];
    Dice() {}
    void roll_z() { roll(1, 2, 4, 3);}
    void roll_W() { roll(0, 2, 5, 3);}
    void roll_N() { roll(0, 1, 5, 4);}
    void roll_S() { roll(0, 4, 5, 1);}
    void roll_E() { roll(0, 3, 5, 2);}
    void roll (int i, int j, int k, int l) {
        int t = f[i];
        f[i] = f[j];
        f[j] = f[k];
        f[k] = f[l];
        f[l] = t;
    }
    int top() {
        return f[0];
    }
    int front() {
        return f[1];
    }
    int left() {
        return f[3];
    }
    int right() {
        return f[2];
    }
};


int main() {
    Dice d;
    
    for (int i = 0; i < 6; i++) cin >> d.f[i];
    int q;
    cin >> q;
    
    for (int i = 0; i < q; i++) {
        int a ,b; cin >> a >> b;
        if(d.left() == a) d.roll_E();
        if(d.right() == a) d.roll_W();
        while(d.top() != a) d.roll_N();
        while(d.front() != b) d.roll_z();
        cout << d.right() << endl;
    }
    return 0;
}

