eolymp
bolt
Try our new interface for solving problems
Problems

Crazy old lady

Crazy old lady

The following problem is a variation of a well known puzzle in the Probability theory. There are n seats on a plane and all of the seats are assigned to passengers. Passengers are asked to enter the plane, one at a time, in order of their seats, from 1 to n (the passenger that is assigned seat number 1 enters first, next enters the passenger that is assigned seat number 2, and so on...).

As you might have guessed, queues are too mainstream for a crazy old lady, so she usually goes ahead of everyone and enters first (despite the fact that she might not be assigned the first seat), furthermore she takes some seat that she likes (by chance, it may happen to be her own seat).

After she has taken a seat, the next passengers enter with respect to their seat number (as described above) and take seat as follows:

  • if his/her seat is vacant, then he/she takes this seat.
  • but if his/her seat is already taken, he/she takes any of the remaining seats.

Which seat takes the last passenger? The answer is simple: the last passenger takes either his own seat or the seat of the crazy old lady!

Assume that crazy old lady occupy seat j, which is not her own. When passenger that was assigned the seat j will enter, he/she will have to take some other seat from a set of free seats. This situation then may repeat with next passengers. But when some passenger take the seat of old crazy lady, obviously (!) all of the following passengers take their own seats. In this problem we would like to know the original seat of old crazy lady.

Input

May contain several tests. First line of Input contains the number of tests t (1t10). Each of the next t lines contains n + 1 numbers, separated by space, first is n (1n103), then n numbers follow: the seats taken by passengers in order of their entrance (p1, p2, ..., pn - where pi means that the passenger that was i-th to enter took seat pi). Input is guaranteed to be correct, i.e. to satisfy conditions of the problem statement.

Output

Output the seat of old crazy lady, if it can be determined uniquely, otherwise, output 0.

Time limit 1 second
Memory limit 128 MiB
Input example #1
2
2 2 1
4 2 3 1 4
Output example #1
0
1
Source 2013 IX Zhautykov Olympiad Almaty, Kazakhstan, January 16