Just Some Permutations

Dexter considers a permutation of first N positive numbers (1, 2, ..., N) beautiful if all the absolute differences between adjacent numbers in the permutation are distinct. So for N = 4: {3, 2, 4, 1} is a beautiful permutation because the absolute differences are {1, 2, 3}. But {3, 1, 4, 2} is not beautiful since the absolute differences {2, 3, 2} are not distinct. Given N and K find the lexicographically K-th smallest beautiful permutation of the first N pos- itive numbers. A permutation of N numbers A1, A2, ..., An is lexicographically smaller than another permutationB1,B2,...,Bn ifAi <Bi forsomeiandAj =Bj forallj<i. Input First line of the input contains an integer T (≤ 1000) which is the number of test cases. Each of the next T lines contain two space separated integers N (1 < N < 20) and K (1 ≤ K ≤ 109). Output For each test case output the case number and then N space separated integers which is the lexico- graphically K-th smallest beautiful permutation of first N positive numbers. If there are less than K beautiful permutations then output ‘-1’. See sample output for exact formatting. Sample Input 4 51 52 54 5 10 Sample Output Case 1: 1 5 2 4 3 Case 2: 2 3 5 1 4 Case 3: 3 2 4 1 5 Case 4: -1