#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;

struct Dice{
  vector<int> asp;
  string dir;
};

void rot(vector<int> &asp, char ch){
  switch(ch){
    case 'N': asp={asp[1],asp[5],asp[2],asp[3],asp[0],asp[4]};
              break;
    case 'E': asp={asp[3],asp[1],asp[0],asp[5],asp[4],asp[2]};
              break;
    case 'S': asp={asp[4],asp[0],asp[2],asp[3],asp[5],asp[1]};
              break;
    case 'W': asp={asp[2],asp[1],asp[5],asp[0],asp[4],asp[3]};
              break;
  }
}



int main(){
  Dice d1;
  for(int i=0; i<6; i++){
    int x;
    cin >> x;
    d1.asp.push_back(x);
  }
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    int top, frt;
    cin >> top >> frt;
    while(d1.asp[0] != top){
      if(top==d1.asp[2]) rot(d1.asp, 'W');
      else if(top==d1.asp[3]) rot(d1.asp,'E');
      else rot(d1.asp, 'N');
    }
    if(frt==d1.asp[1]) cout << d1.asp[2];
    else if(frt==d1.asp[2]) cout << d1.asp[4];
    else if(frt==d1.asp[3]) cout << d1.asp[1];
    else cout << d1.asp[3];
    cout << endl;
  }
  return 0;
}
