Stacking Books

No attempts yetTime limit1sMemory limit128 MB

Problem

Sunyoung keeps books of various sizes stored as a single stack. Reading the stack from the top downward, if the sizes never decrease (that is, the books are arranged in non-decreasing order of size from top to bottom), the stack is said to be stable. Otherwise the stack may topple.

To keep the stack from toppling, Sunyoung wants to sort the books by size. In one operation she pulls a single book out of the middle or the very bottom of the stack and places it on top. However, at that moment the part of the stack lying above the book she removes must be stable.

For example, a stack piled as $3, 4, 1, 2$ from the top can be sorted by size ($1, 2, 3, 4$ from the top) in three operations, and the minimum number of operations needed is $3$.

Given the current arrangement of the books, write a program that finds the minimum number of operations required to make the stack stable.

Input

The first line contains the number of test cases $T$. ($T \le 100$)

Each test case consists of two lines. The first line contains the number of books $n$ ($1 \le n \le 50$), and the second line contains the sizes $s_i$ of the books in order from the top of the stack to the bottom. ($1 \le s_i \le 1000$)

Output

For each test case, print on its own line the minimum number of operations required to make the stack stable.