High School Assembly

It’s Saturday morning of a new week and students of National High School have gathered on the central ground for an assembly. At the beginning, students from different classes stand in their own lines. Then the class teachers of each class move over from front to back and organize the line according to the increasing order of students’ heights. They can pick a student from any position and send him to the end of the line. Mr. Kapono Khan is the class teacher of 7th grade. He doesn’t like this job of walking along the line back and forth. So he wants to organize the students with minimal number of moves. As usual, you are here to help Mr. Khan. Given the heights of each student of his class, your job is to find out minimum number of moves required to sort the students based on the increasing order of their heights. Picking up a student from any position and sending him to the end is defined as a move for this problem. Luckily students of his class have unique heights. Input There will be T test cases, (T ≤ 100). Input for each case will start with an integer, n (1 ≤ n ≤ 104) which represents the number of students of the class. Then an array of n integers will follow where 1 ≤ Hi ≤ n and each height is unique. Output For each case, print case number using the format ‘Case x: ’ (without quotes) followed by an integer showing minimum number of moves required to sort the line in increasing order. Explanation of Sample I/O Case 1: move 3 to last, move 4 to last, move 5 to last. Sample Input 2 5 51324 9 451263897 Sample Output Case 1: 3 Case 2: 6