#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

struct dice {
	int f2n[6];
	map<int,int> n2f;
};

int main(void) {
	dice d;
	for (int i = 0; i < 6; ++i) {
		cin >> d.f2n[i];
		d.n2f[d.f2n[i]] = i;
	}

	int noq,top,front;
	cin >> noq;
	for (int q = 0; q < noq; ++q) {
		cin >> top >> front;
		top = d.n2f[top];
		front = d.n2f[front];
		int neg = 1;
		if (top > 2) {
			neg = -1;
			top = 5-top;
		}
		for (int i = 0; i < 4; ++i) {
			if (line[top][i] == front) {
				int next = (i+neg)%4;
				if (next < 0) {
					next = 3;
				}
				cout << d.f2n[line[top][next]] << endl; 
			}
		}
	}

	return 0;
}


