#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const vector<vector<int>> D = {
    {4, 0, 2, 3, 5, 1}, // N
    {2, 1, 5, 0, 4, 3}, // E
    {1, 5, 2, 3, 0, 4}, // S
    {3, 1, 0, 5, 4, 2}  // W
};

struct Dice {
  vector<int> face;

  Dice(vector<int> v) : face(v) {
  }

  void roll(char direction) {
    int dir;
    if (direction == 'N')
      dir = 0;
    if (direction == 'E')
      dir = 1;
    if (direction == 'S')
      dir = 2;
    if (direction == 'W')
      dir = 3;

    vector<int> tmp(6);
    rep(i, tmp.size()) tmp[D[dir][i]] = face[i];
    face = tmp;
  }

  int top() {
    return face.front();
  }
  int bottom() {
    return face.back();
  }
};

int main() {
  vector<int> v(6);
  rep(i, 6) cin >> v[i];
  Dice d(v);

  int q;
  cin >> q;
  rep(i, q) {
    int t, f;
    cin >> t >> f;

    if (d.top() != f && d.bottom() != f)
      d.roll('N');
    while (d.top() != f)
      d.roll('E');
    d.roll('S');
    while (d.top() != t)
      d.roll('E');
    d.roll('W');
    cout << d.top() << endl;
  }
}
