Under construction

Still being built. Things may change

Malvika gets bored along with her Cats

Time limit1sMemory limit1024 MB

Summary
Given bar lengths in a row, find the fewest picks needed to eat every bar, where each pick also eats all bars forming an inversion with the picked bar.
Level

Medium6 of 10

Topics
Array, Greedy
Solved
No attempts yet

Problem

Malvika's cats, Chingam and Jimma, are also bored of solving problems. Fortunately, Chingam has found nn dark chocolate bars. They all have the same width but differ in length, and no two bars have the same length. The bars are kept in a row, with lengths L1,L2,…,LnL_1, L_2, \ldots, L_n from left to right. That is, bar ii has length LiL_i.

Chingam decided to play a small game with Jimma. In one step, Jimma chooses a bar that has not been eaten yet. Chingam hates inversions, so he instantly eats that bar, along with every other bar that forms an inversion pair with it. Bars ii and jj form an inversion pair when the bar on the left is longer than the bar on the right.

So if Jimma selects bar ii, Chingam eats bar ii, every bar jj with j>ij > i and Lj<LiL_j < L_i, and every bar kk with k<ik < i and Lk>LiL_k > L_i. Then the step ends, and the next step begins with Jimma selecting another bar. The process repeats until all nn bars are eaten.

Jimma does not like this game because she gets no chocolate. So she wants to finish it as soon as possible and go back to sleep. Find the minimum number of steps needed for the game to end.

Input

The first line contains a single integer TT, the number of test cases.

The first line of each test case contains one integer nn.

The second line contains nn space-separated integers L1,L2,…,LnL_1, L_2, \ldots, L_n.

Output

For each test case, output a single integer on its own line: the minimum number of steps needed for the game to end.

Constraints

  • 1≤T≤51 \le T \le 5
  • 1≤n≤1051 \le n \le 10^5
  • 1≤Li≤n1 \le L_i \le n

Hint

In the first step, Jimma can choose bar 4, which has length 2. Bars 3 and 1 form inversion pairs with bar 4, so Chingam eats all three bars. In the second step, Jimma chooses bar 2, and the game ends. You can check that Jimma cannot remove all four bars in one step.

Examples1

  1. Example 1

    Input
    1
    4
    3 1 4 2
    
    Expected output
    2