#P1649A. Game
Game
Description
You are playing a very popular computer game. The next level consists of consecutive locations, numbered from to , each of them containing either land or water. It is known that the first and last locations contain land, and for completing the level you have to move from the first location to the last. Also, if you become inside a location with water, you will die, so you can only move between locations with land.
You can jump between adjacent locations for free, as well as no more than once jump from any location with land to any location with land , spending coins ().
Your task is to spend the minimum possible number of coins to move from the first location to the last one.
Note that this is always possible since both the first and last locations are the land locations.
There are several test cases in the input data. The first line contains a single integer () — the number of test cases. This is followed by the test cases description.
The first line of each test case contains one integer () — the number of locations.
The second line of the test case contains a sequence of integers (), where means that the -th location is the location with land, and means that the -th location is the location with water. It is guaranteed that and .
For each test case print a single integer — the answer to the problem.
Input
There are several test cases in the input data. The first line contains a single integer () — the number of test cases. This is followed by the test cases description.
The first line of each test case contains one integer () — the number of locations.
The second line of the test case contains a sequence of integers (), where means that the -th location is the location with land, and means that the -th location is the location with water. It is guaranteed that and .
Output
For each test case print a single integer — the answer to the problem.
Note
In the first test case, it is enough to make one free jump from the first location to the second one, which is also the last one, so the answer is .
In the second test case, the only way to move from the first location to the last one is to jump between them, which will cost coins.
In the third test case, you can jump from the first location to the third for coins, and then jump to the fourth location for free, so the answer is . It can be shown that this is the optimal way.