#include <iostream>
using namespace std;
typedef long long ll;
const int N = 2e5+9, INF = 0x3f3f3f3f;

int main( void ) {
    ios::sync_with_stdio( false );
    int dt[7];
    for( int i = 1; i <= 6; ++i ) cin >> dt[i];
    int f[7][10] = { {0}, { 0, 2, 3, 5, 4, 2 }, { 0, 6, 3, 1, 4, 6 }, { 0, 1, 2, 6, 5, 1 },
    { 0, 2, 1, 5, 6, 2 }, { 0, 1, 3, 6, 4, 1 }, { 0, 2, 4, 5, 3, 2 } };
    int q, a, b;
    cin >> q;
    while( q-- ) {
        cin >> a >> b;
        int k, h;
        for( int i = 1; i <= 6; ++i ) {
            if( dt[i] == a ) {
                k = i;
            }
            if( dt[i] == b ) {
                h = i;
            }
        }
        for( int i = 1; i <= 4; ++i ) {
            if( f[k][i] == h ) {
                cout << dt[f[k][i + 1]] << '\n';
                break;
            }
        }
    }
    return 0;
}

