import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class Solution { Scanner in = new Scanner(System.in); int comparison = 0; public static void main(String[] args) { new Solution().solve(); } void solve() { int t = in.nextInt(); for (int T=0; T < t; T++) { int n = in.nextInt(); int c = in.nextInt(); int max = 0; for (int i = 1; i < n; i++) { max += i; } int min = calculateMin(n); //System.out.printf("Min = %d\n",min); //min = n-1; if ((c > max) || (c < min)){ System.out.println(-1); }else { if (( c == min) && (c == max)) { //can only be n=1 System.out.println(1); }else { Integer[] a = new Integer[n]; for (int i = 1; i <= n; i++) { a[i-1]= i; } while (comparison != c){ comparison = 0; shuffleArray(a); lena_sort(a); // System.out.println(comparison); if (comparison == c) { for (int i=0; i < n; i++) { System.out.printf("%d ", a[i]); } System.out.println(); } } } } } } private int calculateMin(int n) { if (n==1) return 0; if (n==0) return 0; if (n==2) return 1; int times = (n-1) /2; return (n-1) + (times * calculateMin(n/2)); } void shuffleArray(Integer[] ar) { // If running on Java 6 or older, use `new Random()` on RHS here Random rnd = new Random(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } } Integer[] lena_sort(Integer[] nums) { if (nums.length <= 1) { return nums; } int pivot = nums[0]; ArrayList less = new ArrayList(); ArrayList more = new ArrayList(); for (int i = 1; i < nums.length; ++i) { // Comparison comparison++; if (nums[i] < pivot) { less.add(nums[i]); } else { more.add(nums[i]); } } Integer []sorted_less_param = new Integer[less.size()]; sorted_less_param = less.toArray(sorted_less_param); Integer []sorted_less= lena_sort(sorted_less_param); Integer []sorted_more_param = new Integer[more.size()]; sorted_more_param = more.toArray(sorted_more_param); Integer []sorted_more = lena_sort(sorted_more_param); Integer [] ans = new Integer[sorted_less.length + sorted_more.length +1]; for (int i = 0; i < sorted_less.length; i++) { ans[i] = sorted_less[i]; } ans[sorted_less.length] = pivot; int j = sorted_less.length + 1; int i = 0; for (; j< ans.length; j++) { ans[j] = sorted_more[i]; i++; } return ans; } }