d = gets.chomp.split
n = gets.to_i

matrix =
  [[0], [4], [2], [5], [3], [0]],
  [[3], [0], [6], [1], [0], [4]],
  [[5], [1], [0], [0], [6], [2]],
  [[2], [6], [0], [0], [1], [5]],
  [[4], [0], [1], [6], [0], [3]],
  [[0], [3], [5], [2], [4], [0]]

n.times do
  f1, f2 = gets.chomp.split.map(&:to_s)
  s1 = d.find_index f1
  s2 = d.find_index f2
  u = matrix[s2][s1]
  puts d[u[0] - 1]
end

__END__

全パターン
1    2    3    4    5    6
2 3  4 6  1 2  1 5  1 3  2 4
3 5  6 3  2 6  5 6  3 6  4 5
5 4  3 1  6 5  6 2  6 4  5 3
4 2  1 4  5 1  2 1  4 1  3 2

