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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
				
		//?????????????????????????´?????????????
		int[] aryDice = new int[6];
		//????????????????????????
		String[] ary = insBR.readLine().split(" ");
		//int???????????????????????£??\
		for(int i = 0; i < ary.length; i++){
			aryDice[i] = Integer.parseInt(ary[i]);
		}
		 
		//????????????????????????(?????±?????°)
		int intNum = Integer.parseInt(insBR.readLine());
				
		//top,front,right??¢????????????????????°
		int intTop = 0;
		int intFront = 0;
		int intRight = 0;
		
		//Dice ????????????????????????
		Dice dice = new Dice();
		dice.setAryDice(aryDice);
		
		for(int i = 0; i < intNum; i++){
			//???????????\??????????????????(?????????1????????\?????????)
			String[] strAry = insBR.readLine().split(" ");
			try{
				intTop = Integer.parseInt(strAry[0]);
				intFront = Integer.parseInt(strAry[1]);	
			}catch(NumberFormatException e){
				System.out.println("??°?????\????????\?????????????????????");
			}
			
			
			if(intTop == aryDice[5]){
				dice.roll("S");
				dice.roll("S");
				//??????????????§??????????????????????????????
				intRight = dice.getIntRight(intFront);
			}else if(intTop == aryDice[4]){
				dice.roll("S");
				intRight = dice.getIntRight(intFront);
			}else if(intTop == aryDice[3]){
				dice.roll("E");
				intRight = dice.getIntRight(intFront);
			}else if(intTop == aryDice[2]){
				dice.roll("W");
				intRight = dice.getIntRight(intFront);
			}else if(intTop == aryDice[1]){
				dice.roll("N");
				intRight = dice.getIntRight(intFront);
			}else{
				//aryDice[0]????????????Top????????´????????????????????????
				intRight = dice.getIntRight(intFront);
			}
			System.out.println(intRight);
		}

	}

////?????????????????????????????????	
	static class Dice {
		
		//?????£?????????
		
		//???????????????????????????????????????????´?????????????
		private int [] aryDice = new int[6];
		
		//?????????????????????Dice
		Dice(){
		}
		//Method ????§?????????°??§??????????????????????????????????????????
		public void roll(String direction){
			//??£??\?????????????????¨??????????????¨
			int temp = 0;
			if("S".equals(direction)){
				temp = aryDice[0];
				aryDice[0] = aryDice[4];
				aryDice[4] = aryDice[5];
				aryDice[5] = aryDice[1];
				aryDice[1] = temp;
			}else if("E".equals(direction)){
				temp = aryDice[0];
				aryDice[0] = aryDice[3];
				aryDice[3] = aryDice[5];
				aryDice[5] = aryDice[2];
				aryDice[2] = temp;
			}else if("W".equals(direction)){
				temp = aryDice[0];
				aryDice[0] = aryDice[2];
				aryDice[2] = aryDice[5];
				aryDice[5] = aryDice[3];
				aryDice[3] = temp;
			}else if("N".equals(direction)){
				temp = aryDice[0];
				aryDice[0] = aryDice[1];
				aryDice[1] = aryDice[5];
				aryDice[5] = aryDice[4];
				aryDice[4] = temp;
			}
		
		}
		//Method ??£??¢?????°???????????°??§?????????????????????????????¢?????????
		public int getIntRight(int intFront){
			//right??¢????????????????????°
			int intRight = 0;
			
			if(intFront == aryDice[1]){//1??¢??§?????´????????´???
				intRight = aryDice[2];
			}else if(intFront == aryDice[2]){//2??¢??§?????´????????´???
				intRight = aryDice[4];
			}else if(intFront == aryDice[3]){//3??¢??§?????´????????´???
				intRight = aryDice[1];
			}else if(intFront == aryDice[4]){//4??¢??§?????´????????´???
				intRight = aryDice[3];
			}
			
			return intRight;
		}

		
		
		
		
		//Method set get
		public int[] getAryDice() {
			return aryDice;
		}
		public void setAryDice(int[] aryDice) {
			this.aryDice = aryDice;
		}
		
	}//??????????????????
}

Measured memory_bytes: 16924