#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = a; (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmix(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<int>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;

vad Read(ll n) {
    auto      v = vad(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

class Dice {
  public:
    ll top_;
    ll bottom_;
    ll W_;
    ll S_;
    ll E_;
    ll N_;

    Dice() {
        top_    = 1;
        bottom_ = 6;
        W_      = 4;
        S_      = 2;
        E_      = 3;
        N_      = 5;
    }

    void RollW(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = E;
        bottom_ = W;
        W_      = top;
        S_      = S;
        E_      = bottom;
        N_      = N;
    }

    void RollS(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = N;
        bottom_ = S;
        W_      = W;
        S_      = top;
        E_      = E;
        N_      = bottom;
    }

    void RollE(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = W;
        bottom_ = E;
        W_      = bottom;
        S_      = S;
        E_      = top;
        N_      = N;
    }

    void RollN(ll top, ll bottom, ll W, ll S, ll E, ll N) {
        top_    = S;
        bottom_ = N;
        W_      = W;
        S_      = bottom;
        E_      = E;
        N_      = top;
    }


    void Roll(char dist) {
        if (dist == 'W') RollW(top_, bottom_, W_, S_, E_, N_);
        else if (dist == 'S')RollS(top_, bottom_, W_, S_, E_, N_);
        else if (dist == 'E')RollE(top_, bottom_, W_, S_, E_, N_);
        else if (dist == 'N')RollN(top_, bottom_, W_, S_, E_, N_);
        //else cout << dist << " is not distance" << endl;

        //cout << "top : " << top_ << ", bottom : " << bottom_ << ", W : " << W_
        //<< ", S : " << S_ << ", E : " << E_ << ", N : " << N_ << endl;
    }

    void DetectS(int S){
        REP(i, 4) {
            Roll('S');
            if (S_ == S) return;
        }
        Roll('E');
        Roll('S');
        if (S_ == S) return;
        Roll('S');
        Roll('S');
    }

    int ITP1_11_B(int top, int S){
        DetectS(S);
        REP(i, 4){
            Roll('E');
            if (top_ == top && S_ == S) return E_;
        }
        return 0;
    }
};

int Eyes(const vi& num, int eye){
    REP(i, int(num.size())){
        if (num[i] == eye) return i;
    }
}

int main() {
    cout << setprecision(20) << fixed;
    auto num = vi(7);

    FOR(i, 1, 7) cin >> num[i];

    int p;
    cin >> p;

    Dice dice;
    REP(i, p) {
       int top, S;

       cin >> top >> S;
        const auto i_top = Eyes(num, top);
        const auto i_S = Eyes(num, S);
        cout << num[dice.ITP1_11_B(i_top, i_S)] << endl;
    }

    return 0;
}



Measured memory_bytes: 3096