import java.io.*;

class Dice
{
  String[] face; //???????????¢???????????¨???
  int[] num; //?????????????????????
  static final int SURFACE = 6;
  static final int TOP = 0;
  static final int SOUTH = 1;
  static final int EAST = 2;
  static final int WEST = 3;
  static final int NORTH = 4;
  static final int BOTTOM = 5;

  public Dice(String str) //?????????
  {
    this.face = new String[SURFACE];
    this.face = str.split(" ");
    this.num = new int[SURFACE];
    for(int i = 0; i < this.face.length; i++){
      num[i] = Integer.parseInt(face[i]);
    }
  }

  public int get(int n) { return this.num[n]; } //?????°?????¢?????????

  public void roll(char way) //?????¢???????????????????????¢?????????????????´??????
  {
    int tmp;
    switch(way){
      case 'N':
        tmp = num[0];
        this.num[0] = this.num[1];
        this.num[1] = this.num[5];
        this.num[5] = this.num[4];
        this.num[4] = tmp;
        break;
      case 'S':
        tmp = this.num[0];
        this.num[0] = this.num[4];
        this.num[4] = this.num[5];
        this.num[5] = this.num[1];
        this.num[1] = tmp;
        break;
      case 'E':
        tmp = this.num[0];
        this.num[0] = this.num[3];
        this.num[3] = this.num[5];
        this.num[5] = this.num[2];
        this.num[2] = tmp;
        break;
      case 'W':
        tmp = this.num[0];
        this.num[0] = this.num[2];
        this.num[2] = this.num[5];
        this.num[5] = this.num[3];
        this.num[3] = tmp;
        break;
      case 'C': //clockwise
        tmp = this.num[1];
        this.num[1] = this.num[2];
        this.num[2] = this.num[4];
        this.num[4] = this.num[3];
        this.num[3] = tmp;
        break;
      case 'A': //anticlockwise(counterclockwise)
        tmp = this.num[1];
        this.num[1] = this.num[3];
        this.num[3] = this.num[4];
        this.num[4] = this.num[2];
        this.num[2] = tmp;
        break;
      default:
        break;
    }
  }

  public void change(String str) //top??¨front?????????????????¢????????????????????????
  {
    String[] cond = str.split(" ");
    int t;
    int top = SURFACE; //????????¶??????6???num???????????????????????????
    int front = SURFACE;

    for(t = 0; t < this.num.length; t++){ //top??¨front??????????????¢?????¢???
      if(Integer.parseInt(cond[0]) == num[t]){ //top
        top = t;
      }else if(Integer.parseInt(cond[1]) == num[t]){ //front
        front = t;
      }
    }

    if(top == SURFACE || front == SURFACE) return; //?????????????????¢?????????????????????

    switch(top){ //top?????????????????´
      case TOP:
        break;
      case SOUTH:
        this.roll('N');
        break;
      case EAST:
        this.roll('W');
        break;
      case WEST:
        this.roll('E');
        break;
      case NORTH:
        this.roll('S');
        break;
      case BOTTOM:
        this.roll('S');
        this.roll('S');
        break;
    }

    while(Integer.parseInt(cond[1]) != num[SOUTH]){ //front?????????????????´
      this.roll('C');
    }
  }
}

class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine(); // dice?????¢???????????\???

    Dice dice = new Dice(str);

    str = br.readLine(); //????????°?????\???
    int q = Integer.parseInt(str);
    for(int i = 0; i < q; i++){
      str = br.readLine();
      dice.change(str); //??????????????´
      System.out.println(dice.get(2)); //???????????????
    }
  }
}

Measured memory_bytes: 24356