CodeChef PESU ECC Chapter
00:00Log in

Sorted Deletion

Medium1s limit256 MB

Shlok is playing a game on an array a of n positive integers. During each turn:

  • If a is non-decreasing, the game ends.
  • Otherwise, he can choose any single element and remove it from the array.

Determine the minimum possible number of elements that can remain in the array after the game ends.

An array a of length m is non-decreasing if a_i <= a_{i+1} for all 1 <= i <= m-1. A single remaining element is always trivially non-decreasing.

Input Format

The first line contains a single integer t (1 <= t <= 1000) — the number of test cases.

For each test case:

The first line contains an integer n (1 <= n <= 10) — the length of the array.

The second line contains n integers a_1, a_2, ..., a_n (1 <= a_i <= 100) — the elements of the array.

Output Format

For each test case, output a single integer: the minimum possible number of elements left in the array once it is non-decreasing.

Constraints

1 <= t <= 1000

1 <= n <= 10

1 <= a[i] <= 100

Sample

Input
3
4
1 4 2 3
1
100
2
6 7
Output
1
1
2

Explanation

In the first test case, the array [1, 4, 2, 3] is not sorted, so it can be reduced down to a single element. In the second test case, the array already has one element, so it stays as is. In the third test case, [6, 7] is already non-decreasing, so no elements need to be removed.

Code
Loading editor…
Auto-savedC++
Case 1using sample

Run uses this input. Submit always judges the hidden tests.