#P10765. 「CROI · R2」在相思树下 I

「CROI · R2」在相思树下 I

Description

This problem uses multiple test cases.

Xinxin has a sequence from 11 to nn and wants to perform the following two operations:

Operation 1: Delete all elements at odd positions.
Operation 2: Delete all elements at even positions.

After performing kk operations, exactly one number remains. Given the sequence of operations, determine the final remaining number.

Input Format

  • The first line contains a positive integer TT, the number of test cases.
  • For each test case:
    • The first line contains two integers nn and kk.
    • The second line contains kk integers representing the operations (1 for Operation 1, 2 for Operation 2).

Output Format

Output TT lines, each containing the answer for the corresponding test case.

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

Hint

Explanation

Sample Explanation:
For the first test case, the sequence evolves as:
{1,2,3,4,5}{2,4}{4}\{1,2,3,4,5\} \to \{2,4\} \to \{4\}.

Constraints

  • For 30%30\% of the data: n5×105n \leq 5 \times 10^5.
  • For 100%100\% of the data:
    • 1T101 \leq T \leq 10,
    • 1n10181 \leq n \leq 10^{18}.
  • It is guaranteed that exactly one number remains after kk operations for all test cases.