i = gets.split

gets.to_i.times do
  o = gets.split.map { |e| i.index(e) }
  puts n =
  case o
  when [0, 1] then i[2]
  when [0, 2] then i[4]
  when [0, 3] then i[1]
  when [0, 4] then i[3]

  when [1, 0] then i[3]
  when [1, 3] then i[5]
  when [1, 5] then i[2]
  when [1, 2] then i[0]

  when [2, 0] then i[1]
  when [2, 1] then i[5]
  when [2, 5] then i[4]
  when [2, 4] then i[0]

  when [3, 0] then i[4]
  when [3, 4] then i[5]
  when [3, 5] then i[1]
  when [3, 1] then i[0]

  when [4, 0] then i[2]
  when [4, 2] then i[5]
  when [4, 5] then i[3]
  when [4, 3] then i[0]

  when [5, 1] then i[3]
  when [5, 3] then i[4]
  when [5, 4] then i[2]
  when [5, 2] then i[1]
  end
end