#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

class Dice{
  public:
    vector<int> numbers;
    int buttom_index;
    int top_index;
    int w_index;
    int e_index;
    int s_index;
    int n_index;
  
    void roll_to(char direction){
      int tmp;
      if (direction == 'W'){
        tmp = top_index;
        top_index = e_index;
        e_index = buttom_index;
        buttom_index = w_index;
        w_index = tmp;
      }else if(direction == 'E'){
        // cout << "e" << endl;
        tmp = top_index;
        top_index = w_index;
        w_index = buttom_index;
        buttom_index = e_index;
        e_index = tmp;
      }else if(direction == 'S'){
        // cout << "s" << endl;
        tmp = top_index;
        top_index = n_index;
        n_index = buttom_index;
        buttom_index = s_index;
        s_index = tmp;
      }else{
        tmp = top_index;
        top_index = s_index;
        s_index = buttom_index;
        buttom_index = n_index;
        n_index = tmp;
      }
    }

    int right_side(int top_i, int front_i){
      if (top_i == 0){
        switch (front_i){
        case 1:
          return numbers[2];
          break;
        case 2:
          return numbers[4];
          break;
        case 3:
          return numbers[1];
          break;
        case 4:
          return numbers[3];
          break;
        }
      }
      if (top_i == 1){
        switch (front_i){
        case 0:
          return numbers[3];
          break;
        case 2:
          return numbers[0];
          break;
        case 3:
          return numbers[5];
          break;
        case 5:
          return numbers[2];
          break;
        }
      }
      if (top_i == 2){
        switch (front_i){
        case 0:
          return numbers[1];
          break;
        case 1:
          return numbers[5];
          break;
        case 4:
          return numbers[0];
          break;
        case 5:
          return numbers[4];
          break;
        }
      }
      if (top_i == 3){
        switch (front_i){
        case 0:
          return numbers[4];
          break;
        case 1:
          return numbers[0];
          break;
        case 4:
          return numbers[5];
          break;
        case 5:
          return numbers[1];
          break;
        }
      }
      if (top_i == 4){
        switch (front_i){
        case 0:
          return numbers[2];
          break;
        case 2:
          return numbers[5];
          break;
        case 3:
          return numbers[0];
          break;
        case 5:
          return numbers[3];
          break;
        }
      }
      if (top_i == 5){
        switch (front_i){
        case 1:
          return numbers[3];
          break;
        case 2:
          return numbers[1];
          break;
        case 3:
          return numbers[4];
          break;
        case 4:
          return numbers[2];
          break;
        }
      }
    }
};

int main(){
  Dice dice;
  int tmp;
  for (int i = 0; i < 6; i++){
    cin >> tmp;
    dice.numbers.push_back(tmp);
  }
  int n, top_num, front_num;
  cin >> n;
  for (int i = 0; i < n; i++){
    cin >> top_num >> front_num;
    vector<int>::iterator top_itr = find(dice.numbers.begin(), dice.numbers.end(), top_num);
    vector<int>::iterator front_itr = find(dice.numbers.begin(), dice.numbers.end(), front_num);
    size_t top_index = distance(dice.numbers.begin(), top_itr);
    size_t front_index = distance(dice.numbers.begin(), front_itr);
    cout << dice.right_side(top_index, front_index) << endl;
  }
  
}


Measured memory_bytes: 3148