You are given a sequence of n positive integers a1, a2, ….., an where 1 ≤ n ≤ 1000 and 1 ≤ ai ≤ 230-1. You have to make the sequence strictly increasing by performing following operation zero or more times:
- Choose an integer ai from the sequence where 1 ≤ i ≤ n.
- And perform ai = ai | (1 << p) where 0 ≤ p ≤ 59.
Here
|
denotes bitwise or operation and1 << p
means 2p.
Now you need to find the minimum number of operations needed to convert the given sequence to a strictly increasing sequence. If it is not possible to make the sequence strictly increasing then output -1.
Input
The first line contains the number of test cases T where 1 ≤ T ≤ 10. Then T test cases follow. The first line of each test case contains n (1 ≤ n ≤ 1000) and the second line contains the sequence of n positive integers. The sum of n over all test cases is not larger than 5000.
Output
Print the case number in a single line followed by the minimum number of operations needed or -1 if there is no solution.
Sample
Sample Input | Sample Output |
---|---|
3 5 5 2 1 3 4 3 1 3 9 2 2 2 | Case 1: 4 Case 2: 0 Case 3: 1 |