#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> 
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main(){
	VI ds(6);
	rep(i,6) cin >>ds[i];
	map<int, int> mp;
	rep(i,6) mp[ds[i]] = i;
	int fx[6][6] ={
		{2,4,5,3}, {4,1,3,6}, {1,5,6,2},
		{1,2,6,5}, {1,4,6,3}, {2,3,5,4}, 
	};
	int n;
	cin >>n;
	rep(g,n){
		int aa, bb;
		cin >>aa >>bb;
		int a=mp[aa]+1, b=mp[bb]+1;
		int ps= -1;
		rep(i, 4){
			if(fx[a-1][i] == b){ ps=i; break;}
		}
		
		cout << ds[fx[a-1][(ps-1+4)%4]-1] <<"\n";
	}
	
	return 0;
}


