#include <string>
#include <iostream>
using namespace std;

class Dice
{
public:
	int label[7];
	int orientation[7];

	Dice() { }
	Dice(int l[6]) : orientation{0,1,2,3,4,5,6}
	{
		for(int i=1; i<7; ++i) label[i] = l[i-1];
	}

	int getIndex(int l) const {
		int i=0;
		while(++i<7) if(l == label[i]) break;
		return i;
	}

	int getFace(int top, int front) const {
		// top then front
		int i=0;
		static const int loops[3][4] = { {2,3,5,4}, {1,2,6,5}, {1,3,6,4}};
		static const int result[3] = {1,3,5};

		for(int j=0; j<3 && i==0; ++j)
			for(int k=0; k<4 && i==0; ++k)
				if(loops[j][k] == top) {
					if(loops[j][(k+1)%4] == front) i = result[j];
					else if(loops[j][(k+3)%4] == front) i = 7 - result[j];
				}
		return label[i];
	}

};


int main()
{
	int label[6];
	for(auto &l : label) cin >> l;

	Dice dice(label);

	int q; cin >> q;
	while(q--) {
		int top, front;
		cin >> top >> front;
		top = dice.getIndex(top);
		front = dice.getIndex(front);
		cout << dice.getFace(top, front) << '\n';
	}
	
	return 0;
}

