Increasingly Strict Sequence

Given a sequence of N integers A = {A[1], A[2], . . . , A[N ]} and all of the integers has an equal number of digits. You are allowed to perform the following operation on the sequence as many times as you wish: Change a single digit from some integer into a different digit. You goal is to obtain a strictly increasing sequence where none of the numbers has a leading zero. What is the minimum number of operations required to achieve this goal? Note that, the input sequence can have numbers with leading zeros. Input The first line contains an integer T (T ≤ 30) denoting the number of test cases. The first line of each test case contains N (1 ≤ N ≤ 50) denoting the number of integers in the input sequence. Each of the next N lines contains an integer containing at most 50 digits. The numbers will contain equal number of digits. Output For each test case, print the answer in the format ‘Case X: Y ’, where X is the serial of the input and Y is the minimum number of operations required to convert the input sequence into a strictly increasing sequence. If it is not possible to achieve this goal, print ‘-1’ Sample Input 2 3 31 21 11 2 135 100 Sample Output Case 1: 2 Case 2: 1