An index i in a permutation P of length N is said to be *good* if:
P_{i} is divisible by i

You are given 2 integers N and K. You need to construct a permutation P of length N such that exactly K indices in that permutation are good.

If no such permutation exists, output -1.

If multiple such permutations exist, output any.

------ Input Format ------ 

- The first line contains a single integer T - the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two integers N and K - the length of the permutation to be constructed and the number of good indices.

------ Output Format ------ 

For each test case, output any permutation satisfying the given condition.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ N$
- Sum of $N$ over all testcases does not exceed $2 \cdot 10^{5}$

----- Sample Input 1 ------ 
2
1 1
6 2

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

----- explanation 1 ------ 
Test case-1: In $[1]$, $P_{1} = 1$ is divisible by $1$. Therefore it is a valid permutation having $1$ good index.

Test case-2: In $[4, 5, 6, 1, 2, 3]$, $P_{1} = 4$ is divisible by $1$ and $P_{3} = 6$ is divisible by $3$. Therefore it is a valid permutation having $2$ good indices.

Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	if k == n - 1:
		res = list(range(1, n + 1))
		res[0] = res[-1]
		res[-1] = 1
		for r in res:
			print(r, end=' ')
		print()
		continue
	res = []
	a = 0
	while a < k:
		res.append(a)
		a += 1
	diff = n - a
	while a < n:
		if diff % 3 == 0 or diff % 3 == 2:
			if a + 2 >= n:
				res.append(a + 1)
				res.append(a)
				a += 2
			else:
				res.append(a + 1)
				res.append(a + 2)
				res.append(a)
				a += 3
		else:
			res.append(a + 1)
			res.append(a)
			a += 2
			diff = 0
	for r in res:
		print(r + 1, end=' ')
	print()


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	l = [i for i in range(1, n + 1)]
	if k == n - 1:
		(l[0], l[-1]) = (l[-1], l[0])
	else:
		for i in range(k, n - 1):
			(l[i], l[i + 1]) = (l[i + 1], l[i])
	print(*l)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, k) = ma()
	res = [i for i in range(1, n + 1)]
	if k != n:
		res[0] = n
		pre = 1
		for i in range(k, n):
			(res[i], pre) = (pre, res[i])
		print(*res)
	else:
		print(*res)


for z in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	if k == n:
		r = [str(i) for i in range(1, n + 1)]
		print(' '.join(r))
		continue
	if k == n - 1:
		r = [0] * n
		r[0] = str(n)
		for i in range(1, n - 1):
			r[i] = str(i + 1)
		r[n - 1] = str(1)
		print(' '.join(r))
		continue
	r = [0] * n
	for i in range(k):
		r[i] = str(i + 1)
	for i in range(k, n - 1):
		r[i] = str(i + 2)
	r[n - 1] = str(k + 1)
	print(' '.join(r))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == 2:
		if k == 1:
			print('2 1')
			continue
		else:
			print('1 2')
			continue
	if k == n - 1:
		print(n, end=' ')
		for i in range(2, n):
			print(i, end=' ')
		print(1)
		continue
	for i in range(1, k + 1):
		print(i, end=' ')
	for i in range(k + 1, n):
		print(i + 1, end=' ')
	if i != n:
		print(k + 1, end=' ')
	print()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k == n - 1:
		p = list(range(1, n + 1))
		(p[-1], p[0]) = (p[0], p[-1])
		print(*p)
	elif k == n:
		p = list(range(1, n + 1))
		print(*p)
	else:
		p = list(range(1, k + 1))
		p1 = list(range(k + 1, n + 1))
		print(*p + p1[1:] + p1[0:1])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(i + 1)
	if n != k:
		(arr[0], arr[-1]) = (arr[-1], arr[0])
		prev = arr[-1]
		for i in range(k, n):
			(arr[i], prev) = (prev, arr[i])
	print(*arr)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(range(1, n + 1))
	if k > 0:
		for i in range(k, n):
			if l[i] % (i + 1) == 0:
				(l[i], l[0]) = (l[0], l[i])
	else:
		print(-1)
		break
	for x in l:
		print(x, end=' ')
	print()


t = int(input())
for i in range(t):
	(N, K) = map(int, input().split())
	if K == N - 1:
		P = list(range(1, N + 1))
		(P[-1], P[0]) = (P[0], P[-1])
		print(*P)
	elif K == N:
		P = list(range(1, N + 1))
		print(*P)
	else:
		P = list(range(1, K + 1))
		P1 = list(range(K + 1, N + 1))
		print(*P + P1[1:] + P1[0:1])


