#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define BR "\n"

vector<int> face(6);
void rotate(char d) {
  vector<int> newFace(6);
  newFace = face;
  if (d == 'N') {
    newFace[0] = face[1];
    newFace[1] = face[5];
    newFace[5] = face[4];
    newFace[4] = face[0];
  } else if (d == 'S') {
    newFace[0] = face[4];
    newFace[1] = face[0];
    newFace[5] = face[1];
    newFace[4] = face[5];
  } else if (d == 'E') {
    newFace[0] = face[3];
    newFace[2] = face[0];
    newFace[5] = face[2];
    newFace[3] = face[5];
  } else if (d == 'W') {
    newFace[0] = face[2];
    newFace[2] = face[5];
    newFace[5] = face[3];
    newFace[3] = face[0];
  }
  face = newFace;
}

int main() {
  rep0(i, 6) cin >> face[i];
  int q; cin >> q;

  string s = "NEWS";

  rep0(i, q) {
    int u, f;
    cin >> u >> f;
    while (true) {
      char c = s[rand() % 4];
      rotate(c);
      if (face[0] == u && face[1] == f) {
        cout << face[2] << BR;
        break;
      }
    }
  }

  return 0;
}
