#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}
// mod 1000000007 の世界で a += b する関数
int n;
int bit[100010];
void add(int v, int x) {

	while (v <= n)
	{
		bit[v] += x;
		v += v & -v;
	}
}

ll sum(int v) {
	ll r = 0;
	while (v > 0)
	{
		r += bit[v];
		v -= v & -v;
	}
	return r;
}
class Dice {

public :
	int u, s, e, w, n, d;
	Dice(int u, int s, int e, int w, int n, int d) : u(u),s(s),e(e),w(w),n(n),d(d){
	}
	void cp(int _u, int _s, int _e, int _w, int _n, int _d) {
		u = _u;
		s = _s;
		e = _e;
		w = _w;
		n = _n;
		d = _d;
	}
	void swicth(char c) {
		if (c == 'S') {
			cp(n, u, e, w, d, s);
		}
		else if (c == 'E') {
			cp(w, s, u, d, n, e);
		}
		else if (c == 'W') {
			cp(e, s, d, u, n, w);
		}
		else if (c == 'N') {
			cp(s, d, e, w, u, n);
		}
	}
	void left() {
		cp(u,w,s,n,e,d);
	}
	void right() {
		cp(u,e,n,s,w,d);
	}
	void ck(int _u,int _s){
		if (_u == d) {
			locate("SS");
		}
		else if (_u == s) {
			locate("N");
		}
		else if (_u == e) {
			locate("W");
		}
		else if (_u == n) {
			locate("S");
		}
		else if (_u == w) {
			locate("E");
		}
		
		if (_s == e) {
			right();
		}
		else if (_s == n) {
			right();
			right();
		}
		else if (_s == w) {
			left();
		}
	}

	void locate(string s){
		for (size_t i = 0; i < s.size(); i++)
		{
			swicth(s[i]);
		}
	}
};
void solv() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	Dice di(a, b, c, d, e, f);
	int q;
	cin >> q;
	for (size_t i = 0; i < q; i++)
	{
		int a, b;
		cin >> a >> b;
		di.ck(a, b);
		cout << di.e << endl;
	}

}


int main() {
	//	COMinit();
	solv();

	return 0;
}



Measured memory_bytes: 3148