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

class Dice{
public:
	int m_t, m_s, m_e, m_w, m_n, m_b;
	Dice(int a[6]){
		m_t = a[0];
		m_s = a[1];
		m_e = a[2];
		m_w = a[3];
		m_n = a[4];
		m_b = a[5];
	}
	~Dice(){}
	void south(){
		int tmp = m_t;
		m_t = m_n;
		m_n = m_b;
		m_b = m_s;
		m_s = tmp;
	}
	void east(){
		int tmp = m_t;
		m_t = m_w;
		m_w = m_b;
		m_b = m_e;
		m_e = tmp;
	}
	void west(){
		int tmp = m_t;
		m_t = m_e;
		m_e = m_b;
		m_b = m_w;
		m_w = tmp;
	}
	void north(){
		int tmp = m_t;
		m_t = m_s;
		m_s = m_b;
		m_b = m_n;
		m_n = tmp;
	}
};

int main(){
	int a[6];
	for (int i = 0; i < 6; i++) cin >> a[i];
	Dice k(a);
	int q;
	cin >> q;
	for (int i = 0; i < q; i++){
		int a, b;
		cin >> a >> b;
		for (int j = 0; j < 4; j++){
			k.north();
			if (k.m_t == a) break;
		}
		for (int j = 0; j < 4; j++){
			k.west();
			if (k.m_t == a) break;
		}
		k.north();
		while (k.m_t != b){
			k.west();
		}
		k.south();
		cout << k.m_e << endl;
	}
}
