Reve has two integers $n$ and $k$.

Let $p$ be a permutation$^\dagger$ of length $n$. Let $c$ be an array of length $n - k + 1$ such that $$c_i = \max(p_i, \dots, p_{i+k-1}) + \min(p_i, \dots, p_{i+k-1}).$$ Let the cost of the permutation $p$ be the maximum element of $c$.

Koxia wants you to construct a permutation with the minimum possible cost.

$^\dagger$ A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).


-----Input-----

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 2000$) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 2 \cdot 10^5$).

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


-----Output-----

For each test case, output $n$ integers $p_1,p_2,\dots,p_n$, which is a permutation with minimal cost. If there is more than one permutation with minimal cost, you may output any of them.


-----Examples-----

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


-----Note-----

In the first test case,

$c_1 = \max(p_1,p_2,p_3) + \min(p_1,p_2,p_3) = 5 + 1 = 6$.

$c_2 = \max(p_2,p_3,p_4) + \min(p_2,p_3,p_4) = 3 + 1 = 4$.

$c_3 = \max(p_3,p_4,p_5) + \min(p_3,p_4,p_5) = 4 + 2 = 6$.

Therefore, the cost is $\max(6,4,6)=6$. It can be proven that this is the minimal cost.

Source: codeforces | Difficulty: EASY
Tags: Constructive algorithms


