num_comparisons = 0 def _non_random_quick_sort(array, start, end): global num_comparisons if end <= start: return num_comparisons += (end-start) pivot_idx = start pivot_item = array[pivot_idx] i, j = start + 1, start + 1 has_moved = False while j <= end: if array[j] < pivot_item: has_moved = True array[i], array[j] = array[j], array[i] array[pivot_idx], array[i] = array[i], array[pivot_idx] pivot_idx = i i = pivot_idx + 1 j += 1 # if not has_moved: # num_comparisons -= comps # recursion up until we hit partition every part _non_random_quick_sort(array, start, pivot_idx-1) # do the same for the left part _non_random_quick_sort(array, pivot_idx+1, end) # do the same for the right part def non_random_quick_sort(array: list): _non_random_quick_sort(array, 0, len(array)-1) return array from itertools import permutations q = int(input()) for _ in range(q): c, comparisonz = [int(p) for p in input().split()] broke = False for array in permutations(list(range(1, c+1))): # sorted_arr = list(sorted(nums)) non_random_quick_sort(list(array)) if num_comparisons == comparisonz: print(' '.join([str(p) for p in array])) broke = True break num_comparisons = 0 if not broke: print(-1) """ array = [i for i in range(1,11)] """ """ array = [2,8,9,3,7,5,10,1,6,4] """