Seiji Maki doesn't only like to observe relationships being unfolded, he also likes to observe sequences of numbers, especially permutations. Today, he has his eyes on almost sorted permutations.

A permutation $a_1, a_2, \dots, a_n$ of $1, 2, \dots, n$ is said to be almost sorted if the condition $a_{i + 1} \ge a_i - 1$ holds for all $i$ between $1$ and $n - 1$ inclusive.

Maki is considering the list of all almost sorted permutations of $1, 2, \dots, n$, given in lexicographical order, and he wants to find the $k$-th permutation in this list. Can you help him to find such permutation?

Permutation $p$ is lexicographically smaller than a permutation $q$ if and only if the following holds:

in the first position where $p$ and $q$ differ, the permutation $p$ has a smaller element than the corresponding element in $q$.


-----Input-----

The first line contains a single integer $t$ ($1\le t\le 1000$) — the number of test cases.

Each test case consists of a single line containing two integers $n$ and $k$ ($1 \le n \le 10^5$, $1 \le k \le 10^{18}$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case, print a single line containing the $k$-th almost sorted permutation of length $n$ in lexicographical order, or $-1$ if it doesn't exist.


-----Examples-----

Input
5
1 1
1 2
3 3
6 5
3 4
Output
1 
-1
2 1 3 
1 2 4 3 5 6 
3 2 1


-----Note-----

For the first and second test, the list of almost sorted permutations with $n = 1$ is $\{[1]}$.

For the third and fifth test, the list of almost sorted permutations with $n = 3$ is $\{[1, 2, 3], [1, 3, 2], [2, 1, 3], [3, 2, 1]}$.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Sorting

Combinatorics

Implementation

Constructive algorithms


Solutions:
import sys
import itertools
input = sys.stdin.readline

def solve(N, K):
	if K > 1 << N - 1:
		return [-1]
	left = 1
	right = N + 1
	ret = []
	while right > left:
		r = right - left
		block = 1
		while 1 << max(0, r - 1 - block) < K:
			K -= 1 << max(0, r - 1 - block)
			block += 1
		ret.extend(range(left, left + block)[::-1])
		left += block
	return ret

def main():
	(T,) = map(int, input().split())
	for _ in range(T):
		(N, K) = map(int, input().split())
		print(' '.join(map(str, solve(N, K))))
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = bin(k - 1)[2:]
	if k - 1 > 0:
		b += '0'
	if len(b) > n:
		print(-1)
	else:
		b = '0' * (n - len(b)) + b
		(p, temp) = ([], [])
		for i in range(n):
			temp += [str(i + 1)]
			if b[i] == '0':
				p += temp[::-1]
				temp = []
		print(*p)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if n < 70 and pow(2, n - 1) < k:
		print(-1)
		continue
	k -= 1
	k = bin(k)[2:].zfill(n - 1)
	l = []
	cnt = 1
	for i in range(n - 1):
		if k[i] == '1':
			cnt += 1
		else:
			l.append(cnt)
			cnt = 1
	l.append(cnt)
	idx = 0
	res = [0] * n
	for x in l:
		for i in range(idx, idx + x):
			res[i] = idx * 2 + x - i
		idx += x
	print(*res)


import time
import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string, heapq as h
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def getInt():
	return int(input())

def getStrs():
	return input().split()

def getInts():
	return list(map(int, input().split()))

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def getBin():
	return list(map(int, list(input())))

def isInt(s):
	return '0' <= s[0] <= '9'

def ceil_(a, b):
	return a // b + (a % b > 0)
MOD = 10 ** 9 + 7
num = [1]
tot = 1
while tot <= 4 * 10 ** 18:
	num.append(tot)
	tot += num[-1]

def solve2(n, k, start):
	if not n:
		return []
	if n == 1:
		return [start]
	lst = start
	rng = num[n]
	while k > rng // 2 and rng:
		k -= rng // 2
		lst += 1
		rng //= 2
	if not rng:
		lst = start + n - 1
	return list(range(lst, start - 1, -1)) + solve2(n - (lst - start + 1), k, lst + 1)

def solve():
	(N, K) = getInts()
	ans = []
	curr = 1
	while N >= len(num):
		ans.append(curr)
		curr += 1
		N -= 1
	if K > num[N]:
		print(-1)
		return
	ans += solve2(N, K, curr)
	print(*ans)
	return
for _ in range(getInt()):
	solve()


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	v = bin(k - 1)[2:]
	if k > 1:
		v += '0'
	if len(v) > n:
		print(-1)
		continue
	v = v.rjust(n, '0')
	a = []
	t = []
	for i in range(n):
		t += (str(i + 1),)
		if v[i] < '1':
			a += t[::-1]
			t = []
	print(*a)


def reverse(arr, i, j):
	while i < j:
		temp = arr[i]
		arr[i] = arr[j]
		arr[j] = temp
		i += 1
		j -= 1
	return

def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, k) = readIntArr()
		if n <= 62 and k > pow(2, n - 1):
			allans.append([-1])
		else:
			ans = list(range(1, n + 1))
			i = 0
			while i < n:
				j = i
				cnts = 0
				while n - 2 - j <= 62 and cnts + pow(2, n - 2 - j) < k and (j + 1 < n):
					cnts += pow(2, n - 2 - j)
					j += 1
				k -= cnts
				reverse(ans, i, j)
				i = j + 1
			allans.append(ans)
	multiLineArrayOfArraysPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


def dfs(l, r, k, dir):
	if l == r:
		dir.append(1)
		return
	mid = l + r >> 1
	if k > mid:
		dir.append(-1)
		dfs(mid + 1, r, k, dir)
	else:
		dir.append(1)
		dfs(l, mid, k, dir)

def test():
	(n, k) = [int(i) for i in input().split()]
	if 2 ** (n - 1) < k:
		return -1
	dir = [0]
	x = n
	while x > 64:
		x -= 1
		dir.append(1)
	dfs(1, 2 ** (x - 1), k, dir)
	result = []
	buf = []
	i = 1
	while i <= n:
		if dir[i] == 1:
			result.append(i)
			i += 1
		else:
			j = i
			while j <= n and dir[j] == -1:
				j += 1
			result += list(range(j, i - 1, -1))
			i = j + 1
	return ' '.join([str(i) for i in result])
