import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	static String[] defDice;
	static int[] intDice;

	public static void main(String[] args) throws IOException{


		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		//????????????????????????????????????
		defDice = insBR.readLine().split(" ");
		//int????????????
		intDice = new int[defDice.length];
		for(int i = 0; i < defDice.length; i++){
			intDice[i] = Integer.parseInt(defDice[i]);
		}

		//?????¶??°????????????
		int intNum = Integer.parseInt(insBR.readLine());

		//?????¢?????£??¢????????¢????????????????????°
		int intTopNum = 0;
		int intFrontNum = 0;
		int intRightNum = 0;


		for(int i = 0; i < intNum; i++){

			//?????´???????????????????????§??????
			String strLine = insBR.readLine();
			String[] ary = strLine.split(" ");
			intTopNum = Integer.parseInt(ary[0]);
			intFrontNum = Integer.parseInt(ary[1]);


			//??´?????°????????´????????????????????????roll??????????????????
			if(intTopNum == intDice[5]){
				roll("S");
				roll("S");
				//??£??¢??°???????????°??§??????????????????????????§????????????????????§?????¢????????????
				intRightNum = getRightNum(intFrontNum);

			}else if(intTopNum == intDice[4]){

				roll("S");
				//??£??¢??°???????????°??§??????????????????????????§????????????????????§?????¢????????????
				intRightNum = getRightNum(intFrontNum);
			}else if(intTopNum == intDice[3]){

				roll("E");
				//??£??¢??°???????????°??§??????????????????????????§????????????????????§?????¢????????????
				intRightNum = getRightNum(intFrontNum);
			}else if(intTopNum == intDice[2]){

				roll("W");
				//??£??¢??°???????????°??§??????????????????????????§????????????????????§?????¢????????????
				intRightNum = getRightNum(intFrontNum);
			}else if(intTopNum == intDice[1]){

				roll("N");
				//??£??¢??°???????????°??§??????????????????????????§????????????????????§?????¢????????????
				intRightNum = getRightNum(intFrontNum);
			}else {

				//intDice[0]?????¨???????????????????????????
				//??£??¢??°???????????°??§??????????????????????????§????????????????????§?????¢????????????
				intRightNum = getRightNum(intFrontNum);
			}
			System.out.println(intRightNum);
		}

	}


	//???????????????????§?????????????????????????????????????????????´??????
	public static void roll(String direction){

		if("S".equals(direction)){

			int temp = intDice[0];
			intDice[0] = intDice[4];
			intDice[4] = intDice[5];
			intDice[5] = intDice[1];
			intDice[1] = temp;
		}else if("E".equals(direction)){

			int temp = intDice[0];
			intDice[0] = intDice[3];
			intDice[3] = intDice[5];
			intDice[5] = intDice[2];
			intDice[2] = temp;
		}else if("W".equals(direction)){

			int temp = intDice[0];
			intDice[0] = intDice[2];
			intDice[2] = intDice[5];
			intDice[5] = intDice[3];
			intDice[3] = temp;
		}else if("N".equals(direction)){

			int temp = intDice[0];
			intDice[0] = intDice[1];
			intDice[1] = intDice[5];
			intDice[5] = intDice[4];
			intDice[4] = temp;
		}

	}
	//???????????????Front??¢?????????????????´????????´???????????????????????¢?????????
	 public static int getRightNum(int intFrontNum){
		//return????????¢???num????????????????????°
		int intRightNum = 0 ;
		if(intFrontNum == intDice[1]){//1??¢????????´????????¨???

			intRightNum = intDice[2];

		}else if(intFrontNum == intDice[2]){//2??¢????????´????????¨???

			intRightNum = intDice[4];
		}else if(intFrontNum == intDice[3]){//3??¢????????´????????¨???

			intRightNum = intDice[1];
		}else if(intFrontNum == intDice[4]){//4??¢????????´????????¨???

			intRightNum = intDice[3];
		}

		return intRightNum;
	 }

}

Measured memory_bytes: 16904