def output(l):
	for i in l:
		print(i, end=' ')
	print()
n = int(input())
while n:
	(num, k) = map(int, input().split())
	if k > num:
		print(-1)
		n -= 1
		continue
	if k == num - 1:
		l = []
		for i in range(1, num + 1):
			l.append(i)
		l[num - 1] = 1
		l[0] = num
		output(l)
		n -= 1
		continue
	l = []
	for i in range(1, k + 1):
		l.append(i)
	j1 = k + 1
	j2 = k + 2
	i = 0
	while len(l) < num:
		if i % 2 == 0:
			l.append(j2)
			j2 += 2
		else:
			l.append(j1)
			j1 += 2
		i += 1
	if k % 2 == 0 and num % 2 == 1 or (k % 2 == 1 and num % 2 == 0):
		temp = l[num - 2]
		l[num - 2] = num
		l[num - 1] = temp
	output(l)
	n -= 1


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	arr = []
	for i in range(a):
		arr.append(i + 1)
	if a != b:
		(arr[0], arr[-1]) = (arr[-1], arr[0])
		prev = arr[-1]
		for i in range(b, a):
			(arr[i], prev) = (prev, arr[i])
	print(*arr)


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	arr = []
	for j in range(1, k + 1):
		arr.append(j)
	if k == n - 1:
		arr.append(n)
		(arr[-1], arr[0]) = (arr[0], arr[-1])
		for j in range(n):
			print(arr[j], end=' ')
		print()
		continue
	for j in range(k + 1, n):
		arr.append(j + 1)
	arr.append(k + 1)
	for j in range(n):
		print(arr[j], end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	permutation = [i for i in range(1, n + 1)]
	if n % 2 == 0 and k % 2 == 0 or (n % 2 == 1 and k % 2 == 1):
		i = k
		while i < n:
			(permutation[i], permutation[i + 1]) = (permutation[i + 1], permutation[i])
			i += 2
	else:
		i = k + 1
		while i < n:
			(permutation[i], permutation[i + 1]) = (permutation[i + 1], permutation[i])
			i += 2
		(permutation[0], permutation[k]) = (permutation[k], permutation[0])
	for i in permutation:
		print(i, end=' ')
	print()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	p = []
	for i in range(n):
		p.append(i + 1)
	if n != k:
		(p[0], p[-1]) = (p[-1], p[0])
		prev = p[-1]
		for i in range(k, n):
			(p[i], prev) = (prev, p[i])
	print(*p)


T = int(input())

def permutation(N, K):
	ans = [i + 1 for i in range(N)]
	if K == N:
		return ans
	for i in range(K + 1, N):
		ans[i] = i
	ans[0] = N
	ans[K] = 1
	return ans
for _ in range(T):
	(N, K) = [int(i) for i in input().split()]
	ans = permutation(N, K)
	x = ' '.join([str(i) for i in ans])
	print(x)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(i + 1)
	if n == k:
		print(*l)
		continue
	(l[0], l[-1]) = (l[-1], l[0])
	prev = 1
	for i in range(k, n):
		(l[i], prev) = (prev, l[i])
	print(*l)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ans = []
	if n == 2 and k == 1:
		print('2 1')
		continue
	if k != n - 1:
		ans = [i for i in range(1, k + 1)]
		for i in range(k + 2, n + 1):
			ans += [i]
		if len(ans) != n:
			ans += [k + 1]
		print(*ans)
	else:
		ans = [2, 1]
		for i in range(3, n + 1):
			ans += [i]
		print(*ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = [x + 1 for x in range(n)]
	for j in range(k, n - 1, 2):
		(ans[j], ans[j + 1]) = (ans[j + 1], ans[j])
	if k != n:
		(ans[0], ans[-1]) = (ans[-1], ans[0])
	print(*ans)


def lisin():
	a = list(map(int, input().split()))
	return a
for tastcas in range(int(input())):
	(n, k) = lisin()
	if 0 < k <= n:
		a = list(range(1, 1 + n))
		j = 1
		while k < n - 1:
			(a[k], a[k + 1]) = (a[k + 1], a[k])
			k += 2
		if k == n - 1:
			(a[k], a[0]) = (a[0], a[k])
		for i in a:
			print(i, end=' ')
		print()
	else:
		print(-1)


mod = 1000000007
from sys import stdin, stdout
from math import ceil
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == 1:
		print(1)
		continue
	if n == k:
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	else:
		print(n, end=' ')
		for i in range(2, k + 1):
			print(i, end=' ')
		print(1, end=' ')
		for i in range(k + 1, n):
			print(i, end=' ')
		print()


for l in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		for i in range(n):
			print(i + 1, end=' ')
		print()
	else:
		print(n - k + 1, end=' ')
		for i in range(1, n - k + 1):
			print(i, end=' ')
		for i in range(n - k + 2, n + 1):
			print(i, end=' ')
		print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		for i in range(1, n + 1):
			print(i, end=' ')
	else:
		for i in range(1, n + 1):
			if k != 0:
				if i == 1:
					print(k + 1, end=' ')
				else:
					print(i, end=' ')
				k = k - 1
			elif i == n:
				print('1', end=' ')
			else:
				print(i + 1, end=' ')
	print()


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	if k == n - 1:
		ans = []
		ans.append(n)
		for i in range(1, k):
			ans.append(i + 1)
		ans.append(1)
		print(*ans)
	else:
		ans = []
		for i in range(k):
			ans.append(i + 1)
		for i in range(k + 1, n):
			ans.append(i + 1)
		if len(ans) < n:
			ans.append(k + 1)
		print(*ans)


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	N = [i for i in range(1, n + 1)]
	if n == k:
		print(*N)
	else:
		N[0] = N[n - k]
		for i in range(1, n - k + 1):
			N[i] = i
		print(*N)


t = int(input())
while t:
	t -= 1
	ls = []
	(n, k) = map(int, input().split())
	for i in range(1, n + 1):
		ls.append(i)
	if n == k:
		print(*ls)
	else:
		(ls[0], ls[n - 1]) = (ls[n - 1], ls[0])
		k1 = ls.pop(n - 1)
		ls.insert(k, k1)
		print(*ls)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == k:
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
		continue
	e = n - k + 1
	print(e, end=' ')
	for i in range(1, n + 1):
		if i != e:
			print(i, end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	k = n - k
	perms = [i + 1 for i in range(n)][::-1]
	index = 0
	for i in range(k // 2):
		(perms[index], perms[index + 1]) = (perms[index + 1], perms[index])
		index += 2
	if k % 2 == 1:
		(perms[-1], perms[index]) = (perms[index], perms[-1])
	print(*perms[::-1])


def swap(ls, a, b):
	(ls[a], ls[b]) = (ls[b], ls[a])
t = int(input())
while t:
	(n, k) = map(int, input().split(' '))
	ls = [i for i in range(1, n + 1)]
	(count, ind) = (0, 0)
	for i in range(n):
		if count < k:
			count += 1
		else:
			ind = i
			break
	if ind != 0:
		for i in range(ind, n, 2):
			if i != n - 1:
				swap(ls, i, i + 1)
			else:
				swap(ls, 0, i)
	print(*ls)
	t -= 1


T = int(input())
for _ in range(T):
	(L, G) = map(int, input().split())
	arr = []
	if L - G == 1:
		arr.append(L)
		for i in range(1, G):
			arr.append(i + 1)
		arr.append(1)
	else:
		for i in range(G):
			arr.append(i + 1)
		for j in range(len(arr) + 1, L):
			arr.append(j + 1)
			if j == L - 1:
				arr.append(G + 1)
	print(*arr)


for _ in range(0, int(input())):
	(n, k) = [int(x) for x in input().split()]
	p = []
	for i in range(2, n - k + 2):
		p.append(i)
	p.append(1)
	for i in range(n - k + 2, n + 1):
		p.append(i)
	print(*p)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = [i for i in range(1, k + 1)]
	ans += [i for i in range(k + 2, n + 1)]
	if n != k:
		ans += [k + 1]
	if k == n - 1:
		(ans[0], ans[-1]) = (ans[-1], ans[0])
	print(*ans)


t = int(input())
for i in range(t):
	(x, n) = map(int, input().split())
	if n > x:
		print('-1')
	elif n == x:
		for i in range(1, x + 1, 1):
			print(i, end=' ')
		print()
	elif n == x - 1:
		print(x, end=' ')
		for i in range(2, n + 1, 1):
			print(i, end=' ')
		print('1', end=' ')
		print()
	else:
		print(x - n + 1, end=' ')
		for i in range(1, x - n + 1, 1):
			print(i, end=' ')
		for i in range(x - n + 2, x + 1, 1):
			print(i, end=' ')
		print()


def rotate_array(lst, n, d):
	lst_res = [0] * n
	j = 0
	for i in range(n - d, n):
		lst_res[j] = lst[i]
		j += 1
	for i in range(0, n - d):
		lst_res[j] = lst[i]
		j += 1
	return lst_res
for t in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	lst = [x for x in range(1, n + 1)]
	if n == k:
		for x in lst:
			print(x, end=' ')
	else:
		res_1 = rotate_array(lst[0:n - k + 1], n - k + 1, 1)
		res_2 = lst[n - k + 1:]
		lst_res = res_1 + res_2
		for x in lst_res:
			print(x, end=' ')
	print()


def solution(n, k):
	ans = []
	for i in range(1, n + 1):
		if i <= k:
			ans.append(i)
		elif i == n:
			ans.append(k + 1)
		else:
			ans.append(i + 1)
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if k == n - 1:
		ans = []
		ans.append(n)
		for i in range(2, n):
			ans.append(i)
		ans.append(1)
		print(*ans)
	else:
		print(*solution(n, k))


t = int(input())
for i in range(t):
	(N, K) = map(int, input().split())
	if N == K:
		for x in range(1, N + 1):
			print(x, end=' ')
		print()
	else:
		print(N - K + 1, end=' ')
		for j in range(1, N - K + 1):
			print(j, end=' ')
		for j in range(N - K + 2, N + 1):
			print(j, end=' ')
		print()


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = [i for i in range(1, n + 1)]
	if n != k:
		a = n - k
		for j in range(k, n - 1, 2):
			(arr[j], arr[j + 1]) = (arr[j + 1], arr[j])
		if a % 2:
			(arr[0], arr[n - 1]) = (arr[n - 1], arr[0])
	print(*arr)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	if k == n:
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	else:
		print(n - k + 1, end=' ')
		for i in range(1, n - k + 1):
			print(i, end=' ')
		for j in range(n - k + 2, n + 1):
			print(j, end=' ')
		print()


import math, os, io, heapq
from functools import reduce
from sys import stdin, stdout
from collections import Counter, deque, defaultdict
from itertools import product
import bisect

def getList(method=int):
	return list(map(method, input().split()))

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

def solve():
	(n, k) = getList()
	if k == n - 1:
		if n <= 3:
			print(*range(n, 0, -1))
		else:
			ans = list(range(1, n + 1))
			(ans[1], ans[3]) = (4, 2)
			print(*ans)
		return
	ans = []
	for i in range(1, n + 1):
		ans.append(i)
	for j in range(k, n, 2):
		swp = j + 1 if j + 1 < n else j - 1
		(ans[j], ans[swp]) = (ans[swp], ans[j])
	print(*ans)
for _ in range(getInt()):
	solve()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = []
	if n == k:
		for j in range(1, n + 1):
			print(j, end=' ')
		print()
		continue
	b = []
	for j in range(1, n + 1):
		b.append(j)
	for j in range(n):
		if k > 0:
			if j == 0:
				a.append(n)
				b.remove(n)
			else:
				a.append(j + 1)
				b.remove(j + 1)
			k -= 1
		elif b[0] != j + 1:
			a.append(b[0])
			b.pop(0)
		else:
			a.append(b[1])
			b.pop(1)
	print(*a)


T = int(input())
for i in range(T):
	(N, K) = map(int, input().split(' '))
	a = []
	if K == N:
		a = [alpha for alpha in range(1, N + 1)]
		print(*a)
	elif K != N - 1:
		for theta in range(1, K + 1):
			a.append(theta)
		for delta in range(K + 2, N + 1):
			a.append(delta)
		a.append(K + 1)
		print(*a)
	else:
		a = [alpha for alpha in range(1, N + 1)]
		a[0] = 2
		a[1] = 1
		print(*a)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if b != a - 1:
		for i in range(1, b + 1):
			print(i, end=' ')
		for i in range(b + 2, a + 1):
			print(i, end=' ')
		if b != a:
			print(b + 1)
		else:
			print()
	else:
		print(a, end=' ')
		for i in range(2, a):
			print(i, end=' ')
		print(1)


def solve(N, K):
	P = [0] * N
	for i in range(N):
		if i < N - K:
			P[i] = i + 2
		elif i == N - K:
			P[i] = 1
		else:
			P[i] = i + 1
	return P
for _ in range(int(input())):
	(N, K) = [int(x) for x in input().split()]
	print(*solve(N, K))


import math
from sys import stdin, stdout
mod = 1000000007
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	if n == k + 1:
		a = [i for i in range(1, n + 1)]
		(a[0], a[-1]) = (a[-1], a[0])
	else:
		a = []
		for i in range(n):
			if i == k:
				continue
			a.append(i + 1)
		if k != n:
			a.append(k + 1)
	for i in a:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = list((x for x in range(1, n + 1)))
	ind = list1.index(n - k + 1)
	list1.pop(ind)
	list1.insert(0, n - k + 1)
	print(*list1)


t = int(input())
while t != 0:
	t -= 1
	(n, k) = list(map(int, input().split()))
	if n == k:
		for i in range(1, k + 1):
			print(i, end=' ')
	else:
		a = n - k + 1
		print(a, end=' ')
		for i in range(1, a):
			print(i, end=' ')
		for i in range(n - k + 2, n + 1):
			print(i, end=' ')
	print()


from collections import Counter
from math import ceil, floor, log, gcd
import bisect as bs
import sys
input = sys.stdin.readline
inp_lis = lambda : list(map(int, input().split()))
inp_multi = lambda : map(int, input().split())
inp_int = lambda : int(input().strip())
for _ in range(int(input().strip())):
	(n, k) = inp_multi()
	if k == n:
		for i in range(1, n + 1):
			print(i, end=' ')
	else:
		temp = n - k + 1
		print(temp, end=' ')
		for i in range(1, n + 1):
			if i != temp:
				print(i, end=' ')
	print()


for T in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(range(1, N + 1))
	A.insert(0, A.pop(N - K))
	print(*A)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	l.append(n - k + 1)
	for j in range(1, n - k + 1):
		l.append(j)
	for k in range(n - k + 2, n + 1):
		l.append(k)
	for x in l:
		print(x, end=' ')
	print()


try:
	from itertools import permutations
	N = int(input())
	for w in range(N):
		(n, k) = [int(x) for x in input().split()]
		l = [i for i in range(1, n + 1)]
		if n == 1:
			print(1)
			continue
		(l[0], l[n - k]) = (l[n - k], l[0])
		for i in range(1, n - k):
			(l[i], l[n - k]) = (l[n - k], l[i])
		print(*l)
except:
	pass


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	flag = False
	if n % 2 == 0 and k % 2 == 0:
		for i in range(k):
			print(i + 1, end=' ')
		for i in range(k + 1, n + 1):
			if i % 2 != 0:
				print(i + 1, end=' ')
			else:
				print(i - 1, end=' ')
	elif n % 2 == 0 and k % 2 != 0:
		for i in range(k):
			if flag == False:
				print(n, end=' ')
				flag = True
			else:
				print(i + 1, end=' ')
		for i in range(k + 1, n):
			if i % 2 == 0:
				print(i + 1, end=' ')
			else:
				print(i - 1, end=' ')
		print(1, end=' ')
	elif n % 2 != 0 and k % 2 == 0:
		for i in range(k):
			if flag == False:
				print(n, end=' ')
				flag = True
			else:
				print(i + 1, end=' ')
		for i in range(k + 1, n):
			if i % 2 != 0:
				print(i + 1, end=' ')
			else:
				print(i - 1, end=' ')
		print(1, end=' ')
	else:
		for i in range(k):
			print(i + 1, end=' ')
		for i in range(k + 1, n + 1):
			if i % 2 == 0:
				print(i + 1, end=' ')
			else:
				print(i - 1, end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	p = n - k + 1
	if p < 0 or p > n + 1:
		print(-1)
	else:
		a = [i for i in range(n + 1)]
		a.pop(p)
		a[0] = p
		print(' '.join(map(str, a)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [i for i in range(1, n + 1)]
	for i in range(k, n - 1, 2):
		(a[i], a[i + 1]) = (a[i + 1], a[i])
	if (n - k) % 2 != 0:
		(a[n - 1], a[0]) = (a[0], a[n - 1])
	for i in a:
		print(i, end=' ')
	print('')


T = int(input())
for tc in range(T):
	(n, k) = map(int, input().split(' '))
	s = list(range(1, n + 1))
	if k < n:
		s.insert(k, s[0])
		s[0] = s.pop()
	for i in s:
		print(i, end=' ')
	print('')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	for i in range(1, n + 1):
		l.append(i)
	u = n - k + 1
	m = l.pop(u - 1)
	l.insert(0, m)
	if k < 1:
		print(-1)
	else:
		print(*l)


def main():
	T = int(input())
	for _ in range(T):
		(N, K) = list(map(int, input().split()))
		print(solution(N, K))

def solution(N, K):
	if N == K:
		return ' '.join([str(i) for i in range(1, N + 1)])
	res = [i + 1 for i in range(K)]
	res.append(N)
	res.extend([i + 1 for i in range(K, N - 1)])
	if res[K] % (K + 1) == 0:
		(res[0], res[K]) = (res[K], res[0])
	return ' '.join(list(map(str, res)))
main()


T = int(input())
for test in range(T):
	(N, K) = map(int, input().split())
	if K == N - 1:
		print('2 1', end=' ')
		for i in range(3, N + 1):
			print(i, end=' ')
		print()
		continue
	for i in range(1, K + 1):
		print(i, end=' ')
	for i in range(K + 1, N + 1):
		if i == N:
			print(K + 1, end=' ')
			break
		print(i + 1, end=' ')
	print()


import sys
input = sys.stdin.readline

def ma():
	return map(int, input().split())

def inp():
	return int(input())
t = int(input())
while t:
	(n, k) = map(int, input().split())
	if n == k:
		for i in range(1, n + 1):
			print(i, end=' ')
	else:
		print(n - k + 1, end=' ')
		for i in range(1, n - k + 1):
			print(i, end=' ')
		for i in range(n - k + 2, n + 1):
			print(i, end=' ')
	print('')
	t -= 1


t = int(input())
for _ in range(0, t):
	inputs = [int(num) for num in input().split()]
	n = inputs[0]
	k = inputs[1]
	if n - k == 1:
		s = str(n) + ' '
		for i in range(2, n):
			s += str(i) + ' '
		s += str(1)
		print(s)
	else:
		i = n - k
		s = ''
		for i in range(1, k + 1):
			s += str(i) + ' '
		i = k + 2
		for i in range(k + 2, n + 1):
			s += str(i) + ' '
		if k < n:
			s += str(k + 1)
		print(s.strip())


for i in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = []
	if k == 1:
		a.append(n)
		b = [i - 1 for i in range(2, n + 1, 1)]
		a.extend(b)
		print(*a)
	else:
		a.append(n - k + 1)
		b = [j for j in range(n - k + 2, n + 1, 1)]
		c = [i - 1 for i in range(2, n - k + 2)]
		print(*a + c + b)


try:
	for _ in range(int(input())):
		(n, k) = list(map(int, input().split()))
		j = 0
		res = []
		for i in range(1, n + 1):
			res.append(str(i))
		if n == k:
			print(' '.join(res))
		else:
			temp = res.pop(n - k)
			res.insert(0, temp)
			print(' '.join(res))
except:
	pass


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = list(range(1, n + 1))
	arr.insert(0, arr.pop(n - k))
	print(*arr)


ii = lambda : int(input())
imi = lambda : [int(i) for i in input().split()]
for _ in range(ii()):
	(n, k) = map(int, input().split())
	li = [str(i) for i in range(1, n + 1)]
	lians = [str(n - k + 1)] + [str(i) for i in range(1, n - k + 1)] + [str(i) for i in range(n - k + 2, n + 1)]
	print(' '.join(lians))


import itertools
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = [x for x in range(1, n + 1)]
	if n == k:
		print(*l)
	else:
		i = n - k + 1 - 1
		r = [l[i]] + l[0:i] + l[i + 1:]
		print(*r)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = list(range(1, n + 1))
	remeaning = n - k
	idx = 1
	while remeaning:
		if remeaning == 1:
			(ans[0], ans[-1]) = (ans[-1], ans[0])
			remeaning -= 1
		else:
			index = idx * 2
			(ans[index], ans[index - 1]) = (ans[index - 1], ans[index])
			idx += 1
			remeaning -= 2
	print(' '.join(map(str, ans)))