Gholam's Simple Game

No attempts yetTime limit1sMemory limit128 MB

Problem

The floor of Gholam's bedroom is tiled with white and yellow tiles. When he gets bored he stands on one of the tiles and walks along the row he is standing on. He first picks a number of steps nn and then moves one tile at a time in the direction he faces. When he reaches a wall he turns around and keeps walking the other way. He stops once he has taken nn steps. Turning around at a wall does not count as a step. While he walks he counts how many times he steps on a yellow tile.

For example, write Y for a yellow tile and W for a white one, and take the row Y W W Y W Y. If Gholam starts on tile 3 facing right and decides to take 7 steps, he ends up on tile 2. Along the way he steps on a yellow tile three times.

Input

The input holds several test cases. The first line contains the number of test cases TT. Each test case takes two lines.

The first line contains two integers mm (3m1003 \le m \le 100) and nn (1n10001 \le n \le 1000). mm is the number of tiles in the row and nn is the number of steps Gholam takes.

The second line contains mm integers describing the tiles, separated by spaces.

a1 a2 ... am

Each aia_i is 0, 1, 2, or 3. If ai=0a_i = 0, tile ii is yellow, and if ai>0a_i > 0, tile ii is white. If ai=2a_i = 2, Gholam starts on tile ii facing right, and if ai=3a_i = 3, he starts on tile ii facing left. Exactly one of the numbers is 2 or 3. Gholam always starts on a white tile.

Output

For each test case, print on its own line the number of times Gholam steps on a yellow tile.