You have N cards valued from 1 to N. The game starts with every card face down in the "initial" position. Three other positions hold cards face up: "goal", "helper" and "pile". A face up card can be moved only while it is on top of one of those three positions. You win once all N cards are on goal in ascending order with N on top.
The rules are as follows.
Find the minimum number of moves of type 4 needed to finish the game.
The first line contains the number of test cases T (1≤T≤100).
Each test case consists of two lines. The first line contains the number of cards N (1≤N≤1000). The second line contains N integers describing the initial deck. The first number is the card at the bottom of the initial deck, and the last number is the card on top, so it is the first one turned over onto pile. The sequence is a permutation of the integers from 1 to N.
For each test case print the minimum number of moves of type 4 needed to win the game, one per line.