t = int(input())
while t > 0:
	t -= 1
	print(test())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	val = bin(k - 1)[2:]
	if k - 1:
		val += '0'
	if len(val) > n:
		print(-1)
	else:
		val = '0' * (n - len(val)) + val
		ans = []
		t = []
		for i in range(n):
			t += [str(i + 1)]
			if val[i] == '0':
				ans += t[::-1]
				t = []
		print(*ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	f = bin(k - 1)[2:]
	if k - 1:
		f += '0'
	if len(f) > n:
		print('-1')
		continue
	f = '0' * (n - len(f)) + f
	ans = []
	arr = []
	for i in range(n):
		arr += [i + 1]
		if f[i] == '0':
			ans += arr[::-1]
			arr = []
	print(*ans)


from sys import stdin

def read_int():
	return int(stdin.readline())

def read_ints():
	return map(int, stdin.readline().split(' '))
t = read_int()
for case_num in range(t):
	(n, k) = read_ints()
	hi = 1 << min(n - 1, 60)
	if k > hi:
		print(-1)
	else:
		ans = []
		base = 0
		now = 0
		if n > 61:
			base = n - 61
			ans += [i for i in range(1, n - 60)]
			n = 61
		while k > 0:
			if k == 1 << n - 1:
				ans += [base + n - i for i in range(n)]
				break
			for i in range(1, n):
				if k > 1 << n - i - 1:
					k -= 1 << n - i - 1
				else:
					ans += [base + i - j for j in range(i)]
					base += i
					n -= i
					break
		print(' '.join(map(str, ans)))


def dfs(x, n, k):
	if x > n:
		return []
	if k == 0:
		return [i for i in range(x, n + 1)]
	if n - x > 64:
		buf = []
		while n - x > 64:
			buf += [x]
			x += 1
		return buf + dfs(x, n, k)
	if 2 ** (n - x) == k + 1:
		return [i for i in range(n, x - 1, -1)]
	buf = [x]
	x += 1
	cnt = 2 ** (n - x)
	while k >= cnt:
		buf += [x]
		x += 1
		k -= cnt
		cnt //= 2
	return buf[::-1] + dfs(x, n, k)

def test():
	(n, k) = [int(i) for i in input().split()]
	if 2 ** (n - 1) < k:
		return -1
	return ' '.join([str(i) for i in dfs(1, n, k - 1)])
t = int(input())
while t > 0:
	t -= 1
	print(test())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	cnt = 0
	pow2 = 1
	ans = []
	fn = 1
	ln = 1
	while k > pow2:
		pow2 *= 2
		cnt += 1
	if cnt > n - 1:
		print(-1)
	else:
		k -= 1
		filled = 0
		while filled < n:
			c = filled + 1
			if n - c - 1 < 66:
				while k >= pow(2, n - c - 1):
					fn += 1
					k -= pow(2, n - c - 1)
					c += 1
				tmp = fn
				while tmp >= ln:
					ans.append(tmp)
					filled += 1
					tmp -= 1
				fn += 1
				ln = fn
			else:
				ans.append(fn)
				fn += 1
				filled += 1
				ln = fn
		for i in ans:
			print(i, end=' ')
		print()


import sys, os
if os.environ['USERNAME'] == 'kissz':
	inp = open('in.txt', 'r').readline

	def debug(*args):
		print(*args, file=sys.stderr)
else:
	inp = sys.stdin.readline

	def debug(*args):
		pass
for _ in range(int(inp())):
	(n, k) = map(int, inp().split())
	if k > 2 ** (n - 1):
		print(-1)
	else:
		b = bin(k - 1)[2:].zfill(n)
		L = []
		for i in range(n):
			if b[i] == '1':
				L += [L[-1] - 1]
			elif i < n - 1 and b[i + 1] == '1':
				j = i + 1
				cnt = 0
				while j < n and b[j] == '1':
					cnt += 1
					j += 1
				L += [i + 1 + cnt]
			else:
				L += [i + 1]
		print(*L)


import io
import os
from collections import Counter, defaultdict, deque
import itertools

def solve1(N, K):
	good = []
	for perm in itertools.permutations(range(1, N + 1)):
		if all((y >= x - 1 for (x, y) in zip(perm, perm[1:]))):
			good.append(perm)
	good.sort()
	K -= 1
	if K >= len(good):
		return -1
	return ' '.join(map(str, good[K]))
from heapq import heappush, heappop, heapify

def solve(N, K):
	K -= 1
	M = 1 << N - 1
	if K >= M:
		return -1
	remain = list(range(1, N + 1))
	heapify(remain)
	ans = []
	k = K
	while remain:
		bits = (1 << len(remain) - 1) - 1 - k
		keep = bits.bit_length()
		ret = []
		assert len(remain) - keep
		for i in range(len(remain) - keep):
			ret.append(heappop(remain))
		ret = ret[::-1]
		mask = 1 << keep
		ans.extend(ret)
		k = k % mask
	return ' '.join(map(str, ans))
DEBUG = False
if DEBUG:
	import random
	random.seed(0)
	for N in range(1, 10):
		for K in range(1, (1 << N) + 1):
			print()
			print(N, K)
			ans = solve(N, K)
			ans1 = solve1(N, K)
			print(repr(ans), repr(ans1))
			assert ans == ans1
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, K) = [int(x) for x in input().split()]
	ans = solve(N, K)
	print(ans)


it = int(input())
for _ in range(it):
	(n, k) = map(int, input().split())
	if n < 64 and 2 ** (n - 1) < k:
		print(-1)
	else:
		l = n
		c = 1
		ans = []
		while l > 0:
			z = 1
			while k > 1 and k > 2 ** (l - z - 1):
				k -= 2 ** (l - z - 1)
				z += 1
			ans += list(range(c + z - 1, c - 1, -1))
			c += z
			l -= z
			z = 1
		ans = [str(x) for x in ans]
		print(' '.join(ans))


import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def N():
	return int(inp())

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def testcase(t):
	for p in range(t):
		solve()

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[start:start + _load] for start in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for start in range(len(_fen_tree)):
			if start | start + 1 < len(_fen_tree):
				_fen_tree[start | start + 1] += _fen_tree[start]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		A = 0
		while end:
			A += _fen_tree[end - 1]
			end &= end - 1
		return A

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
pow2 = [1]
for i in range(67):
	pow2.append(pow2[-1] * 2)

