#include<iostream>
using namespace std;
int main(){
    int x[6]={};
    for(int i=0;i<6;i++){
        cin>>x[i];
    }
    int y[6][5]={{1,2,4,3,1},{0,3,5,2,0},{0,1,5,4,0},{0,4,5,1,0},{0,2,5,3,0},{1,3,4,2,1}};
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int A,B,a=0,b=0,c=0;
        cin>>A>>B;
        while(1){
            if(x[a]==A){
                break;
            }
            a++;
        }
        while(1){
            if(x[b]==B){
                break;
            }
            b++;
        }
        while(1){
            if(b==y[a][c]){
                break;
            }
            c++;
        }
        
        cout<<x[y[a][c+1]]<<endl;
    }

    return 0;
}
