#include <bits/stdc++.h>
#define ll long long
ll mod=1000000007;
#define vl vector<ll>
#define pl pair<ll,ll>
#define rep(i,b) for(ll i=0;i<b;i++)
#define all(v) (v).begin(),(v).end()
using namespace std;

int main(){
    int y[7];
    int x[6][6]={{0,3,5,2,4,0},{4,0,1,6,0,3},{2,6,0,0,1,5},{5,1,0,0,6,2},{3,0,6,1,0,4},{0,4,2,5,3,0}};
    int a,b,c,d,q;
    rep(i,6)cin>>y[i+1];
    cin>>q;
    rep(i,q){
        cin>>a>>b;
        for(int j=1;j<=6;j++){
            if(a==y[j])c=j;
            if(b==y[j])d=j;
        }
        cout<<y[x[c-1][d-1]]<<endl;
    }
}
