CF1956A.Nene's Game

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Nene's Game

Nene invented a new game based on an increasing sequence of integers a1,a2,,aka_1, a_2, \ldots, a_k.

In this game, initially nn players are lined up in a row. In each of the rounds of this game, the following happens:

  • Nene finds the a1a_1-th, a2a_2-th, \ldots, aka_k-th players in a row. They are kicked out of the game simultaneously. If the ii-th player in a row should be kicked out, but there are fewer than ii players in a row, they are skipped.

Once no one is kicked out of the game in some round, all the players that are still in the game are declared as winners.

For example, consider the game with a=[3,5]a=[3, 5] and n=5n=5 players. Let the players be named player A, player B, \ldots, player E in the order they are lined up initially. Then,

  • Before the first round, players are lined up as ABCDE. Nene finds the 33-rd and the 55-th players in a row. These are players C and E. They are kicked out in the first round.
  • Now players are lined up as ABD. Nene finds the 33-rd and the 55-th players in a row. The 33-rd player is player D and there is no 55-th player in a row. Thus, only player D is kicked out in the second round.
  • In the third round, no one is kicked out of the game, so the game ends after this round.
  • Players A and B are declared as the winners.

Nene has not yet decided how many people would join the game initially. Nene gave you qq integers n1,n2,,nqn_1, n_2, \ldots, n_q and you should answer the following question for each 1iq1 \le i \le q independently:

  • How many people would be declared as winners if there are nin_i players in the game initially?

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t2501 \le t \le 250). The description of test cases follows.

The first line case contains two integers kk and qq (1k,q1001 \le k, q \le 100) — the length of the sequence aa and the number of values nin_i you should solve this problem for.

The second line contains kk integers a1,a2,,aka_1,a_2,\ldots,a_k (1a1<a2<<ak1001\leq a_1 \lt a_2 \lt \ldots \lt a_k\leq 100) — the sequence aa.

The third line contains qq integers n1,n2,,nqn_1,n_2,\ldots,n_q (1ni1001\leq n_i \leq 100).

Output

For each test case, output qq integers: the ii-th (1iq1\le i \le q) of them should be the number of players declared as winners if initially nin_i players join the game.

Note

The first test case was explained in the statement.

In the second test case, when n=1n=1, the only player stays in the game in the first round. After that, the game ends and the only player is declared as a winner.

Samples

6
2 1
3 5
5
5 3
2 4 6 7 9
1 3 5
5 4
3 4 5 6 7
1 2 3 4
2 3
69 96
1 10 100
1 1
100
50
3 3
10 20 30
1 10 100
2 
1 1 1 
1 2 2 2 
1 10 68 
50 
1 9 9 

在线编程 IDE

建议全屏模式获得最佳体验