#include <stdio.h>

//関数プロトタイプ宣言
void moving_north(int *top, int *bottom, int *front, int *back);
void moving_south(int *top, int *bottom, int *front, int *back);
void moving_east(int *top, int *bottom, int *right_side, int *left_side);
void moving_west(int *top, int *bottom, int *right_side, int *left_side);

//ダイスの構造体
typedef struct{
	int top;
	int bottom;
	int right_side;
	int left_side;
	int front;
	int back;
}Dice;

int main(void)
{
	Dice dice1;

	//iはループ変数、input_countは問題の数、input_topとinput_frontは回転後の上面と前面の値
	int i, input_count;
	int input_top[100], input_front[100];

	//ダイスの目と問題数を入力
	scanf("%d %d %d %d %d %d", 
		  &dice1.top, &dice1.front, &dice1.right_side, &dice1.left_side, &dice1.back, &dice1.bottom);
	scanf("%d", &input_count);

	//問題を入力
	for(i = 0; i < input_count; i++){
		scanf("%d %d", &input_top[i], &input_front[i]);
	}

	for(i = 0; i < input_count; i++){
		//上面を揃える(下面も確定する)
		if((input_top[i] == dice1.right_side)){
			moving_west(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
		}
		else if((input_top[i] == dice1.left_side)){
			moving_east(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
		}
		else if(input_top[i] == dice1.front){
			moving_north(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
		}
		else if(input_top[i] == dice1.back){
			moving_south(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
		}
		else if(input_top[i] == dice1.bottom){
			moving_north(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
			moving_north(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
		}

		//上面と前面が揃った状態にする
		if((input_front[i] == dice1.right_side)){
			moving_west(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
			moving_south(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
			moving_east(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
		}
		else if((input_front[i] == dice1.left_side)){
			moving_east(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
			moving_south(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
			moving_west(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
		}
		else if(input_front[i] == dice1.back){
			moving_west(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
			moving_south(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
			moving_south(&dice1.top, &dice1.bottom, &dice1.front, &dice1.back);
			moving_east(&dice1.top, &dice1.bottom, &dice1.right_side, &dice1.left_side);
		}
		
		//結果の出力
		printf("%d\n", dice1.right_side);
	}
	return 0;
}

//北側に転がす関数
void moving_north(int *top, int *bottom, int *front, int *back)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *front;
	*front = *bottom;
	*bottom = *back;
	*back = temp;
}

//南側に転がす関数
void moving_south(int *top, int *bottom, int *front, int *back)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *back;
	*back = *bottom;
	*bottom = *front;
	*front = temp;
}

//東側に転がす関数
void moving_east(int *top, int *bottom, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *left_side;
	*left_side = *bottom;
	*bottom = *right_side;
	*right_side = temp;
}

//西側に転がす関数
void moving_west(int *top, int *bottom, int *right_side, int *left_side)
{
	int temp;

	//各面の値をずらす
	temp = *top;
	*top = *right_side;
	*right_side = *bottom;
	*bottom = *left_side;
	*left_side = temp;
}


Measured memory_bytes: 2048