Sid the train conductor is having a slow day. Looking for something to do, he sees that
the track ahead of his train splits into tracks. These tracks run parallel for a long
distance, then merge back into a single track later on. Held up by delays, he decides to
seize the opportunity and sort his train.
His train has train cars and each car has a distinct serial number. Starting from the
front of the train, he moves each car into one of the split tracks. Once the cars have
been split up among the tracks, he reassembles the train on the other side. He does this
by repeatedly taking the first car out of one of the split tracks, then adding it to the back
of his sorted train. Note that the train cars must leave a track in the same order they
entered and there is no limit to how many cars a track can hold.
Sid knows this task can be done, however he wants to use as little tracks as possible to not bother anyone else. What is minimum number of tracks that he must use in order to sort the train?
Input Specification
The first line of the input provides the number of test cases,
.
test
cases follow. Each test case begins with the integer
. The next line
contains
integers, with the
number being the serial number of the
wagon from the
front. All of the serial numbers will be between
and
.
Output Specification
For each test case, output the minimum number of tracks that he needs to sort the train.
Sample Input
3
3
3 2 1
5
3 2 4 1 5
8
1 2 3 4 5 6 8 7
Sample Output
3
3
2
Explanation for Sample
In the second test case, Sid only needs tracks. The following is one possible way that the train can be sorted:
Comments