#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false


class Dice {
private:
	vector<int> val;
	map<int, int> label;
public:
	Dice(vector<int>& val) : val(val) { 
		for (int i = 0; i < val.size(); i++) {
			label[val[i]] = i + 1;
		}
	}

	void roll(char ch) {
		int &t = val[0], &s = val[1], &e = val[2];
		int &w = val[3], &n = val[4], &b = val[5];
		int tt, ss, ee, ww, nn, bb;
		switch (ch)
		{
		case 'E':
			tt = w; ss = s; ee = t; ww = b; nn = n; bb = e;
			break;
		case 'N':
			tt = s; ss = b; ee = e; ww = w; nn = t; bb = n;
			break;
		case 'S':
			tt = n; ss = t; ee = e; ww = w; nn = b; bb = s;
			break;
		case 'W':
			tt = e; ss = s; ee = b; ww = t; nn = n; bb = w;
			break;
		default:
			break;
		}
		t = tt; s = ss; e = ee; w = ww; n = nn; b = bb;
	}
	void roll(string& S) {
		for (int i = 0; i < S.size(); i++) roll(S[i]);
	}
	int top() { return val[0]; }

	int left(int top, int front) {
		int t = label[top], f = label[front];
		int l;

		if (t == 1) {
			if (f == 2) l = 3;
			else if (f == 3) l = 5;
			else if (f == 4) l = 2;
			else if (f == 5) l = 4;
		}
		else if (t == 2) {
			if (f == 1) l = 4;
			else if (f == 3) l = 1;
			else if (f == 4) l = 6;
			else if (f == 6) l = 3;
		}
		else if (t == 3) {
			if (f == 1) l = 2;
			else if (f == 2) l = 6;
			else if (f == 5) l = 1;
			else if (f == 6) l = 5;
		}
		else if (t == 4) {
			if (f == 1) l = 5;
			else if (f == 2) l = 1;
			else if (f == 5) l = 6;
			else if (f == 6) l = 2;
		}
		else if (t == 5) {
			if (f == 1) l = 3;
			else if (f == 3) l = 6;
			else if (f == 4) l = 1;
			else if (f == 6) l = 4;
		}
		else if (t == 6) {
			if (f == 2) l = 4;
			else if (f == 3) l = 2;
			else if (f == 4) l = 5;
			else if (f == 5) l = 3;
		}

		return val[l - 1];
	}
};

int main()
{
	//clock_t start, end;
	//start = clock();

	vector<int> val(6);
	cin >> val;

	Dice d(val);
	
	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int t, f;
		cin >> t >> f;
		cout << d.left(t, f) << endl;
	}

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}



Measured memory_bytes: 3084