#include<bits/stdc++.h>
#define N 6
#define NA 100
#define Q 24
using namespace std;

void change(char);
int dice[N];

int main(){
  
  char arrow[]="NWNWNW";
  string str;
  int i,j,num,x,y;

  for(i=0;i<N;i++)cin>>dice[i];
  cin>>num;
  
  for(i=0;i<num;i++){
    cin>>x>>y;
    for(j=0;j<6;j++){
      
      change(arrow[j]);
      
      if(dice[0]==x&&dice[1]==y){
	cout<<dice[2]<<endl;
	break;
      }else if(dice[0]==x&&dice[3]==y){
	cout<<dice[1]<<endl;
	break;
      }else if(dice[0]==x&&dice[4]==y){
	cout<<dice[3]<<endl;
	break;
      }else if(dice[0]==x&&dice[2]==y){
	cout<<dice[4]<<endl;
	break;
      }
    }
  }
    
}

void change(char c){
  if(c=='N'){
    swap(dice[0],dice[4]);
    swap(dice[0],dice[1]);
    swap(dice[1],dice[5]);
  }else if(c=='S'){
    swap(dice[0],dice[1]);
    swap(dice[0],dice[4]);
    swap(dice[5],dice[4]);
  }else if(c=='W'){
    swap(dice[2],dice[0]);
    swap(dice[2],dice[5]);
    swap(dice[5],dice[3]);
  }else if(c=='E'){
    swap(dice[0],dice[3]);
    swap(dice[3],dice[5]);
    swap(dice[5],dice[2]);
  }
}

