The great detective Sherlock Holmes has discovered a peculiar cipher machine at the scene of a mysterious crime. The machine contains a double-ended sequence holder with n
number cards, where the i
-th card shows the number ai.
Holmes has deduced that the machine operates on a specific algorithm:
Holmes finds a ledger with q timestamps. Each timestamp mj represents a critical moment in the criminal's plan. To decode the hidden message, Holmes must determine which two cards would be extracted at the start of the mj-th operation cycle.
Input:
5 3 1 2 3 4 5 1 2 10
Output:
1 2 2 3 5 2