#include <bits/stdc++.h>

using namespace std;

const int NUM_FACES = 6;
const int NUM_SWAPS = 3;
const int UP = 0;
const int ACROSS = 1;

int faces[NUM_FACES];

int swap_i[2][NUM_SWAPS][2] = {
	{{0, 1}, {1, 5}, {4, 5}},
	{{1, 3}, {2, 3}, {3, 4}}
};

void rotate(int dir) {
	for (int i = 0; i < NUM_SWAPS; ++i) {
		swap(faces[swap_i[dir][i][0]], faces[swap_i[dir][i][1]]);
	}	
}

int main() {
	for (int i = 0; i < NUM_FACES; ++i) {
		cin >> faces[i];
	}

	int q;
	cin >> q;
	while (q--) {
		int a, b;
		cin >> a >> b;

		if (faces[2] == a || faces[3] == a) {
			rotate(ACROSS);
		}
		while (faces[0] != a) {
			rotate(UP);
		}

		while (faces[1] != b) {
			rotate(ACROSS);
		}

		cout << faces[2] << '\n';
	}
}