def solve():
	(n, k) = sep()
	ans = []
	S = SortedList()
	if n > 66:
		for i in range(1, n - 66):
			ans.append(i)
		for i in range(n - 66, n + 1):
			S.add(i)
	else:
		for i in range(1, n + 1):
			S.add(i)
	while k > 0 and S:
		le = len(S)
		if k == pow2[le - 1]:
			while S:
				ans.append(S[-1])
				S.remove(S[-1])
			k = 0
			break
		if k > pow2[le - 1]:
			print(-1)
			return
		for l in range(le, 1, -1):
			t = pow2[l - 2]
			if k <= t:
				tor = le - l
				while tor >= 0:
					ans.append(S[tor])
					S.remove(S[tor])
					tor -= 1
				break
			else:
				k -= t
	if k > 0:
		print(-1)
		return
	print(*ans)
testcase(N())


import sys, io, os
try:
	Z = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
except:
	Z = lambda : sys.stdin.readline().encode()
O = []
for _ in range(int(Z())):
	(n, k) = map(int, Z().split())
	k -= 1
	if k.bit_length() >= n:
		O.append('-1')
		continue
	if n < 2:
		O.append('1')
		continue
	r = []
	low = 0
	c = 1
	s = bin(k)[2:].rjust(n - 1, '0')
	for i in s:
		if i == '1':
			c += 1
		else:
			for j in range(low + c, low, -1):
				r.append(j)
			low += c
			c = 1
	for j in range(low + c, low, -1):
		r.append(j)
	O.append(' '.join(map(str, r)))
print('\n'.join(O))


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	if K <= 2 ** min(N - 1, 100):
		K -= 1
		S = [i + 1 for i in range(N - 1) if K >> N - 2 - i & 1 == 0] + [N]
		T = []
		ma = 0
		for s in S:
			T.append(s)
			if s > ma:
				for i in range(ma + 1, s)[::-1]:
					T.append(i)
				ma = s
		print(*T)
	else:
		print(-1)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10)]
pp = [0] * 10

def SieveOfEratosthenes(n=10):
	p = 2
	c = 0
	while p * p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				pp[i] += 1
				prime[i] = False
		p += 1

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[n - 1]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = arr[mid]
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[0]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = arr[mid]
			left = mid + 1
	return res
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = []
	copy = k
	k -= 1
	while k:
		a.append(k % 2)
		k //= 2
	a = a[::-1]
	d = max(0, n - len(a) - 1)
	a = [0] * d + a + [0]
	if len(a) > n:
		print(-1)
		continue
	curr = 1
	res = [0] * n
	for i in range(n):
		if a[i] == 0:
			j = i
			while j >= 0 and res[j] == 0:
				res[j] = curr
				curr += 1
				j -= 1
	print(*res)


def gen(n):
	from itertools import permutations
	count = 0
	for perm in permutations(range(1, n + 1)):
		for i in range(n - 1):
			if perm[i + 1] >= perm[i] - 1:
				continue
			else:
				break
		else:
			count += 1
			print(perm)
	return count
