using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

    public void Proc()
    {
        Dice d = new Dice(Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray());
        int inputCount = int.Parse(Reader.ReadLine());
        System.Text.StringBuilder ans = new System.Text.StringBuilder();
        for (int i = 0; i < inputCount; i++) {
            int[] tmp = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            ans.AppendLine(d.GetRightNum(tmp[0], tmp[1]).ToString());
        }
        Console.Write(ans.ToString());
    }

    private class Dice {
        DiceState state = new DiceState(1, 2, 3);
        public int[] Label;
        public Dice(int[] label) {
            this.Label = label;
        }
        public int GetTopNum() {
            return this.Label[this.state.Top - 1];
        }
        public void Move(String str) {
            foreach(char c in str) {
                if(c == 'N') {
                    this.state = this.Move(this.state, MoveDir.N);
                } else if(c == 'S') {
                    this.state = this.Move(this.state, MoveDir.S);
                } else if( c== 'E') {
                    this.state = this.Move(this.state, MoveDir.E);
                } else {
                    this.state = this.Move(this.state, MoveDir.W);
				}
            }
        }

        public int GetRightNum(int topNum, int frontNum) {
            int topIdx = this.Label.ToList().IndexOf(topNum) + 1;
            int frontIdx = this.Label.ToList().IndexOf(frontNum) + 1;
            int rightIdx = GetRight(topIdx, frontIdx);
            this.state = new DiceState(topIdx, frontIdx, rightIdx);
            return this.Label[rightIdx - 1];
        }

        public static int GetRight(int top, int front) {
            if((top == 1 && front == 2)||(top == 2 && front == 6) || (top == 6 && front == 5) || (top == 5 && front == 1)) {
                return 3;
            }
            if((top == 1 && front == 3) || (top == 3 && front == 6) || (top == 6 && front == 4) || (top == 4 && front == 1)) {
                return 5;
            }
            if((top == 4 && front == 2) || (top == 2 && front == 3) || (top == 3 && front == 5) || (top == 5 && front == 4)) {
                return 1;
            }
            return 7 - GetRight(front, top);
		}

		private DiceState Move(DiceState current, MoveDir md)
		{
			DiceState ret = new DiceState(current.Top, current.Front, current.Rigt);
			if (md == MoveDir.N)
			{
				ret.Top = current.Front;
				ret.Front = 7 - current.Top;
			}
			if (md == MoveDir.S)
			{
				ret.Top = 7 - current.Front;
				ret.Front = current.Top;
			}
			if (md == MoveDir.E)
			{
				ret.Top = 7 - current.Rigt;
				ret.Rigt = current.Top;
			}
            if (md == MoveDir.W)
			{
				ret.Top = current.Rigt;
				ret.Rigt = 7 - current.Top;
			}
			return ret;
		}


	}


    private struct DiceState {
        public int Top;
        public int Front;
        public int Rigt;
        public DiceState(int t, int f, int r) {
            this.Top = t;
            this.Front = f;
            this.Rigt = r;
        }
    }

    enum MoveDir {
        N,
        S,
        E,
        W
    }

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"




1 2 3 4 5 6
3
6 5
1 3
3 2



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 10008