Solutions:
t = int(input())
out = []
for i in range(t):
	(n, k) = [int(j) for j in input().split()]
	a = []
	for j in range(n // 2):
		a.append(f'{n - j}')
		a.append(f'{j + 1}')
	if n % 2 != 0:
		a.append(f'{n // 2 + 1}')
	out.append(' '.join(a))
for i in out:
	print(i)


import sys
input = sys.stdin.readline

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

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
test_cases = inp()
inp_arr = []
for i in range(test_cases):
	nums = inlt()
	(n, k) = (nums[0], nums[1])
	inp_arr.append((n, k))

def findResult(n, k):
	result = [str(0)] * n
	if n % 2 != 0:
		result[int(n / 2)] = str(int(n / 2))
	m = int(n / 2) - 1 if n % 2 == 0 else int(n / 2)
	s = n
	for i in range(0, int(n / 2) + 1, 2):
		result[i] = str(s)
		s -= 2
	s = 1
	for i in range(1, int(n / 2), 2):
		result[i] = str(s)
		s += 2
	s = n - 1
	for i in range(n - 1, m, -2):
		result[i] = str(s)
		s -= 2
	s = 2
	for i in range(n - 2, m, -2):
		result[i] = str(s)
		s += 2
	return ' '.join(result)
result = [findResult(n, k) for (n, k) in inp_arr]
for m in result:
	print(m)


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	if n % 2 == 0:
		l = []
		for i in range(n // 2):
			l.append(str(n - i))
			l.append(str(i + 1))
		print(' '.join(l))
	if n % 2 == 1:
		l = []
		for i in range(n // 2):
			l.append(str(n - i))
			l.append(str(i + 1))
		l.append(str(n // 2 + 1))
		print(' '.join(l))


def solve(n, k):
	lst = []
	j = 1
	l = n
	for _ in range(n // k):
		for i in range(k - 1):
			lst.append(l)
			l -= 1
		lst.append(j)
		j += 1
	while len(lst) < n:
		lst.append(j)
		j += 1
	return ' '.join(map(str, lst))
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(solve(n, k))


def helper(n, k):
	import heapq
	arr = [i + 1 for i in range(n)]
	arr2 = arr[::-1]
	ans = [0] * n
	nn = len(ans[::2])
	ans[::2] = arr2[:nn]
	ans[1::2] = arr[:n - nn]
	return ' '.join(list(map(str, ans)))
for i in range(int(input())):
	inp = list(map(int, input().split()))
	print(helper(inp[0], inp[1]))


import sys

def solve():
	(n, k) = map(int, sys.stdin.readline().split())
	ar = []
	(a, b) = (1, n)
	for i in range(n):
		if i % 2:
			ar.append(a)
			a += 1
		else:
			ar.append(b)
			b -= 1
	print(' '.join((str(x) for x in ar)))

def main():
	n = int(sys.stdin.readline())
	for _ in range(n):
		solve()
main()


import os
import math
import collections
import bisect
import functools
import itertools
import heapq

def solve(n, k):
	if k == 1 or k == n:
		return list(range(1, n + 1))
	(i, j) = (1, n)
	ans = []
	while i <= j:
		ans.append(j)
		if i < j:
			ans.append(i)
		i += 1
		j -= 1
	return ans
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	res = solve(n, k)
	print(' '.join(map(str, res)))


t = int(input())

def solve(n, k):
	if n == k or k == 1:
		return ' '.join([str(x) for x in range(1, n + 1)])
	start = 1
	end = n
	result = []
	while start < end:
		result.append(end)
		result.append(start)
		end -= 1
		start += 1
	if start == end:
		result.append(start)
	return ' '.join([str(x) for x in result])
for _ in range(t):
	(n, k) = [int(w) for w in input().split()]
	print(solve(n, k))


from math import ceil
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	if k == 1 or k == n:
		p = list(range(1, n + 1))
	else:
		p = []
		for i in range(ceil(n / 2)):
			p.append(n - i)
			if len(p) < n:
				p.append(i + 1)
	print(' '.join(list(map(str, p))))


import heapq
n = int(input())

def solve(n, m):
	arr = []
	i = 1
	j = n
	while i < j:
		arr.append(j)
		arr.append(i)
		i += 1
		j -= 1
	if i == j:
		arr.append(i)
	print(' '.join([str(_) for _ in arr]))
for _ in range(n):
	(n, m) = [int(_) for _ in input().split()]
	solve(n, m)


t = int(input())
for p in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		a = []
		for i in range(1, n + 1):
			a.append(i)
		print(' '.join(map(str, a)))
	elif n % 2 == 0:
		a = []
		for i in range(1, (n + 1) // 2 + 1):
			a.append(n - i + 1)
			a.append(i)
		print(' '.join(map(str, a)))
	else:
		a = []
		for i in range(1, (n + 1) // 2):
			a.append(n - i + 1)
			a.append(i)
		a.append((n + 2) // 2)
		print(' '.join(map(str, a)))


import sys

def solve():
	inp = sys.stdin.readline
	(n, m) = map(int, inp().split())
	a = [None] * n
	j = 1
	for i in range(m - 1, n, m):
		a[i] = j
		j += 1
	j = n
	for i in range(n):
		if a[i] is None:
			a[i] = j
			j -= 1
	print(' '.join(map(str, a)))

def main():
	for i in range(int(sys.stdin.readline())):
		solve()
main()


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	if k == 1 or k == n:
		print(' '.join(map(str, range(1, n + 1))))
		continue
	l = []
	top = n
	bottom = 1
	while len(l) < n:
		l.append(top)
		l.append(bottom)
		top -= 1
		bottom += 1
	print(' '.join(map(str, l[:n])))


for _ in range(int(input())):
	[n, m] = list(map(int, input().split(' ')))
	arr = []
	i = n
	j = 1
	while i > j:
		arr.append(i)
		arr.append(j)
		(i, j) = (i - 1, j + 1)
	if i == j:
		arr.append(j)
	arr = [str(i) for i in arr]
	print(' '.join(arr))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = []
	l = 1
	r = n
	while l <= r:
		a.append(r)
		r -= 1
		if l <= r:
			a.append(l)
			l += 1
	print(' '.join(map(str, a)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	p = 1
	q = n
	l = []
	while p < q:
		l.append(q)
		l.append(p)
		q -= 1
		p += 1
	if p == q:
		l.append(p)
	print(' '.join(map(str, l)))


import math

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

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

def inchar():
	return list(input().split())

def insr():
	s = input()
	return list(s)

def invr():
	return map(int, input().split())
a = inp()
for _ in range(a):
	k = inlt()
	l = []
	for i in range(math.ceil(k[0] / 2)):
		l.append(str(k[0] - i))
		if k[0] - i > i + 1:
			l.append(str(i + 1))
		else:
			break
	print(' '.join(l))


from heapq import heappush, heappop
t = int(input().strip())
for _ in range(t):
	(n, k) = map(int, input().strip().split())
	lo = 1
	hi = n
	output = []
	while lo <= hi:
		output.append(str(hi))
		if lo != hi:
			output.append(str(lo))
		lo += 1
		hi -= 1
	print(' '.join(output))


t = int(input())
for i in range(t):
	(n, m) = [int(x) for x in input().split()]
	ans = []
	(a, b) = (1, n)
	while a <= b:
		ans.append(b)
		if b != a:
			ans.append(a)
		a += 1
		b -= 1
	ans = [str(i) for i in ans]
	print(' '.join(ans))


import heapq
k = int(input())
for _ in range(k):
	(n, _) = map(int, input().split())
	ar = []
	(i, j) = (1, n)
	while j > i:
		ar.append(j)
		j -= 1
		if j >= i:
			ar.append(i)
			i += 1
	if j == i:
		ar.append(i)
	print(' '.join(map(str, ar)))


tests = int(input())
for _ in range(tests):
	(n, k) = list(map(int, input().split()))
	hi = list(range(n // 2 + 1, n + 1))
	lo = list(range(1, n // 2 + 1))
	lo.reverse()
	out = []
	while hi or lo:
		if hi:
			out.append(hi.pop())
		if lo:
			out.append(lo.pop())
	print(' '.join((str(x) for x in out)))


t = int(input())

def cost(p, k):
	cc = 0
	for i in range(len(p) - k + 1):
		c = min(p[i:i + k]) + max(p[i:i + k])
		cc = max(c, cc)
	return cc
for _ in range(t):
	(n, k) = (int(v) for v in input().split())
	maxi = n
	mini = 1
	p = []
	while maxi > mini:
		p += [maxi]
		p += [mini]
		maxi -= 1
		mini += 1
	if maxi == mini:
		p += [maxi]
	print(' '.join([str(v) for v in p]))


from math import *
for z in range(int(input())):
	(n, k) = map(int, input().split())
	a = []
	for i in range(n, n // 2, -1):
		a.append(str(i))
		if n % 2 == 0 or i != n // 2 + 1:
			a.append(str(n - i + 1))
	print(' '.join(a))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	res = [i for i in range(1, n + 1)]
	ans = []
	temp = n
	for i in range(1, n + 1):
		ans.append(str(n))
		temp -= 1
		if not temp:
			break
		ans.append(str(i))
		temp -= 1
		if not temp:
			break
		n -= 1
	a = ' '.join(ans)
	print(a)


t = int(input())
for x in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	res = list(range(n))
	for x in range(n):
		if x % 2:
			res[x] = 1 + x // 2
		else:
			res[x] = n - x // 2
	print(' '.join([str(x) for x in res]))


t = int(input(''))
for _ in range(t):
	(n, k) = [int(x) for x in input('').split(' ')]
	out = [0] * n
	low = 1
	high = n
	for i in range(n):
		if i % k == k - 1:
			out[i] = low
			low += 1
		else:
			out[i] = high
			high -= 1
	print(' '.join((str(x) for x in out)))


for tes in range(int(input())):
	(n, k) = map(int, input().split())
	if k == 1:
		print(' '.join((str(i + 1) for i in range(n))))
	else:
		ans = []
		i = 1
		j = n
		while i <= j:
			ans.append(j)
			if i == j:
				break
			ans.append(i)
			i += 1
			j -= 1
		print(' '.join((str(i) for i in ans)))


import sys
t = int(sys.stdin.readline())
for i in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	nlst = [i + 1 for i in range(n)]
	newlst = []
	if n % 2 == 0:
		a = nlst[:int(n / 2)]
		b = nlst[int(n / 2):]
		b.reverse()
		for j in range(int(n / 2)):
			newlst.append(b[j])
			newlst.append(a[j])
	else:
		a = nlst[:int((n - 1) / 2)]
		b = nlst[int((n + 1) / 2):]
		b.reverse()
		ex = nlst[int((n - 1) / 2)]
		for j in range(int((n - 1) / 2)):
			newlst.append(b[j])
			newlst.append(a[j])
		newlst.append(ex)
	newlst = [str(e) for e in newlst]
	st = ' '.join(newlst)
	sys.stdout.write(st + '\n')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	L1 = [k for k in range(1, n + 1)]
	L2 = [k for k in range(n, 0, -1)]
	L3 = []
	j = 0
	while len(L3) < n:
		L3.append(L2[j])
		if len(L3) < n:
			L3.append(L1[j])
		j += 1
	print(' '.join(map(str, L3)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	result = []
	max_val = n
	min_val = 1
	while len(result) < n:
		temp = 0
		while temp < k - 1 and len(result) < n:
			result.append(str(max_val))
			max_val -= 1
			temp += 1
		if len(result) < n:
			result.append(str(min_val))
			min_val += 1
	print(' '.join(result))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = ''
	for i in range(n // 2):
		s += str(n - i) + ' '
		s += str(i + 1) + ' '
	if n % 2 == 1:
		s += str(n // 2 + 1) + ' '
	print(s)


def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		i = n
		j = 1
		s = ''
		while i > j:
			s += ' ' + str(i)
			s += ' ' + str(j)
			i -= 1
			j += 1
		if i == j:
			s += ' ' + str(i)
		print(s)
main()


t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	s = ''
	for i in range(a // 2):
		s += str(a - i) + ' '
		s += str(i + 1) + ' '
	if a % 2 == 1:
		s += str(a // 2 + 1)
	print(s)


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	s = ''
	for i in range(int(n / 2)):
		s += str(n - i) + ' ' + str(i + 1) + ' '
	if n % 2 != 0:
		s += str(int(n / 2) + 1)
	print(s)


import heapq
t = int(input())
for x in range(t):
	[n, k] = [int(i) for i in input().split()]
	arr = [str(i) for i in range(1, n + 1)]
	if k == 1:
		print(' '.join(arr))
	elif k > n // 2:
		print(' '.join(arr[(n + 1) // 2:][::-1]) + ' ' + ' '.join(arr[:(n + 1) // 2]))
	else:
		i = 1
		j = n
		turn = 0
		ans = []
		while i <= j:
			if j - i + 1 >= k - 1:
				for a in range(k - 1):
					if turn == 0:
						ans.append(j)
						j -= 1
					else:
						ans.append(i)
						i += 1
				turn = (turn + 1) % 2
			else:
				for a in range(i, j + 1):
					ans.append(a)
					i += 1
		print(' '.join([str(i) for i in ans]))


import sys

def fn(n):
	out = ''
	max_val = n
	min_val = 1
	alt = True
	while min_val <= max_val:
		if alt:
			out += str(max_val) + ' '
			max_val -= 1
		else:
			out += str(min_val) + ' '
			min_val += 1
		alt = not alt
	return out[:-1]
input = sys.stdin.readlines()
for i in range(int(input[0].strip('\n'))):
	n = int(input[i + 1].strip('\n').split(' ')[0])
	print(fn(n))


import heapq
import math
eps = 10 ** (-9)

def solve():
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	res = ''
	a = [x for x in range(1, n + 1)]
	i = 0
	j = n - 1
	for p in range(k - 1):
		res += ' ' + str(a[j])
		j -= 1
	res += ' ' + str(a[i])
	i += 1
	while i <= j:
		c = 0
		while i <= j and c < k - 1:
			res += ' ' + str(a[j])
			j -= 1
			c += 1
		if i <= j:
			res += ' ' + str(a[i])
			i += 1
	print(res[1:])
t = int(input())
for _ in range(t):
	solve()


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	s = ''
	i = 1
	j = 0
	if k == 1 or n == k:
		print(*range(1, n + 1))
		continue
	while n - i >= 0:
		if j == 0:
			s += str(n) + ' '
			n -= 1
			j = 1
		else:
			s += str(i) + ' '
			i += 1
			j = 0
	print(s)


def fun(n, k):
	l = []
	if k != 1:
		x = int(n // (k - 1))
		i = int(x // 2)
		d = x - i
		a = 1
		b = n
		if x % 2 == 0:
			for q in range(1, int(x / 2 + 1)):
				l.extend(list(range(n - (k - 1) * (q - 1), n - q * (k - 1), -1)))
				l.extend(list(range(1 + (k - 1) * (q - 1), 1 + (k - 1) * q)))
			l.extend(list(range(n - int(x / 2) * (k - 1), (k - 1) * int(x / 2), -1)))
			print(*l)
		else:
			for q in range(1, d):
				l.extend(list(range(n - (k - 1) * (q - 1), n - q * (k - 1), -1)))
				l.extend(list(range(1 + (k - 1) * (q - 1), 1 + (k - 1) * q)))
			q = d
			l.extend(list(range(n - (k - 1) * (q - 1), n - q * (k - 1), -1)))
			q = d - 1
			l.extend(list(range(1 + (k - 1) * q, n - q * (k - 1) + 1 - k + 1)))
			print(*l)
	else:
		l = list(range(1, n + 1))
		print(*l)
for q12 in range(int(input())):
	(n, k) = map(int, input().split())
	fun(n, k)


def solve():
	(n, k) = map(int, input().split())
	ans = []
	for i in range(n // 2):
		ans.extend([n - i, i + 1])
	if n % 2 == 1:
		ans.append((n + 1) // 2)
	print(*ans)
for _ in range(int(input())):
	solve()


for _ in [*open(0)][1:]:
	(n, k) = map(int, _.split())
	li = []
	for i in range(n >> 1):
		li += [n - i, i + 1]
	print(*li + [['', n + 1 >> 1][n & 1]])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n // 2):
		a.append(n - i)
		a.append(i + 1)
	if n & 1:
		a.append((n + 1) // 2)
	print(*a)


def func():
	(n, k) = map(int, input().split())
	for i in range(n // 2):
		print(n - i, end=' ')
		print(i + 1, end=' ')
	if n % 2 != 0:
		print((n + 1) // 2)
for i in range(int(input())):
	func()


for i in range(int(input())):
	(n, m) = map(int, input().split())
	for i in range(0, n // 2):
		print(n - i, i + 1, end=' ')
	if n % 2 != 0:
		print(n // 2 + 1)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	anil = []
	for i in range(n // 2):
		anil.append(n - i)
		anil.append(i + 1)
	print(*(anil if n & 1 == 0 else (*anil, n // 2 + 1)))


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	vec = []
	for i in range(n // 2):
		vec.append(n - i)
		vec.append(i + 1)
	if n % 2 == 0:
		print(*vec)
	else:
		vec.append(n // 2 + 1)
		print(*vec)


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(n, q) = map(int, input().split())
	l = []
	for i in range(n // 2):
		l.append(n - i)
		l.append(i + 1)
	if n % 2 == 0:
		print(*l)
	else:
		l.append(n // 2 + 1)
		print(*l)


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(no, k) = map(int, input().split())
	lost = []
	for x in range(no // 2):
		lost.append(no - x)
		lost.append(x + 1)
	if no % 2 == 0:
		print(*lost)
	else:
		lost.append(no // 2 + 1)
		print(*lost)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split(' '))
	l = []
	for i in range(n // 2):
		l.append(n - i)
		l.append(i + 1)
	if n % 2 == 1:
		l.append(n // 2 + 1)
	print(*l)


for j in range(int(input())):
	(n, k) = map(int, input().split())
	res = []
	for i in range(n // 2):
		res.append(n - i)
		res.append(i + 1)
	if n % 2 == 1:
		res.append(n // 2 + 1)
	print(*res)


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


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


t = int(input())
while t:
	t -= 1
	a = []
	(n, k) = map(int, input().split())
	for x in range(n // 2):
		a.append(n - x)
		a.append(x + 1)
	if n % 2 == 1:
		a.append(n // 2 + 1)
	print(*a)


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = []
	for i in range(n // 2):
		l.append(n - i)
		l.append(i + 1)
	if n % 2 == 0:
		print(*l)
	else:
		l.append(n // 2 + 1)
		print(*l)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n // 2):
		l.append(n - i)
		l.append(i + 1)
	if n % 2 != 0:
		l.append(n // 2 + 1)
	print(*l)


import heapq
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	res = []
	if n % 2 == 0:
		for i in range(n // 2):
			res.append(n - i)
			res.append(i + 1)
		print(*res)
	else:
		for i in range(n // 2):
			res.append(n - i)
			res.append(i + 1)
		res.append(n // 2 + 1)
		print(*res)


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(ejfejofjefo, ehfiefieuhef) = map(int, input().split())
	vjfhvfvhjfvn = []
	for i in range(ejfejofjefo // 2):
		vjfhvfvhjfvn.append(ejfejofjefo - i)
		vjfhvfvhjfvn.append(i + 1)
	if ejfejofjefo % 2 == 0:
		print(*vjfhvfvhjfvn)
	else:
		vjfhvfvhjfvn.append(ejfejofjefo // 2 + 1)
		print(*vjfhvfvhjfvn)


import math
from collections import defaultdict

def sol():
	(n, k) = map(int, input().split())
	last = n
	first = 1
	a = []
	while last > first:
		a.append(last)
		a.append(first)
		last -= 1
		first += 1
	if last == first:
		a.append(last)
	print(*a)

def main():
	for _ in range(int(input())):
		sol()
main()


import sys
import math
input = sys.stdin.readline
for _ in range(int(input())):
	(z, k) = map(int, input().split())
	l = []
	for i in range(z // 2):
		l.append(z - i)
		l.append(i + 1)
	if z % 2 == 0:
		print(*l)
	else:
		l.append(z // 2 + 1)
		print(*l)


def check(n, k):
	data = []
	for i in range(n // 2):
		data.append(n - i)
		data.append(i + 1)
	if n % 2 == 0:
		return data
	else:
		data.append(n // 2 + 1)
		return data
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	sharma = check(n, k)
	print(*sharma)


for _ in range(int(input())):
	(number, kmap) = map(int, input().split())
	suii = []
	for i in range(number // 2):
		suii.append(number - i)
		suii.append(i + 1)
	if number % 2 == 0:
		print(*suii)
	else:
		suii.append(number // 2 + 1)
		print(*suii)


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


test = int(input())
for i in range(test):
	sample1 = input().split(' ')
	n = int(sample1[0])
	k = int(sample1[1])
	ml = []
	for i in range(n // 2):
		ml.append(n - i)
		ml.append(i + 1)
	if n % 2 == 0:
		print(*ml)
	else:
		ml.append(n // 2 + 1)
		print(*ml)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	lst = []
	if n % 2 != 0:
		for i in range(int(n / 2) + 1):
			lst.append(n - i)
			lst.append(i + 1)
		lst.pop()
		st1 = ''
		for i in lst:
			st1 += str(i)
			st1 += ' '
		print(st1)
	else:
		for i in range(int(n / 2)):
			lst.append(n - i)
			lst.append(i + 1)
		st1 = ''
		for i in lst:
			st1 += str(i)
			st1 += ' '
		print(st1)


import sys
import math
hellonewyear = sys.stdin.readline
for _ in range(int(hellonewyear())):
	(helloworld, helloworld1) = map(int, hellonewyear().split())
	abra_cadabra = []
	for i in range(helloworld // 2):
		abra_cadabra.append(helloworld - i)
		abra_cadabra.append(i + 1)
	if helloworld % 2 == 0:
		print(*abra_cadabra)
	else:
		abra_cadabra.append(helloworld // 2 + 1)
		print(*abra_cadabra)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	z = n // 2
	l = []
	for i in range(z):
		l.append(n - i)
		l.append(i + 1)
	if n % 2 == 0:
		print(*l)
	else:
		print(*l, end=' ')
		print(n // 2 + 1)


for i in range(int(input())):
	(n, c) = map(int, input().split())
	nn = n
	p = [n]
	r = n - 1
	i = 1
	while i <= r:
		p.append(i)
		i += 1
		if i - 1 == r:
			break
		p.append(r)
		r -= 1
	print(*p)


def solve():
	(n, k) = map(int, input().split())
	lis = list(range(1, n + 1))
	(low, high) = (1, n)
	ans = list()
	while low < high:
		ans.append(lis[high - 1])
		ans.append(lis[low - 1])
		low += 1
		high -= 1
	if low == high:
		ans.append(lis[low - 1])
	print(*ans)
for _ in range(int(input())):
	solve()


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


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


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


from typing import *
from collections import *
from math import *
from functools import *
INF = 1061109567

def RI():
	return int(input())

def RAI():
	return [int(i) for i in input().split()]

def RAI_1():
	return [INF] + RAI()

def slove():
	(n, k) = RAI()
	(i, j) = (1, n)
	ans = []
	while i < j:
		ans.append(j)
		ans.append(i)
		j -= 1
		i += 1
	if i == j:
		ans.append(i)
	print(*ans)

def main():
	t = 1
	t = RI()
	for _ in range(t):
		slove()
main()


from collections import Counter
op = int(input())
for _ in range(op):
	(n, m) = map(int, input().split())
	co = 0
	o = n
	if n % 2 == 0:
		for i in range(1, n // 2 + 1):
			print(o, i, end=' ')
			o -= 1
		print()
	else:
		for i in range(1, n // 2 + 1):
			print(o, i, end=' ')
			o -= 1
		print(n // 2 + 1)


for _ in range(int(input())):
	(n, m) = [int(x) for x in input().split()]
	ans = []
	for i in range(n // 2):
		ans.append(n - i)
		ans.append(i + 1)
	if n % 2 == 0:
		print(*ans)
	else:
		ans.append(n // 2 + 1)
		print(*ans)


for __ in range(int(input())):
	(nn, kk) = map(int, input().split())
	ll = []
	for ii in range(nn // 2):
		ll.append(nn - ii)
		ll.append(ii + 1)
	if nn % 2 == 1:
		ll.append(nn // 2 + 1)
	print(*ll)


import sys

def in_int():
	return int(sys.stdin.readline())

def in_str():
	return sys.stdin.readline().rstrip()

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

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

def in_arr_str():
	return sys.stdin.readline().split()

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

def bin2dec(s):
	n = 0
	for i in range(len(s)):
		n += int(s[len(s) - i - 1]) * 2 ** i
	return n

def dec2bin(n):
	if n == 0:
		return '0'
	ans = ''
	while n > 0:
		ans += str(n % 2)
		n //= 2
	return ans[::-1]

def solve(n, m):
	arr = [0] * n
	i = 0
	(a, b) = (n, 1)
	while i < n:
		if i % 2:
			arr[i] = b
			b += 1
		else:
			arr[i] = a
			a -= 1
		i += 1
	return arr

def main():
	t = in_int()
	for _ in range(t):
		(n, k) = in_map_int()
		print(*solve(n, k))
main()


import math
import bisect
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = []
	for i in range(n // 2):
		ans.append(n - i)
		ans.append(i + 1)
	if n % 2 != 0:
		ans.append(n // 2 + 1)
		print(*ans)
	else:
		print(*ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	asif = []
	for i in range(n // 2):
		asif.append(n - i)
		asif.append(i + 1)
	if n % 2 != 0:
		a = n // 2
		b = a + 1
		asif.append(b)
		print(*asif)
	else:
		print(*asif)