from sys import stdin, stdout
tc = int(stdin.readline())
for _ in range(tc):
	(n, k) = map(int, stdin.readline().split())
	if k > 1 << n - 1:
		stdout.write('-1\n')
		continue
	n_copy = n
	ans = []
	k -= 1
	n -= 1
	fr = 1
	to = 1
	while len(ans) < n_copy and k:
		divider = float('inf') if n == 0 else 1 << n - 1
		shift = 0
		while k >= divider:
			n -= 1
			divider += float('inf') if n == 0 else 1 << n - 1
			shift += 1 << n
			to += 1
		k -= shift
		for i in range(to, fr - 1, -1):
			ans.append(i)
		n -= 1
		to += 1
		fr = to
	for i in range(len(ans) + 1, n_copy + 1):
		ans.append(i)
	stdout.write(' '.join(map(str, ans)))
	stdout.write('\n')


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if n < 100 and 1 << n - 1 < k:
			print(-1)
			continue
		k -= 1
		ans = [0] * (n - 1)
		cnt = 0
		while k:
			ans[cnt] = k % 2
			k //= 2
			cnt += 1
		ans.reverse()
		rAns = []
		stack = [1]
		for i in range(n - 1):
			if ans[i]:
				stack.append(i + 2)
			else:
				while stack:
					rAns.append(stack.pop())
				stack.append(i + 2)
		while stack:
			rAns.append(stack.pop())
		print(' '.join(map(str, rAns)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	k -= 1
	out = []
	curr = [1]
	todo = []
	for i in range(n - 1):
		todo.append(k % 2)
		k //= 2
	todo.reverse()
	for i in range(n - 1):
		if todo[i]:
			curr.append(i + 2)
		else:
			while curr:
				out.append(curr.pop())
			curr.append(i + 2)
	while curr:
		out.append(curr.pop())
	if k == 0:
		print(' '.join(map(str, out)))
	else:
		print(-1)


import sys
input = iter(sys.stdin.read().splitlines()).__next__

def solve():
	(n, k) = map(int, input().split())
	if k > 2 ** (n - 1):
		return -1
	head = []
	prev_max = 0
	k_bits = bin(k - 1)[2:]
	k_bits = '0' * (n - 1 - len(k_bits)) + k_bits
	for (i, bit) in enumerate(k_bits):
		if bit == '0':
			head.append(i + 1)
			for j in range(i, prev_max, -1):
				head.append(j)
			prev_max = i + 1
	for j in range(n, prev_max, -1):
		head.append(j)
	return ' '.join(map(str, head))
t = int(input())
output = []
for _ in range(t):
	output.append(solve())
print(*output, sep='\n')


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(n, k) = R()
	f = bin(k - 1)[2:]
	if k - 1:
		f += '0'
	if len(f) > n:
		print(-1)
		continue
	f = '0' * (n - len(f)) + f
	arr = []
	ans = []
	for i in range(n):
		arr += (i + 1,)
		if f[i] == '0':
			ans += arr[::-1]
			arr = []
	print(*ans)


def leftmost_off(num):
	last_off = 0
	i = 1
	while num != 0:
		if num & 1 == 0:
			last_off = i
		i += 1
		num >>= 1
	return last_off

def get_start(num, n):
	power2 = int((1 << n - 1) // 2)
	p2 = power2
	i = 0
	offset = 0
	l = 0
	if power2 == 0:
		return (1, 0, 0)
	while num > 0:
		offset += l
		l = power2
		num -= power2
		power2 >>= 1
		i += 1
		if power2 == 0:
			power2 = 1
	return (i, offset, p2)

def almost_sorted_lexi(n, pos):
	b = 1
	e = n
	res = ''
	tmp = 0
	while b <= n:
		(start, offset, power2) = get_start(pos, e - b + 1)
		cnt = 0
		while power2 > pos and b <= n:
			res += str(b) + ' '
			b += 1
			cnt += 1
			power2 >>= 1
		if cnt != 0:
			tmp += cnt
			continue
		tmp += start
		start = tmp
		while start >= b:
			res += str(start) + ' '
			start -= 1
		b = tmp + 1
		pos -= offset
	print(res)

def main():
	t = int(input(''))
	for i in range(t):
		(n, k) = tuple(map(int, input('').split(' ')))
		if k > 1 << n - 1:
			print('-1')
		elif n == 1:
			print('1')
		else:
			almost_sorted_lexi(n, k)
main()


import sys
r = sys.stdin.readline
for _ in range(int(r())):
	(n, k) = map(int, r().split())
	if k > 1 << n - 1:
		print(-1)
		continue
	ans = []
	i = 1
	while i <= n:
		l = 0
		while i < n and 1 << n - i - 1 < k:
			k -= 1 << n - i - 1
			l += 1
			i += 1
		for j in range(i, i - l - 1, -1):
			ans.append(j)
		i += 1
	print(*ans)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		(N, K) = map(int, input().split())
		if N == 1:
			if K == 1:
				print(1)
			else:
				print(-1)
			continue
		cnt = 1
		ok = 0
		for _ in range(N - 1):
			cnt *= 2
			if cnt >= K:
				ok = 1
				break
		if not ok:
			print(-1)
			continue
		K -= 1
		skip = [0] * (N + 1)
		for i in range(N - 1):
			if K >> i & 1:
				skip[N - 1 - i] = 1
		ans = []
		st = []
		for i in range(1, N + 1):
			if skip[i]:
				st.append(i)
			else:
				ans.append(i)
				while st:
					ans.append(st.pop())
		print(*ans)
main()


import sys
input = sys.stdin.readline

def main():
	(n, k) = map(int, input().split())
	if k > 2 ** (n - 1):
		print(-1)
		return
	if n == 1:
		print(1)
		return
	bi = bin(k - 1)[2:].zfill(n - 1)
	ans = []
	bef = 1
	for (i, b) in enumerate(bi, 1):
		if b == '0':
			for j in range(i, bef - 1, -1):
				ans.append(j)
			bef = i + 1
	for j in range(n, bef - 1, -1):
		ans.append(j)
	print(*ans)
for _ in range(int(input())):
	main()


import sys
input = sys.stdin.readline
POW2 = [1] + [1 << i for i in range(63)]
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	if n <= 61 and 2 ** (n - 1) < k:
		print(-1)
		continue
	NOW = 1
	ANS = []
	while k:
		if k == 1:
			ANS += list(range(NOW, n + 1))
			break
		S = 0
		for i in range(61):
			if n - NOW - i >= 64:
				j = i
				ANS += list(range(NOW + j, NOW - 1, -1))
				break
			S += POW2[n - NOW - i]
			if S == k:
				j = i
				k = 0
				ANS += list(range(NOW + j, NOW - 1, -1))
				ANS += list(range(n, NOW + j, -1))
				break
			elif S > k:
				j = i
				k -= S - POW2[n - NOW - i]
				ANS += list(range(NOW + j, NOW - 1, -1))
				break
		NOW = NOW + j + 1
	print(*ANS)


import sys
import re
import random
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def nck(n, k, kaijyo):
	return npk(n, k, kaijyo) * divide(kaijyo[k]) % MOD

def npk(n, k, kaijyo):
	if k == 0 or k == n:
		return n % MOD
	return kaijyo[n] * divide(kaijyo[n - k]) % MOD

def fact_and_inv(SIZE):
	inv = [0] * SIZE
	fac = [0] * SIZE
	finv = [0] * SIZE
	inv[1] = 1
	fac[0] = fac[1] = 1
	finv[0] = finv[1] = 1
	for i in range(2, SIZE):
		inv[i] = MOD - MOD // i * inv[MOD % i] % MOD
		fac[i] = fac[i - 1] * i % MOD
		finv[i] = finv[i - 1] * inv[i] % MOD
	return (fac, finv)

def renritsu(A, Y):
	A = np.matrix(A)
	Y = np.matrix(Y)
	Y = np.reshape(Y, (-1, 1))
	X = np.linalg.solve(A, Y)
	return X.flatten().tolist()[0]

class TwoDimGrid:

	def __init__(self, h, w, wall='#'):
		self.h = h
		self.w = w
		self.size = (h + 2) * (w + 2)
		self.wall = wall
		self.get_grid()

	def get_grid(self):
		grid = [self.wall * (self.w + 2)]
		for i in range(self.h):
			grid.append(self.wall + getS() + self.wall)
		grid.append(self.wall * (self.w + 2))
		self.grid = grid

	def init_cost(self):
		self.cost = [INF] * self.size

	def pos(self, x, y):
		return y * (self.w + 2) + x

	def getgrid(self, x, y):
		return self.grid[y][x]

	def get(self, x, y):
		return self.cost[self.pos(x, y)]

	def set(self, x, y, v):
		self.cost[self.pos(x, y)] = v
		return

	def show(self):
		for i in range(self.h + 2):
			print(self.cost[(self.w + 2) * i:(self.w + 2) * (i + 1)])

	def showsome(self, tgt):
		for t in tgt:
			print(t)
		return

	def showsomejoin(self, tgt):
		for t in tgt:
			print(''.join(t))
		return

	def search(self):
		grid = self.grid
		move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
		move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]

class BIT:

	def __init__(self, n):
		self.n = n
		self.BIT = [0] * (n + 2)

	def query(self, idx):
		res_sum = 0
		while idx > 0:
			res_sum += self.BIT[idx]
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		while idx <= self.n:
			self.BIT[idx] += x
			idx += idx & -idx
		return

	def show(self):
		print(self.BIT)

def solve():
	(n, k) = getList()
	tmp = 1
	for i in range(n - 1):
		tmp <<= 1
		if tmp > 10 ** 19:
			break
	if k == tmp:
		print(*list(reversed([i + 1 for i in range(n)])))
		return
	if k > tmp:
		print(-1)
		return
	k -= 1
	li = [n]
	for i in range(n - 1):
		if k % 2 == 0:
			li.append(n - 1 - i)
		k >>= 1
	li.append(0)
	li.reverse()
	ans = []
	ran = [i + 1 for i in range(n)]
	for (i, j) in zip(li, li[1:]):
		for t in range(j, i, -1):
			ans.append(t)
	print(*ans)

def ran(n):
	ret = []
	for i in range(3):
		a = [random.choice(['0', '1']) for i in range(2 * n)]
		ret.append(''.join(a))
	return ret

def main():
	n = getN()
	for _ in range(n):
		solve()
	return
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = bin(k - 1)[2:]
	if k - 1 > 0:
		b = b + '0'
	if len(b) > n:
		print(-1)
	else:
		b = '0' * (n - len(b)) + b
		p = []
		temp = []
		for i in range(n):
			temp += [str(i + 1)]
			if b[i] == '0':
				p += temp[::-1]
				temp = []
		print(*p)


import sys
input = sys.stdin.readline
for f in range(int(input())):
	(n, k) = map(int, input().split())
	b = bin(k - 1)[2:]
	if k - 1:
		b += '0'
	if len(b) > n:
		print(-1)
	else:
		b = '0' * (n - len(b)) + b
		a = []
		t = []
		for i in range(n):
			t += [str(i + 1)]
			if b[i] == '0':
				a += t[::-1]
				t = []
		print(*a)


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	(n, k) = map(int, stdin.readline().split())
	if n < 100 and 2 ** (n - 1) < k:
		print(-1)
		continue
	k -= 1
	lis = []
	for i in range(n):
		lis.append(k % 2)
		k //= 2
	lis.reverse()
	ans = []
	stk = []
	for i in range(n):
		if lis[i] == 0:
			while len(stk) > 0:
				ans.append(stk[-1])
				del stk[-1]
			stk.append(i + 1)
		else:
			stk.append(i + 1)
	while len(stk) > 0:
		ans.append(stk[-1])
		del stk[-1]
	print(*ans)


def divisors(M):
	d = []
	i = 1
	while M >= i ** 2:
		if M % i == 0:
			d.append(i)
			if i ** 2 != M:
				d.append(M // i)
		i = i + 1
	return d

def popcount(x):
	x = x - (x >> 1 & 1431655765)
	x = (x & 858993459) + (x >> 2 & 858993459)
	x = x + (x >> 4) & 252645135
	x = x + (x >> 8)
	x = x + (x >> 16)
	return x & 127

def eratosthenes(n):
	res = [0 for i in range(n + 1)]
	prime = set([])
	for i in range(2, n + 1):
		if not res[i]:
			prime.add(i)
			for j in range(1, n // i + 1):
				res[i * j] = 1
	return prime

def factorization(n):
	res = []
	for p in prime:
		if n % p == 0:
			while n % p == 0:
				n //= p
			res.append(p)
	if n != 1:
		res.append(n)
	return res

def euler_phi(n):
	res = n
	for x in range(2, n + 1):
		if x ** 2 > n:
			break
		if n % x == 0:
			res = res // x * (x - 1)
			while n % x == 0:
				n //= x
	if n != 1:
		res = res // n * (n - 1)
	return res

def ind(b, n):
	res = 0
	while n % b == 0:
		res += 1
		n //= b
	return res

def isPrimeMR(n):
	if n == 1:
		return 0
	d = n - 1
	d = d // (d & -d)
	L = [2, 3, 5, 7, 11, 13, 17]
	for a in L:
		t = d
		y = pow(a, t, n)
		if y == 1:
			continue
		while y != n - 1:
			y = y * y % n
			if y == 1 or t == n - 1:
				return 0
			t <<= 1
	return 1

def findFactorRho(n):
	from math import gcd
	m = 1 << n.bit_length() // 8
	for c in range(1, 99):
		f = lambda x: (x * x + c) % n
		(y, r, q, g) = (2, 1, 1, 1)
		while g == 1:
			x = y
			for i in range(r):
				y = f(y)
			k = 0
			while k < r and g == 1:
				ys = y
				for i in range(min(m, r - k)):
					y = f(y)
					q = q * abs(x - y) % n
				g = gcd(q, n)
				k += m
			r <<= 1
		if g == n:
			g = 1
			while g == 1:
				ys = f(ys)
				g = gcd(abs(x - ys), n)
		if g < n:
			if isPrimeMR(g):
				return g
			elif isPrimeMR(n // g):
				return n // g
			return findFactorRho(g)

def primeFactor(n):
	i = 2
	ret = {}
	rhoFlg = 0
	while i * i <= n:
		k = 0
		while n % i == 0:
			n //= i
			k += 1
		if k:
			ret[i] = k
		i += 1 + i % 2
		if i == 101 and n >= 2 ** 20:
			while n > 1:
				if isPrimeMR(n):
					(ret[n], n) = (1, 1)
				else:
					rhoFlg = 1
					j = findFactorRho(n)
					k = 0
					while n % j == 0:
						n //= j
						k += 1
					ret[j] = k
	if n > 1:
		ret[n] = 1
	if rhoFlg:
		ret = {x: ret[x] for x in sorted(ret)}
	return ret

def divisors(n):
	res = [1]
	prime = primeFactor(n)
	for p in prime:
		newres = []
		for d in res:
			for j in range(prime[p] + 1):
				newres.append(d * p ** j)
		res = newres
	res.sort()
	return res

def xorfactorial(num):
	if num == 0:
		return 0
	elif num == 1:
		return 1
	elif num == 2:
		return 3
	elif num == 3:
		return 0
	else:
		x = baseorder(num)
		return 2 ** x * ((num - 2 ** x + 1) % 2) + function(num - 2 ** x)

def xorconv(n, X, Y):
	if n == 0:
		res = [X[0] * Y[0] % mod]
		return res
	x = [digit[i] + X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	y = [Y[i] + Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	z = [digit[i] - X[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	w = [Y[i] - Y[i + 2 ** (n - 1)] for i in range(2 ** (n - 1))]
	res1 = xorconv(n - 1, x, y)
	res2 = xorconv(n - 1, z, w)
	former = [(res1[i] + res2[i]) * inv for i in range(2 ** (n - 1))]
	latter = [(res1[i] - res2[i]) * inv for i in range(2 ** (n - 1))]
	former = list(map(lambda x: x % mod, former))
	latter = list(map(lambda x: x % mod, latter))
	return former + latter

def merge_sort(A, B):
	(pos_A, pos_B) = (0, 0)
	(n, m) = (len(A), len(B))
	res = []
	while pos_A < n and pos_B < m:
		(a, b) = (A[pos_A], B[pos_B])
		if a < b:
			res.append(a)
			pos_A += 1
		else:
			res.append(b)
			pos_B += 1
	res += A[pos_A:]
	res += B[pos_B:]
	return res

class UnionFindVerSize:

	def __init__(self, N):
		self._parent = [n for n in range(0, N)]
		self._size = [1] * N
		self.group = N

	def find_root(self, x):
		if self._parent[x] == x:
			return x
		self._parent[x] = self.find_root(self._parent[x])
		stack = [x]
		while self._parent[stack[-1]] != stack[-1]:
			stack.append(self._parent[stack[-1]])
		for v in stack:
			self._parent[v] = stack[-1]
		return self._parent[x]

	def unite(self, x, y):
		gx = self.find_root(x)
		gy = self.find_root(y)
		if gx == gy:
			return
		self.group -= 1
		if self._size[gx] < self._size[gy]:
			self._parent[gx] = gy
			self._size[gy] += self._size[gx]
		else:
			self._parent[gy] = gx
			self._size[gx] += self._size[gy]

	def get_size(self, x):
		return self._size[self.find_root(x)]

	def is_same_group(self, x, y):
		return self.find_root(x) == self.find_root(y)

class WeightedUnionFind:

	def __init__(self, N):
		self.parent = [i for i in range(N)]
		self.size = [1 for i in range(N)]
		self.val = [0 for i in range(N)]
		self.flag = True
		self.edge = [[] for i in range(N)]

	def dfs(self, v, pv):
		stack = [(v, pv)]
		new_parent = self.parent[pv]
		while stack:
			(v, pv) = stack.pop()
			self.parent[v] = new_parent
			for (nv, w) in self.edge[v]:
				if nv != pv:
					self.val[nv] = self.val[v] + w
					stack.append((nv, v))

	def unite(self, x, y, w):
		if not self.flag:
			return
		if self.parent[x] == self.parent[y]:
			self.flag = self.val[x] - self.val[y] == w
			return
		if self.size[self.parent[x]] > self.size[self.parent[y]]:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[x] += self.size[y]
			self.val[y] = self.val[x] - w
			self.dfs(y, x)
		else:
			self.edge[x].append((y, -w))
			self.edge[y].append((x, w))
			self.size[y] += self.size[x]
			self.val[x] = self.val[y] + w
			self.dfs(x, y)

class Dijkstra:

	class Edge:

		def __init__(self, _to, _cost):
			self.to = _to
			self.cost = _cost

	def __init__(self, V):
		self.G = [[] for i in range(V)]
		self._E = 0
		self._V = V

	@property
	def E(self):
		return self._E

	@property
	def V(self):
		return self._V

	def add_edge(self, _from, _to, _cost):
		self.G[_from].append(self.Edge(_to, _cost))
		self._E += 1

	def shortest_path(self, s):
		import heapq
		que = []
		d = [10 ** 15] * self.V
		d[s] = 0
		heapq.heappush(que, (0, s))
		while len(que) != 0:
			(cost, v) = heapq.heappop(que)
			if d[v] < cost:
				continue
			for i in range(len(self.G[v])):
				e = self.G[v][i]
				if d[e.to] > d[v] + e.cost:
					d[e.to] = d[v] + e.cost
					heapq.heappush(que, (d[e.to], e.to))
		return d

def Z_algorithm(s):
	N = len(s)
	Z_alg = [0] * N
	Z_alg[0] = N
	i = 1
	j = 0
	while i < N:
		while i + j < N and s[j] == s[i + j]:
			j += 1
		Z_alg[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < N and k + Z_alg[k] < j:
			Z_alg[i + k] = Z_alg[k]
			k += 1
		i += k
		j -= k
	return Z_alg

class BIT:

	def __init__(self, n, mod=0):
		self.BIT = [0] * (n + 1)
		self.num = n
		self.mod = mod

	def query(self, idx):
		res_sum = 0
		mod = self.mod
		while idx > 0:
			res_sum += self.BIT[idx]
			if mod:
				res_sum %= mod
			idx -= idx & -idx
		return res_sum

	def update(self, idx, x):
		mod = self.mod
		while idx <= self.num:
			self.BIT[idx] += x
			if mod:
				self.BIT[idx] %= mod
			idx += idx & -idx
		return

class dancinglink:

	def __init__(self, n, debug=False):
		self.n = n
		self.debug = debug
		self._left = [i - 1 for i in range(n)]
		self._right = [i + 1 for i in range(n)]
		self.exist = [True for i in range(n)]

	def pop(self, k):
		if self.debug:
			assert self.exist[k]
		L = self._left[k]
		R = self._right[k]
		if L != -1:
			if R != self.n:
				(self._right[L], self._left[R]) = (R, L)
			else:
				self._right[L] = self.n
		elif R != self.n:
			self._left[R] = -1
		self.exist[k] = False

	def left(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._left[res]
			if res == -1:
				break
			k -= 1
		return res

	def right(self, idx, k=1):
		if self.debug:
			assert self.exist[idx]
		res = idx
		while k:
			res = self._right[res]
			if res == self.n:
				break
			k -= 1
		return res

class SparseTable:

	def __init__(self, A, merge_func, ide_ele):
		N = len(A)
		n = N.bit_length()
		self.table = [[ide_ele for i in range(n)] for i in range(N)]
		self.merge_func = merge_func
		for i in range(N):
			self.table[i][0] = A[i]
		for j in range(1, n):
			for i in range(0, N - 2 ** j + 1):
				f = self.table[i][j - 1]
				s = self.table[i + 2 ** (j - 1)][j - 1]
				self.table[i][j] = self.merge_func(f, s)

	def query(self, s, t):
		b = t - s + 1
		m = b.bit_length() - 1
		return self.merge_func(self.table[s][m], self.table[t - 2 ** m + 1][m])

class BinaryTrie:

	class node:

		def __init__(self, val):
			self.left = None
			self.right = None
			self.max = val

	def __init__(self):
		self.root = self.node(-10 ** 15)

	def append(self, key, val):
		pos = self.root
		for i in range(29, -1, -1):
			pos.max = max(pos.max, val)
			if key >> i & 1:
				if pos.right is None:
					pos.right = self.node(val)
					pos = pos.right
				else:
					pos = pos.right
			elif pos.left is None:
				pos.left = self.node(val)
				pos = pos.left
			else:
				pos = pos.left
		pos.max = max(pos.max, val)

	def search(self, M, xor):
		res = -10 ** 15
		pos = self.root
		for i in range(29, -1, -1):
			if pos is None:
				break
			if M >> i & 1:
				if xor >> i & 1:
					if pos.right:
						res = max(res, pos.right.max)
					pos = pos.left
				else:
					if pos.left:
						res = max(res, pos.left.max)
					pos = pos.right
			elif xor >> i & 1:
				pos = pos.right
			else:
				pos = pos.left
		if pos:
			res = max(res, pos.max)
		return res

def solveequation(edge, ans, n, m):
	x = [0] * m
	used = [False] * n
	for v in range(n):
		if used[v]:
			continue
		y = dfs(v)
		if y != 0:
			return False
	return x

	def dfs(v):
		used[v] = True
		r = ans[v]
		for (to, dire, id) in edge[v]:
			if used[to]:
				continue
			y = dfs(to)
			if dire == -1:
				x[id] = y
			else:
				x[id] = -y
			r += y
		return r

class Matrix:
	mod = 10 ** 9 + 7

	def set_mod(m):
		Matrix.mod = m

	def __init__(self, L):
		self.row = len(L)
		self.column = len(L[0])
		self._matrix = L
		for i in range(self.row):
			for j in range(self.column):
				self._matridigit[i][j] %= Matrix.mod

	def __getitem__(self, item):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		return self._matridigit[i][j]

	def __setitem__(self, item, val):
		if type(item) == int:
			raise IndexError('you must specific row and column')
		elif len(item) != 2:
			raise IndexError('you must specific row and column')
		(i, j) = item
		self._matridigit[i][j] = val

	def __add__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matridigit[i][j] + other._matridigit[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __sub__(self, other):
		if (self.row, self.column) != (other.row, other.column):
			raise SizeError('sizes of matrixes are different')
		res = [[0 for j in range(self.column)] for i in range(self.row)]
		for i in range(self.row):
			for j in range(self.column):
				res[i][j] = self._matridigit[i][j] - other._matridigit[i][j]
				res[i][j] %= Matrix.mod
		return Matrix(res)

	def __mul__(self, other):
		if type(other) != int:
			if self.column != other.row:
				raise SizeError('sizes of matrixes are different')
			res = [[0 for j in range(other.column)] for i in range(self.row)]
			for i in range(self.row):
				for j in range(other.column):
					temp = 0
					for k in range(self.column):
						temp += self._matridigit[i][k] * other._matrix[k][j]
					res[i][j] = temp % Matrix.mod
			return Matrix(res)
		else:
			n = other
			res = [[n * self._matridigit[i][j] % Matrix.mod for j in range(self.column)] for i in range(self.row)]
			return Matrix(res)

	def __pow__(self, m):
		if self.column != self.row:
			raise MatrixPowError('the size of row must be the same as that of column')
		n = self.row
		res = Matrix([[int(i == j) for i in range(n)] for j in range(n)])
		while m:
			if m % 2 == 1:
				res = res * self
			self = self * self
			m //= 2
		return res

	def __str__(self):
		res = []
		for i in range(self.row):
			for j in range(self.column):
				res.append(str(self._matridigit[i][j]))
				res.append(' ')
			res.append('\n')
		res = res[:len(res) - 1]
		return ''.join(res)
import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import gcd, log
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())

def pow2(n):
	if n >= 70:
		return 10 ** 18
	else:
		return pow(2, n)

def solve(n, k):
	if n < 70 and k > 2 ** (n - 1):
		return [-1]
	res = []
	skip = 0
	for i in range(n - 1):
		if skip + pow2(n - 2 - i) < k:
			skip += pow2(n - 2 - i)
			continue
		else:
			res = [j + 1 for j in range(i, -1, -1)]
			tmp = solve(n - i - 1, k - skip)
			res += [j + i + 1 for j in tmp]
			return res
	return [n - i for i in range(n)]

def solve_no_recurse(n, k):
	if n < 70 and k > 2 ** (n - 1):
		return [-1]
	res = []
	plus = 0
	while n:
		tmp = []
		skip = 0
		for i in range(n - 1):
			if skip + pow2(n - 2 - i) < k:
				skip += pow2(n - 2 - i)
				continue
			else:
				tmp = [j + 1 + plus for j in range(i, -1, -1)]
				res += tmp
				(n, k, plus) = (n - i - 1, k - skip, len(res))
				break
		else:
			tmp = [n - i + plus for i in range(n)]
			res += tmp
			n = 0
	res = [val for val in res]
	return res
for _ in range(int(input())):
	(n, k) = mi()
	print(*solve_no_recurse(n, k))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = []
	ans = []
	for i in range(n):
		a.append(i + 1)
	if n <= 80 and pow(2, n - 1) < k:
		print(-1)
		continue
	k -= 1
	st = []
	for i in range(min(80, n)):
		if 1 << i & k:
			st.append(1)
		else:
			st.append(0)
	for i in range(80, n):
		st.append(0)
	st.reverse()
	tmp = [1]
	for i in range(1, n):
		if st[i] == 0:
			for j in range(len(tmp) - 1, -1, -1):
				ans.append(tmp[j])
			tmp = []
		tmp.append(a[i])
	for j in range(len(tmp) - 1, -1, -1):
		ans.append(tmp[j])
	print(' '.join(map(str, ans)))


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	if k > 1 << n - 1:
		print(-1)
		continue
	ans = []
	i = 1
	while i <= n:
		l = 0
		while i < n and 1 << n - i - 1 < k:
			k -= 1 << n - i - 1
			l += 1
			i += 1
		for j in range(i, i - l - 1, -1):
			ans.append(j)
		i += 1
	for i in ans:
		print(i, end=' ')
	print()


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def A2(n, m):
	return [[0] * m for i in range(n)]

def G(n):
	return [[] for i in range(n)]

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def bell(s, g):
	dis = AI(n, inf)
	dis[s] = 0
	for i in range(n - 1):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
	change = A(n)
	for i in range(n):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
				change[v] = 1
	return dis

def lcm(a, b):
	return a * b // gcd(a, b)

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None
t = N()
for i in range(t):
	(n, k) = RL()
	if n <= 61 and pow(2, n - 1) < k:
		print(-1)
		continue
	ans = []
	l = 0
	r = n
	cnt = 0
	s = 1
	while k:
		for i in range(s, n + 1):
			if i == n:
				ans += list(range(n, s - 1, -1))
				k = 0
				break
			tmp = pow(2, n - 1 - i)
			cnt += tmp
			if cnt == k:
				k = 0
				ans += list(range(i, s - 1, -1))
				ans += list(range(n, i, -1))
				break
			elif cnt > k:
				cnt -= tmp
				ans += list(range(i, s - 1, -1))
				k -= cnt
				cnt = 0
				s = i + 1
				break
	print(*ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	k -= 1
	p = [i + 1 for i in range(n)]
	x = 1
	sw = []
	for i in range(n - 2, -1, -1):
		if k < x:
			break
		if k & x == x:
			k -= x
			sw.append(i)
		x *= 2
	f = 0
	for i in sw:
		if not f:
			(r, l) = (i + 1, i + 1)
			f = 1
		if l - i == 1:
			l = i
		else:
			for j in range(r - l + 1):
				p[l + j] = r - j + 1
			(r, l) = (i + 1, i)
	if sw:
		for j in range(r - l + 1):
			p[l + j] = r - j + 1
	if k:
		p = [-1]
	print(*p)


import os, sys
from io import BytesIO, IOBase

def main():
	powe = [1] + [pow(2, i) for i in range(100)]
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		if n < 70 and k > powe[n]:
			print(-1)
			continue
		(ans, a) = ([0] * n, 0)
		while a != n:
			if n - a - 1 >= 70 or powe[n - a - 1] >= k:
				ans[a] = a + 1
			else:
				b = a
				while powe[n - a - 1] < k:
					k -= powe[n - a - 1]
					a += 1
				ans[a] = b + 1
			a += 1
		aa = set(range(1, n + 1))
		for i in ans:
			if i in aa:
				aa.remove(i)
		(aa, cou, z, inde) = (sorted(aa), 0, -1, 0)
		for i in range(n):
			if not ans[i]:
				cou += 1
				if z == -1:
					z = i
			else:
				aa1 = aa[inde:inde + cou][::-1]
				for j in range(z, z + cou):
					ans[j] = aa1[j - z]
				inde += cou
				(cou, z) = (0, -1)
		aa1 = aa[inde:inde + cou]
		for j in range(z, z + cou):
			ans[j] = aa1[j - z]
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from itertools import permutations

def almost_sorted(a):
	return all((a[i] >= a[i - 1] - 1 for i in range(1, len(a))))

def experiment(n):
	cnt = 0
	for p in permutations(range(1, n + 1)):
		if almost_sorted(p):
			print(cnt, '\t', *p, mybin(cnt, n - 1))
			cnt += 1

def mybin(n, w):
	res = []
	for i in range(w - 1, -1, -1):
		res.append(str(n >> i & 1))
	return ''.join(res)

def solve(n, k):
	if k >= 1 << n - 1:
		return None
	res = []
	i = 1
	while i <= n:
		b = 2 * k >> n - i & 1
		if b == 0:
			res.append(i)
			i += 1
		else:
			j = i + 1
			while 2 * k >> n - j & 1 == 1:
				j += 1
			res.extend(range(j, i - 1, -1))
			i = j + 1
	return res
tcs = int(input())
for _ in range(tcs):
	(n, k) = map(int, input().split())
	res = solve(n, k - 1)
	if res:
		print(*res)
	else:
		print(-1)


def solve(n, k):
	Exp = n - 1
	resp = ''
	respAux = ''
	expK = CalcularExponente(k)
	restoK = k - 2 ** expK
	if expK > Exp or (expK == Exp and restoK > 0):
		return -1
	for i in range(n):
		Exp -= 1
		respAux = ' ' + str(i + 1) + respAux
		if expK > Exp or (expK == Exp and restoK > 0):
			recalculoK = 2 ** expK - 2 ** Exp + restoK
			expK = CalcularExponente(recalculoK)
			restoK = recalculoK - 2 ** expK
		else:
			resp += respAux
			respAux = ''
	resp += respAux
	return resp[1:]

def CalcularExponente(k):
	kValue = k
	expK = -1
	while k > 0:
		expK += 1
		k = k // 2
	return expK

def main():
	t = int(input())
	for i in range(int(t)):
		(n, k) = input().split(' ')
		print(solve(int(n), int(k)))
main()


from math import gcd, factorial
from collections import defaultdict as dd
MOD = 10 ** 9 + 7

def R(type=int):
	line = input().rstrip()
	try:
		return type(line)
	except:
		pass
	return line
RL = lambda type=int: list(map(type, input().rstrip().split()))
RLL = lambda N, type=int: [RL(type) for _ in range(N)]
RLS = lambda N, type=int: [R(type) for _ in range(N)]

def solve():
	(N, K) = RL()
	if N < 62 and K > 2 ** (N - 1):
		print(-1)
		return
	K -= 1
	r = []
	perm = []
	for i in range(N, 0, -1):
		if K % 2 == 1:
			perm += [i]
		elif perm:
			perm += [i]
			r += perm[::-1]
			perm = []
		else:
			r += [i]
		K //= 2
	print(' '.join(map(str, r[::-1])))
T = R()
for t in range(T):
	solve()