You are given two integers $n$ and $k$. You are asked to choose maximum number of distinct integers from $1$ to $n$ so that there is no subset of chosen numbers with sum equal to $k$.

A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.


-----Input-----

The first line contains the number of test cases $T$ ($1 \le T \le 100$).

Each of the next $T$ lines contains two integers $n$ and $k$ ($1 \le k \le n \le 1000$) — the description of test cases.


-----Output-----

For each test case output two lines. In the first line output a single integer $m$ — the number of chosen integers.

In the second line output $m$ distinct integers from $1$ to $n$ — the chosen numbers.

If there are multiple answers, print any. You can print the numbers in any order.


-----Examples-----

Input
3
3 2
5 3
1 1
Output
2
3 1 
3
4 5 2 
0


-----Note-----

None

Difficulty: EASY
Tags: Greedy algorithms

Constructive algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = [i for i in range(k + 1, n + 1)]
	i = 1
	s = 0
	i = math.ceil(k / 2)
	while i <= k - 1:
		ans.append(i)
		i += 1
	print(len(ans))
	print(*ans)


import sys, math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = []
	for i in range(k + 1, n + 1):
		arr.append(i)
	for i in range((k + 1) // 2, k):
		arr.append(i)
	print(len(arr))
	print(' '.join(map(str, arr)))


def answer(n, k):
	lst = []
	for i in range(1, n + 1):
		if i == k:
			pass
		elif i <= k // 2 and k % 2 == 1:
			pass
		elif i < k // 2 and k % 2 == 0:
			pass
		else:
			lst.append(i)
	print(len(lst))
	print(' '.join(map(str, lst)))
	return

def main():
	t = int(input())
	n = [0] * t
	k = [0] * t
	for j in range(t):
		(n[j], k[j]) = [int(i) for i in input().split()]
	for j in range(t):
		answer(n[j], k[j])
main()


m = int(input())
l = []
for i in range(m):
	(a, b) = map(int, input().split())
	if b % 2 == 0:
		j = 1
	else:
		j = 0
	l.append(a - b + b // 2)
	s = ''
	for i in range(a, b, -1):
		s += str(i) + ' '
	for i in range(b, b // 2 - j, -1):
		if i != b:
			s += str(i) + ' '
	l.append(s[:-1])
for i in l:
	print(i)


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


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = []
	li = [str(i) for i in range(math.ceil(k / 2), k) if i != 0]
	li += [str(i) for i in range(k + 1, n + 1)]
	print(len(li))
	if len(li) == 0:
		pass
	else:
		print(' '.join(li))


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
print = sys.stdout.write
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().strip().split())
	print(str(n - (k + 1) // 2))
	print('\n')
	for i in range((k + 1) // 2, n + 1):
		if i == k:
			continue
		print(str(i))
		print(' ')
	print('\n')


import math
t = int(input())
pos = 0
while t:
	pos += 1
	t -= 1
	(n, k) = map(int, input().split())
	A = []
	s = 0
	for i in range(math.ceil(k / 2), k):
		if i > n:
			continue
		A.append(i)
	A.extend([x for x in range(k + 1, n + 1, 1)])
	print(len(A))
	print(' '.join(map(str, A)))


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	listt = [x for x in range(1, n + 1)]
	listt.remove(k)
	listt = listt[math.floor((k - 1) / 2):]
	stringg = ''
	for j in listt:
		stringg += str(j) + ' '
	print(len(listt))
	print(stringg)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = []
	if n == 1:
		if k == 1:
			print(0)
		else:
			print(1)
	else:
		if n > k:
			for i in range(n, k, -1):
				l.append(i)
		mx = k - 1
		for i in range(mx, int(mx / 2), -1):
			l.append(i)
		ll = len(l)
		print(ll)
		for i in range(ll):
			print(l[i], end=' ')
		print()
		l.clear()


import math

def solve(n, k):
	ans = [i for i in range(math.ceil(k / 2), k)] + [a for a in range(k + 1, n + 1)]
	print(len(ans))
	string = ' '.join(map(str, ans))
	print(string)
x = int(input())
for _ in range(x):
	A = list(map(int, input().split()))
	solve(A[0], A[1])


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


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = [i for i in range(k + 1 >> 1, k)] + [i for i in range(k + 1, n + 1)]
	print(len(ans))
	print(*ans)


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = list(map(int, input().split()))
		num = []
		x = n
		if n >= k:
			while x != k:
				num.append(x)
				x -= 1
		x -= 1
		y = k - x
		while x >= y:
			num.append(x)
			x -= 1
			y = k - x
		print(len(num))
		s = ''
		for i in range(len(num)):
			s += str(num[i]) + ' '
		print(s)
main()


import math
for _ in range(int(input())):
	c = 0
	arr = []
	(n, k) = map(int, input().split())
	for x in range(n, k, -1):
		arr.append(str(x))
		c += 1
	for x in range(math.ceil(k / 2), k):
		arr.append(str(x))
		c += 1
	if not c:
		print(0)
	else:
		print(c)
		print(' '.join(arr))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	used = set()
	a = []
	for i in range(n, 0, -1):
		if i == k:
			continue
		if i > k:
			a.append(i)
			used.add(i)
		elif not k - i in used:
			a.append(i)
			used.add(i)
	print(len(a))
	print(*a)


t = int(input())
for _ in range(t):
	(n, k) = (int(i) for i in input().split())
	res = [i for i in range((k + 1) // 2, k)] + [i for i in range(k + 1, n + 1)]
	print(len(res))
	if res:
		print(*res)


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


from math import ceil
for _ in range(int(input())):
	(n, k) = [i for i in list(map(int, input().split()))]
	li = [i for i in range(ceil(k / 2), n + 1)]
	li.remove(k)
	li = list(map(str, li))
	print(len(li))
	print(' '.join(li))


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


import sys

def solve(N, K):
	print(N - K + int(K / 2))
	out_string = ''
	for i in range(K + 1, N + 1):
		out_string += str(i)
		out_string += ' '
	for i in range(int((K + 1) / 2), K):
		out_string += str(i)
		out_string += ' '
	print(out_string)

def run():
	out = ''
	T = int(input())
	for i in range(T):
		(N, K) = [int(x) for x in input().split()]
		solve(N, K)
run()


def solve(n, k):
	nums = set(range(1, n + 1))
	nums.discard(k)
	for i in range(k):
		if k - i != i and k - i in nums:
			nums.discard(i)
	return nums

def verify(nums, k):
	snums = sorted(nums)
	for i in reversed(range(len(nums))):
		if snums[i] <= k:
			k -= snums[i]
	return k != 0
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	res = solve(n, k)
	if verify(res, k):
		print(len(res))
		print(' '.join(map(str, res)))
	else:
		raise Exception


t = int(input())
for i in range(t):
	x = tuple(map(int, input().split(' ')))
	if x[1] % 2 == 0:
		p = (x[1] - 1) // 2
	else:
		p = (x[1] - 1) // 2
	a = []
	z = p + 1
	while z < x[1]:
		a.append(z)
		z += 1
	z = x[1] + 1
	while z < x[0] + 1:
		a.append(z)
		z += 1
	print(len(a))
	if len(a) != 0:
		print(*a)


from math import ceil
results = []
t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	numbers = list(range(k + 1, n + 1))
	numbers += list(range(ceil(k / 2), k))
	results.append([len(numbers), ' '.join(map(str, numbers))])
for item in results:
	print(item[0])
	if item[0] != 0:
		print(item[1])


import sys

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())
for x in range(int(inp())):
	(n, k) = map_inp(int)
	a = [i for i in range(n, (k + 1) // 2 - 1, -1) if i != k]
	print(len(a))
	print(*a)


from math import ceil
for t in range(int(input())):
	(n, k) = map(int, input().split())
	result = list(range(ceil(k / 2), k)) + list(range(k + 1, n + 1))
	result = list(map(str, result))
	string = ' '.join(result)
	print(len(result))
	print(string)


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


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	ans = []
	if n == 1 and k == 1:
		print(0)
		continue
	elif k % 2 == 0:
		for j in range(k // 2, k):
			ans.append(j)
		for j in range(k + 1, n + 1):
			ans.append(j)
	else:
		for j in range(k // 2 + 1, k):
			ans.append(j)
		for j in range(k + 1, n + 1):
			ans.append(j)
	print(len(ans))
	print(*ans)


import itertools
import bisect
import math
from collections import *
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def main():
	t = ii()
	for test in range(t):
		(n, k) = mii()
		if n == 1 and k == 1:
			print(0)
			print()
		else:
			lst = []
			val = -1
			for i in range(2, n + 1):
				if i - 1 + i > k:
					val = i - 1
					break
			for i in range(val, n + 1):
				if i != k:
					lst.append(i)
			print(len(lst))
			print(*lst)
	pass
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 sys import stdin
from collections import Counter
from math import sqrt, factorial, log10, log, floor, ceil
from itertools import permutations, combinations, combinations_with_replacement
input = stdin.readline

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

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

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

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

def inps():
	return str(input().strip())

def pr(n):
	return stdout.write(str(n) + '\n')
INF = float('inf')

def solve():
	(n, k) = mp()
	mx_sub = []
	mx = 0
	klis = set()
	klis.add(k)
	x = 1
	k -= 1
	while k > x:
		klis.add(x)
		k -= 1
		x += 1
	for i in range(1, n + 1):
		if i not in klis:
			mx_sub.append(i)
	print(len(mx_sub))
	print(*mx_sub)
t = inp()
for i in range(t):
	solve()


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in wtf[1:]:
	(n, k) = map(int, t.split())
	N = math.ceil(k / 2) - 1
	ans = []
	for i in range(1, n + 1):
		if i <= N or i == k:
			continue
		ans.append(i)
	if len(ans) > 0:
		print(f'{len(ans)}' + '\n' + ' '.join(map(str, ans)))
	else:
		print(len(ans))


def solve(n, k):
	ansArr = []
	start = 0
	if k % 2 == 0:
		start = k // 2
	else:
		start = k // 2 + 1
	for i in range(start, k):
		ansArr.append(i)
	for i in range(k + 1, n + 1):
		ansArr.append(i)
	return ansArr
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	ansArr = solve(n, k)
	print(len(ansArr))
	for x in ansArr:
		print(x, end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [x for x in range(1, n + 1)]
	a.remove(k)
	if k % 2 == 0:
		m = k // 2 - 1
	else:
		m = k // 2
	b = a[m:]
	if n == 1:
		print(0)
	else:
		print(len(b))
	for i in b:
		print(i, end=' ')
	print()


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, k) = map(int, input().split())
	arr = []
	for i in range(k + 1, x + 1):
		arr.append(i)
	for i in range(math.ceil(k / 2), k):
		arr.append(i)
	print(len(arr))
	for i in arr:
		print(i, end=' ')
	print()


def solution(count):
	for counting in range(count):
		integer_list = input().split(' ')
		integer_list = list(map(int, integer_list))
		answer_list = []
		n = integer_list[0]
		k = integer_list[1]
		for i in range(k, n):
			now = i + 1
			answer_list.append(now)
		if n == 1:
			print('0')
			continue
		elif k % 2 == 0:
			for j in range(k // 2, k):
				answer_list.append(j)
		else:
			for j in range(k // 2 + 1, k):
				answer_list.append(j)
		print(len(answer_list))
		answer = ''
		for i in answer_list:
			answer = answer + str(i) + ' '
		print(answer)
a = int(input())
solution(a)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = [i for i in range((k + 1) // 2, n + 1) if i != k]
	print(len(arr))
	print(*arr)


import math

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

def getstr():
	return [str(i) for i in input().split()]

def solve():
	(n, k) = getint()
	ans = n - k + k // 2
	print(ans)
	if ans == 0:
		return
	for i in range(n, (k + k % 2) // 2 - 1, -1):
		if i == k:
			continue
		print(i, end=' ')
	print()
for _ in range(int(input())):
	solve()


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


for s in [*open(0)][1:]:
	(n, k) = map(int, s.split())
	l = [x for x in range((k + 1) // 2, k)] + [x for x in range(k + 1, n + 1)]
	print(len(l))
	if len(l):
		print(*l)


from __future__ import division, print_function
import math
import os
import sys
from sys import stdin, stdout
from io import BytesIO, IOBase
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def main():
	p = int(input())
	for _ in range(p):
		(n, k) = map(int, input().split())
		list1 = []
		if n == 1 and k == 1:
			print(0)
		else:
			for i in range(n, 0, -1):
				if i + (i - 1) <= k:
					list1.append(i)
					break
				else:
					list1.append(i)
			list1.remove(k)
			print(len(list1))
			print(*list1)
main()


t = int(input())
for j in range(t):
	vrem = [int(i) for i in input().split()]
	otv = [i for i in range(vrem[1] + 1, vrem[0] + 1)]
	prop = set()
	for i in range(vrem[1] - 1, 0, -1):
		if i not in prop:
			otv.append(i)
			prop.add(int(vrem[1]) - i)
	print(len(otv))
	print(*otv)


import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	(n, k) = map(int, input().strip().split(' '))
	o = []
	while n > k:
		o.append(n)
		n -= 1
	n -= 1
	while 2 * n > k - 1:
		o.append(n)
		n -= 1
	print(len(o))
	print(' '.join(map(str, o)))


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	ans = []
	for j in range(k + 1, n + 1):
		ans.append(j)
	for j in range(k, 0, -1):
		if j + j - 1 > k:
			ans.append(j - 1)
	print(len(ans))
	print(' '.join(list(map(str, ans))))
	print()


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	if k == 1:
		res = list(range(2, n + 1))
	elif k == 2:
		res = [1] + list(range(3, n + 1))
	else:
		res = list(range((k + 1) // 2, k)) + list(range(k + 1, n + 1))
	print(len(res))
	print(' '.join(map(str, res)))
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(range((k + 1) // 2, k)) + list(range(k + 1, n + 1))
	print(len(a))
	print(' '.join(map(str, a)))


for _ in range(int(input())):
	arr = [int(_) for _ in input().split()]
	l = []
	if arr[1] % 2 != 0:
		for i in range(arr[0], arr[1] // 2, -1):
			if i != arr[1]:
				l.append(i)
	else:
		for i in range(arr[0], arr[1] // 2 - 1, -1):
			if i != arr[1]:
				l.append(i)
	print(len(l))
	print(*l)


def solve():
	(n, k) = map(int, input().split())
	print(n - k + k // 2)
	final_list = []
	if n == 1:
		return
	elif k % 2 == 0:
		for i in range(int(k / 2), n + 1):
			final_list.append(i)
		final_list.remove(k)
	elif k % 2 == 1:
		for i in range(k // 2 + 1, n + 1):
			final_list.append(i)
		final_list.remove(k)
	print(' '.join(map(str, final_list)))

def main():
	for case in range(int(input())):
		solve()
main()


import math
for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = [i for i in range(n + 1) if i > k]
	for i in range(k):
		if (k + 1) // 2 <= i:
			l.append(i)
	print(len(l))
	for i in l:
		print(i, end=' ')
	print()


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	a = ''
	c = 0
	for i in range(k + 1, n + 1):
		a += '{} '.format(i)
		c += 1
	for i in range((k + 1) // 2, k):
		a += '{} '.format(i)
		c += 1
	print(c)
	print(a)


from math import ceil
t = int(input().strip())
for _ in range(t):
	(n, m) = map(int, input().split())
	ans = []
	for i in range(m + 1, n + 1):
		ans.append(i)
	for i in range(ceil(m / 2), m):
		ans.append(i)
	print(len(ans))
	print(' '.join((str(i) for i in ans)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	res = []
	for i in range((k + 1) // 2, n + 1):
		if i != k:
			res.append(i)
	res = [str(i) for i in res]
	print(len(res))
	print(' '.join(res))


import math
import os
import random
import re
import string
from sys import *
from collections import *

def bs(arr, x, l, r):
	if l <= r:
		mid = (r + l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return bs(arr, x, l, mid - 1)
		else:
			return bs(arr, x, mid + 1, r)
	else:
		return -1

def solve():
	for _ in range(int(input())):
		(n, k) = map(int, stdin.readline().strip().split())
		s = 0
		r = []
		if n == 1:
			print(0)
			continue
		if k % 2 == 1:
			x = k + 1
		else:
			x = k
		for i in range(n):
			if i + 1 >= x // 2 and i + 1 < k:
				r.append(i + 1)
			elif i + 1 > k:
				r.append(i + 1)
		print(len(r))
		print(*r)
solve()


from collections import Counter, deque, defaultdict
from itertools import accumulate, product, groupby
import operator
import math
from functools import reduce

def solve():
	(n, k) = [int(char) for char in input().split()]
	right = list(range(k + 1, n + 1))
	mid = math.ceil(k / 2)
	left = [i for i in range(mid, k)]
	rs = left + right
	print(len(rs))
	print(*rs)
for _ in range(int(input())):
	solve()


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


T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	output = list(range(k // 2 + k % 2, n + 1))
	output.remove(k)
	print(len(output))
	if len(output) > 0:
		print(*output)


def solve(n, k):
	response = [x for x in range(k + 1, n + 1)]
	options = [x for x in range(1, k)]
	while options:
		if len(options) == 1:
			response.append(options[0])
			del options[0]
		elif options[0] + options[-1] == k:
			del options[0]
			response.append(options[-1])
			del options[-1]
		else:
			response.append(options[-1])
			del options[-1]
	return response
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	r = solve(n, k)
	print(len(r))
	if r:
		print(' '.join(map(str, r)))


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
input = stdin.readline
from random import sample
t = int(input())
from collections import Counter, deque
from math import sqrt, ceil, log2, gcd

class DisjSet:

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

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

	def union(self, x, y):
		xset = self.find(x)
		yset = self.find(y)
		if xset == yset:
			return
		if self.rank[xset] < self.rank[yset]:
			self.parent[xset] = yset
		elif self.rank[xset] > self.rank[yset]:
			self.parent[yset] = xset
		else:
			self.parent[yset] = xset
			self.rank[xset] = self.rank[xset] + 1

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	while n % 2 == 0:
		n = n // 2
		cp += 1
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		while n % ps == 0:
			n = n // ps
			cp += 1
	if n != 1:
		return False
	return True

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
tt = [xa ** 3 for xa in range(0, 10 ** 4 + 1)]
qq = set(tt)
for jj in range(t):
	(n, k) = [int(x) for x in input().strip().split()]
	print(n - k + k // 2)
	u = n - k + k // 2
	count = 0
	arr = []
	for i in range(n, 0, -1):
		if count == u:
			break
		if i != k:
			arr.append(str(i))
			count += 1
	if len(arr) != 0:
		print(' '.join(arr))


t = int(input())
(x1, x2) = ([], [])
for i in range(t):
	(n, k) = list(map(int, input().split()))
	m = [i for i in range((k + 1) // 2, n + 1)]
	m.remove(k)
	x1.append(len(m))
	x2.append(' '.join(map(str, m)))
for (i, j) in zip(x1, x2):
	print(i)
	print(j)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(i + 1)
	j = 1
	z = (k - 1) // 2
	while j <= z:
		a.remove(j)
		j += 1
	a.remove(k)
	print(len(a))
	if len(a) != 0:
		print(*(i for i in a))


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


t = int(input())
for hg in range(t):
	(n, k) = map(int, input().split())
	l = []
	for i in range(k + 1, n + 1):
		l.append(i)
	for i in reversed(range(1, k)):
		d = k - i
		if d not in l:
			l.append(i)
	print(len(l))
	for i in l:
		print(int(i), end=' ')
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = []
	memo = {i: True for i in range(1, n + 1)}
	for i in range(n, 0, -1):
		if memo[i] and i != k:
			ans.append(i)
			if k > i:
				memo[k - i] = False
	print(len(ans))
	if ans:
		ans = list(map(str, ans))
		print(' '.join(ans))


from math import ceil
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [i for i in range(k + 1, n + 1)]
	for i in range(ceil(k / 2), k):
		a.append(i)
	if len(a) == 0:
		print(0)
	else:
		print(len(a))
		print(*a)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(n - (k + 1) // 2)
	subset = list(range((k + 1) // 2, n + 1))
	subset.pop(k // 2)
	print(' '.join(map(str, subset)))


from sys import stdin
from sys import stdout
from math import *
import sys
input = stdin.readline
for __ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = []
	for i in range(ceil(k / 2), n + 1):
		if i != k:
			ans.append(i)
	print(len(ans))
	if len(ans) != 0:
		print(*ans)


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


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


import sys
t = int(input())
for i in range(0, t):
	[n, k] = input().split()
	n = int(n)
	k = int(k)
	count = 0
	result = ''
	for j in range(k + 1, n + 1):
		count += 1
		result += str(j) + ' '
	for j in range(int((k + 1) / 2), k):
		count += 1
		result += str(j) + ' '
	print(count)
	if count > 0:
		print(result)


import sys
import math

def read_ints():
	inp = input().split()
	inp = [int(x) for x in inp]
	return inp

def read_strings():
	inp = input()
	s = [inp[i] for i in range(len(inp))]
	return s
t = int(input())
for _ in range(t):
	nk = read_ints()
	n = nk[0]
	k = nk[1]
	ans = []
	if n > k:
		for i in range(k + 1, n + 1):
			ans.append(i)
	if k % 2 == 0:
		st = k // 2
	else:
		st = k // 2 + 1
	for i in range(st, k):
		ans.append(i)
	ans = [str(a) for a in ans]
	print(len(ans))
	print(' '.join(ans))


from math import ceil
b = int(input())
for x in range(b):
	(n, k) = map(int, input().split())
	c = ceil(k / 2)
	print(k - c + n - k)
	for j in range(c, k):
		print(j, end=' ')
	for i in range(k + 1, n + 1):
		print(i, end=' ')


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	d = []
	for i in range(ceil(k / 2), k):
		d.append(i)
	for i in range(k + 1, n + 1):
		d.append(i)
	print(len(d))
	print(*d)


import math
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = [j for j in range(1, n + 1)]
	l.remove(k)
	l = l[math.floor((k - 1) / 2):]
	print(len(l))
	s = ''
	for i in l:
		s += str(i) + ' '
	print(s)


import sys
import math
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	if n >= m:
		if m % 2 == 0:
			c = m // 2
			for i in range(c, n + 1):
				if i != m:
					l.append(i)
		else:
			c = m // 2 + 1
			for i in range(c, n + 1):
				if i != m:
					l.append(i)
	else:
		k = 0
		for i in range(n, 0, -1):
			k += i
			if m - k in range(1, i):
				g = m - k
				j = m - k + i
				break
		if g % 2 == 0:
			u = g // 2
		else:
			u = g // 2 + 1
		for i in range(u, g):
			l.append(i)
		if (g + j) % 2 == 0:
			for i in range((g + j) // 2, n + 1):
				l.append(i)
		else:
			for i in range((g + j) // 2 + 1, n + 1):
				l.append(i)
	print(len(l))
	print(*l)


from sys import stdin, stdout
input = stdin.readline

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

def ii():
	return int(input())

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

def ins():
	return input()[:-1]
for _ in range(ii()):
	(n, k) = im()
	ans = []
	lis = []
	right = -1
	sm = 0
	for i in range((k + 1) // 2, k):
		ans.append(i)
	for i in range(k + 1, n + 1):
		ans.append(i)
	print(len(ans))
	print(*ans)


t = int(input())

def canMake(n, lst):
	for i in range(len(lst)):
		if n >= lst[i]:
			n -= lst[i]
	return n == 0

def solve():
	(n, k) = map(int, input().split())
	ans = []
	for i in reversed(range(1, n + 1)):
		comp = k - i
		if not canMake(comp, ans) and i != k:
			ans.append(i)
	print(len(ans))
	print(*ans)
for i in range(t):
	solve()


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


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	ans = []
	for i in range((K + 1) // 2, K):
		ans.append(str(i))
	for i in range(K + 1, N + 1, 1):
		ans.append(str(i))
	print(len(ans))
	if ans:
		print(' '.join(ans))


t = int(input())
for i in range(t):
	(n, k) = [int(w) for w in input().split()]
	m = []
	s = ''
	if k % 2 != 0 or k == 1:
		print(int(n - int(k / 2) - 1))
	else:
		print(int(n - int(k / 2)))
	for j in range(k + 1, n + 1):
		s += str(j) + ' '
	for p in range(int((k + 1) / 2), k):
		s += str(p) + ' '
	print(s)


def solve(n, k, ans):
	nums = []
	for i in range(k + 1, n + 1):
		nums.append(str(i))
	if k % 2 == 0:
		limit = k // 2 - 1
	else:
		limit = k // 2
	for i in range(k - 1, limit, -1):
		nums.append(str(i))
	ans.append(str(len(nums)))
	ans.append(' '.join(nums))

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, k) = map(int, input().split())
		solve(n, k, ans)
	print('\n'.join(ans))
main()


t = int(input())
for q in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	(n, k) = (L[0], L[1])
	ch = ''
	nb = 0
	for i in range(k - 1, 0, -1):
		if i <= k // 2:
			if k % 2 == 0:
				ch += str(k // 2) + ' '
				nb += 1
			break
		ch += str(i) + ' '
		nb += 1
	for i in range(k + 1, n + 1):
		ch += str(i) + ' '
		nb += 1
	print(nb)
	print(ch)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	count = 0
	s = ''
	l = math.ceil(k / 2)
	for i in range(l, k):
		s = s + str(i) + ' '
		count += 1
	for j in range(k + 1, n + 1):
		s = s + str(j) + ' '
		count += 1
	print(count)
	print(s)


t = int(input())
for i in range(t):
	s = input().split(' ')
	n = int(s[0])
	k = int(s[1])
	m = k // 2
	if k % 2 != 0:
		m += 1
	s = ''
	c = 0
	for j in range(m, n + 1):
		if j != k:
			c += 1
			s += str(j) + ' '
	if c != 0:
		print(c)
		print(s[:-1])
	else:
		print(0)


for T in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	ans = []
	for i in range(k + 1, n + 1):
		ans.append(i)
	k1 = 0
	if k % 2 == 0:
		k1 = k / 2
	else:
		k1 = k / 2 + 1
	k1 = int(k1)
	for i in range(k1, k):
		ans.append(i)
	print(len(ans))
	for i in ans:
		print(i, end=' ')
	print()


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


from functools import reduce
import os
import sys
from collections import *
from decimal import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

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

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

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

def Ceil(a, b):
	return a // b + int(a % b > 0)
albhabet = 'abcdefghijklmnopqrstuvwxyz'
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	(n, k) = value()
	ans = [x for x in range(k + 1, n + 1)]
	ans += [x for x in range(max(1, Ceil(k, 2)), k)]
	print(len(ans))
	print(*ans)


from math import ceil
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = [i for i in range(n + 1)]
	for i in range(ceil(k / 2)):
		a.remove(i)
	a.remove(k)
	print(len(a))
	print(*a)


def solve():
	(n, k) = map(int, input().split())
	A = set()
	for i in range(n, 0, -1):
		if i == k:
			continue
		if k - i in A:
			continue
		A.add(i)
	print(len(A))
	A = list(A)
	print(*A)
for _ in range(int(input())):
	solve()


import math
import operator as op
from functools import reduce
from collections import defaultdict
from math import comb
from sys import stdout
NO = 'NO'
YES = 'YES'
MOD = 1000000007

def input_int():
	return int(input())

def input_list():
	return input().split(' ')

def input_list_int():
	return list(map(int, input_list()))

def z_func(s):
	n = len(s)
	z = [0] * n
	l = r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 1
	return z
global_ans = []

def pr(a):
	global_ans.append(a)

def solve():
	(n, k) = input_list_int()
	ans = []
	for i in range(k + 1, n + 1):
		ans.append(i)
	for i in range(math.ceil(k / 2), k):
		ans.append(i)
	pr(len(ans))
	if len(ans):
		pr(' '.join((str(x) for x in ans)))
query_count = 1
query_count = input_int()
while query_count:
	query_count -= 1
	solve()
for global_ans_line in global_ans:
	print(global_ans_line)


t = int(input())
for x in range(t):
	(n, k) = map(int, input().split())
	count = k // 2
	print(count + n - k)
	if k % 2 == 0:
		start = count
	else:
		start = count + 1
	for numb in range(start, n + 1):
		if numb != k:
			print(numb, end=' ')
	print('')


import math

def main():
	t = int(input())
	result = []
	for _ in range(t):
		(n, k) = map(int, input().split())
		ans = []
		half = math.ceil(k / 2)
		for v in range(n, 0, -1):
			if v > k:
				ans.append(str(v))
			elif half <= v < k:
				ans.append(str(v))
		n = len(ans)
		result.append(f"{n}\n{' '.join(ans)}")
	print('\n'.join(result))
main()


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


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = k - 1
	b = k - 2
	if a > 0:
		c = [a]
	else:
		c = []
	while a > 0 and b > 0 and (a + b > k):
		c.append(b)
		a -= 1
		b -= 1
	c += list(range(k + 1, n + 1))
	print(len(c))
	print(*c)


import math
t = int(input())
j = 0
while j < t:
	(n, k) = tuple(map(int, input().split()))
	if True:
		x = []
		l = []
		for i in range(n):
			x.append(i + 1)
		for num in x[k:]:
			l.append(str(num))
		m = math.floor((k - 1) / 2)
		for num in x[m:k - 1]:
			l.append(str(num))
		print(len(l))
		print(' '.join(l))
	j += 1


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


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = []
	for i in range(math.ceil(k / 2), k):
		l.append(i)
	for i in range(k + 1, n + 1):
		l.append(i)
	print(len(l))
	for i in l:
		print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	temp = [int(x) for x in input().split()]
	n = temp[0]
	k = temp[1]
	result = []
	if k % 2 == 0:
		x = k // 2
	else:
		x = k // 2 + 1
	for i in range(x, k):
		result.append(i)
	for i in range(k + 1, n + 1):
		result.append(i)
	result = [str(x) for x in result]
	print(len(result))
	print(' '.join(result))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	r = []
	for i in range((k + 1) // 2, k):
		r.append(i)
	for i in range(k + 1, n + 1):
		r.append(i)
	print(len(r))
	res = ' '.join((str(x) for x in r))
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	count = 0
	answer = [str(i) for i in range((k + 1) // 2, k)]
	answer += [str(i) for i in range(k + 1, n + 1)]
	print(len(answer))
	if len(answer) != 0:
		print(' '.join(answer))
	else:
		print()


for _ in range(int(input())):
	arr = list(map(int, input().split()))
	x = list(range(1, arr[0] + 1))
	x.remove(arr[1])
	y = x
	for i in range(arr[1] - 1, arr[1] // 2, -1):
		y.remove(arr[1] - i)
	print(len(y))
	if y != []:
		for x in y:
			print(x, end=' ')
	print('')


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = []
	val = k // 2
	if k % 2 == 1:
		val = val + 1
	for i in range(val, k):
		A.append(i)
	for i in range(k + 1, n + 1):
		A.append(i)
	print(len(A))
	print(*A)


def solve(n, k):
	number_set = list(range((k + 1) // 2, k)) + list(range(k + 1, n + 1))
	print(len(number_set))
	print(' '.join(map(str, number_set)))

def anti_knapsack():
	for _ in range(int(input())):
		(n, k) = input().split()
		solve(int(n), int(k))
anti_knapsack()


def find_numbers(n, k):
	numbers = list(range(1, n + 1))
	k -= 1
	result = numbers[k + 1:]
	half_numbers = numbers[k // 2:k]
	result += half_numbers
	return result

def main():
	numbers = int(input())
	results = []
	for i in range(numbers):
		(n, k) = list(map(int, input().split(' ')))
		results.append(find_numbers(n, k))
	for r in results:
		print(len(r))
		if len(r) != 0:
			print(' '.join(map(str, r)))
main()


T = int(input())
for t in range(T):
	ans = []
	(n, k) = map(int, input().split())
	if k % 2 == 0:
		print(len(list(range(k // 2, k)) + list(range(k + 1, n + 1))))
		print(*list(range(k // 2, k)) + list(range(k + 1, n + 1)))
	else:
		print(len(list(range(k // 2 + 1, k)) + list(range(k + 1, n + 1))))
		print(*list(range(k // 2 + 1, k)) + list(range(k + 1, n + 1)))


import sys
input = sys.stdin.readline
from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = 0
	ans += n - k
	ans += k // 2
	print(ans)
	for i in range((k + 1) // 2, n + 1):
		if i != k:
			print(i, end=' ')
	print('')


for i in range(int(input())):
	(n, k) = map(int, input().split())
	if k % 2 == 0:
		a = int(k / 2)
		print(n - k + a)
		if n - k + a == 0:
			continue
	else:
		a = k // 2 + 1
		print(n - k + a - 1)
		if n - k + a - 1 == 0:
			continue
	l = [j for j in range(a, k)] + [l for l in range(k + 1, n + 1)]
	pr = ' '.join((str(ele) for ele in l))
	print(pr)


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


import sys, math
import copy
import heapq
from collections import deque
input = sys.stdin.readline

def ip():
	return int(input())

def sp():
	return str(input().rstrip())

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

def msp():
	return map(str, input().split())

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

def lmsp():
	return list(map(str, input().split()))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)

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

def find(x):
	if x == p[x]:
		return x
	q = find(p[x])
	p[x] = q
	return q

def union(x, y):
	global n
	x = find(x)
	y = find(y)
	if x != y:
		p[y] = x
tc = ip()
while tc:
	tc -= 1
	(n, k) = mip()
	ans = []
	for i in range(1, n + 1):
		if i <= (k - 1) // 2:
			continue
		if i == k:
			continue
		ans.append(i)
	print(len(ans))
	print(*ans)


from math import ceil
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	subset = []
	for i in range(ceil(k / 2), k):
		subset.append(str(i))
	for i in range(k + 1, n + 1):
		subset.append(str(i))
	print(len(subset))
	print(' '.join(subset))


tt = int(input())
for _ in range(tt):
	(n, k) = map(int, input().split())
	a = [i for i in range(1, n + 1) if i != k and (i > k or 2 * i >= k)]
	print(len(a))
	print(*a)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ban = set()
	ans = []
	for i in reversed(range(1, n + 1)):
		if i > k:
			ans.append(i)
		elif i == k:
			continue
		elif i not in ban:
			ans.append(i)
			ban.add(k - i)
	print(len(ans))
	print(*ans)


from sys import stdin
input = stdin.readline
for tt in range(int(input())):
	(n, k) = map(int, input().split())
	ans = [i for i in range((k - 1) // 2 + 1, n + 1) if i != k]
	print(len(ans))
	print(*ans)


import math
from collections import defaultdict, Counter
from itertools import permutations
from decimal import Decimal, localcontext
from collections import defaultdict
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))

def main():
	for _ in range(int(input())):
		(n, k) = li()
		s = set()
		for i in range(n, 0, -1):
			if k - i not in s and i != k:
				s.add(i)
		print(len(s))
		if len(s) > 0:
			print(*s)
import os, 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')
from math import gcd

def find(l):
	c = 0
	for i in range(len(l)):
		if l[i] > 1:
			c = i
			return c
	else:
		return None

def checkDivisibility(n, digit):
	return digit != 0 and n % digit == 0

def allDigitsDivide(n):
	nlist = list(map(int, set(str(n))))
	for digit in nlist:
		if digit != 0 and (not checkDivisibility(n, digit)):
			return False
	return True

def lcm(s):
	a = [int(d) for d in str(s)]
	lc = a[0]
	for i in a[1:]:
		if i != 0:
			lc = lc * i // gcd(lc, i)
	return lc
main()

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = [1]
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def fact(n):
	return 1 if n == 1 or n == 0 else n * fact(n - 1)

def prime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	a = []
	for j in range((k + 1) // 2, n + 1):
		if j != k:
			a.append(j)
	print(len(a))
	for _ in a:
		print(_, end=' ')
	print(' ')


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


import math
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		f = 0
		if k % 2 == 0:
			f = math.floor(k / 2)
		else:
			f = math.floor(k / 2) + 1
		lst = [i for i in range(f, k)]
		if k != n:
			lst = lst + [i for i in range(k + 1, n + 1)]
		print(len(lst))
		s = ' '.join([str(i) for i in lst])
		print(s)


k = int(input())
while k > 0:
	lista = list(map(int, input().split()))
	n = lista[0]
	x = lista[1]
	raspunsul = ''
	if x % 2 == 0:
		jos = int(x / 2)
	else:
		jos = int((x + 1) / 2)
	cate = n - jos
	print(cate)
	if cate > 0:
		for j in range(jos, n + 1):
			if j != x:
				raspunsul = raspunsul + str(j) + ' '
		print(raspunsul)
	k = k - 1


from functools import lru_cache
from itertools import combinations
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	post_k = tuple(range(k + 1, n + 1))
	pre_k = tuple(range((k + 1) // 2, k))
	ans = pre_k + post_k
	print(len(ans))
	if ans:
		print(' '.join(map(str, ans)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ls = []
	for i in range(k // 2):
		ls.append(k - i - 1)
	for i in range(k + 1, n + 1):
		ls.append(i)
	print(len(ls))
	for i in ls:
		print(i, end=' ')
	print()


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


for w in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	l = []
	for i in range(k + 1, n + 1):
		l.append(i)
	for i in reversed(range(k // 2, k + 1)):
		if i > k - i and k - i >= 1:
			l.append(i)
		elif i == k - i:
			l.append(i)
	print(len(l))
	for i in range(len(l)):
		print(l[i], end=' ')
	print()


from math import ceil

def fun(ls):
	(n, k) = ls
	ans = []
	if n > k:
		for i in range(ceil(k / 2), n + 1):
			if i != k:
				ans.append(i)
		if len(ans) == 1 and ans[0] == 0:
			print(0)
			return
		print(len(ans))
		print(*reversed(ans))
	else:
		extra = k - n
		for i in range(ceil(k / 2), n + 1):
			if i != k:
				ans.append(i)
		if len(ans) == 1 and ans[0] == 0:
			print(0)
			return
		print(len(ans))
		print(*reversed(ans))
T = int(input())
for i in range(T):
	ls = list(map(int, input().split()))
	fun(ls)


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	s = []
	for i in range((k + 1) // 2, k):
		s.append(i)
	for i in range(k + 1, n + 1):
		s.append(i)
	print(len(s))
	print(' '.join(map(str, s)))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	aftr_k = list(range(k + 1, n + 1))
	half_half = k // 2
	if k % 2 != 0:
		half_half += 1
	bfr_k = list(range(half_half, k))
	print(len(aftr_k) + len(bfr_k))
	print(' '.join([str(i) for i in aftr_k + bfr_k]))


def solve1():
	(n, k) = map(int, input().split())
	a = []
	for i in range(k + 1, n + 1):
		a.append(i)
	t = (k + 1) // 2
	for i in range(t, k):
		a.append(i)
	print(len(a))
	print(*a)
for testis in range(int(input())):
	solve1()


import math
import sys
from collections import *

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

def cstr():
	return list(map(str, input().split(' ')))

def solve(t):
	(n, k) = cint()
	lst = []
	for i in range(k + 1, n + 1):
		lst.append(i)
	s = set()
	for i in range(k - 1, 0, -1):
		if i not in s:
			lst.append(i)
			s.add(k - i)
	print(len(lst))
	for item in lst:
		print(item, end=' ')
	print()
t = int(input())
for i in range(1, t + 1):
	solve(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())

def check(arr, k):
	result = arr
	size = len(arr)
	balance = 0
	for i in range(size):
		checker = k - arr[i - balance]
		if checker in arr and checker != arr[i - balance]:
			result.remove(checker)
			balance += 1
	return result

def solve(n, k):
	arr = range(n + 1)[:0:-1]
	result = []
	small = []
	for elem in arr:
		if elem > k:
			result.append(elem)
		elif elem < k:
			small.append(elem)
	small = check(small, k)
	result += small
	size = len(result)
	print(size)
	if size != 0:
		print(' '.join(map(str, result)))

def main():
	T = inp()
	while T > 0:
		(n, k) = inlt()
		solve(n, k)
		T -= 1
main()


from math import ceil
import os
import sys
from io import BytesIO, IOBase

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

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

def int_inp():
	return int(input())

def solution():
	(n, k) = mul_input()
	val = ceil(k / 2)
	print(n - val)
	for i in range(val, n + 1):
		if i != k:
			print(i, end=' ')
	print()
	return

def main():
	testcases = 1
	testcases = int(input())
	for _ in range(testcases):
		solution()
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))

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


for _ in range(int(input())):
	n_k = list(map(int, input().strip().split()))
	n = n_k[0]
	k = n_k[1]
	answ = []
	for i in range(k + 1, n + 1):
		answ.append(i)
	bad = []
	for i in range(0, k + 1):
		bad.append(0)
	bad[-1] = 1
	bad[0] = 1
	for i in range(k, -1, -1):
		if bad[i] == 0:
			answ.append(i)
			bad[k - i] = 1
	print(len(answ))
	answ = list(map(str, answ))
	print(' '.join(answ))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = set()
	tmp = set()
	for x in range(1, n + 1):
		tmp.add(x)
	ans.add(k)
	if k % 2:
		for x in range(1, k // 2 + 1):
			ans.add(x)
	else:
		for x in range(1, k // 2):
			ans.add(x)
	tmp = list(tmp - ans)
	print(len(tmp))
	print(' '.join(map(str, tmp)))


for _ in [*open(0)][1:]:
	(n, k) = map(int, _.split())
	print(n - (k + 1) // 2)
	print(' '.join([str(i) for i in range((k + 1) // 2, k)]) + ' ' + ' '.join([str(j) for j in range(k + 1, n + 1)]))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = math.ceil(k / 2)
	m = n - k
	answer = ''
	while A < k:
		m += 1
		answer += str(A) + ' '
		A += 1
	k += 1
	while k <= n:
		answer += str(k) + ' '
		k += 1
	print(m)
	print(answer)


def enka(n, k):
	m = 0
	lista = ''
	if n > k:
		m += n - k
		t = k + 1
		while t <= n:
			lista += str(t)
			lista += ' '
			t += 1
	if k % 2 == 0:
		f = (k - 1) // 2 + 1
	else:
		f = (k - 1) // 2
	m += f
	z = k - f
	while z < k:
		lista += str(z)
		lista += ' '
		z += 1
	print(m)
	print(lista)
prim = int(input())
while prim > 0:
	ucita = input().split(' ')
	n = int(ucita[0])
	k = int(ucita[1])
	enka(n, k)
	prim -= 1


import math
t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	ans = n - math.ceil(k / 2)
	print(ans)
	ar = []
	for i in range(k + 1, n + 1):
		ar.append(i)
	for i in range(math.ceil(k / 2), k):
		ar.append(i)
	for i in range(len(ar)):
		print(ar[i], end=' ')
	print()


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()
	r = []
	for i in range(k + 1, n + 1):
		r.append(i)
	i = k - 1
	s = set()
	s.add(i)
	while i >= 1:
		if k - i in s and i * 2 != k:
			break
		r.append(i)
		i -= 1
		s.add(i)
	print(len(r))
	print(*r)


for _ in range(int(input())):
	(n, m) = (int(x) for x in input().split())
	ans = n - m + m // 2
	print(ans)
	for i in range(n, m, -1):
		print(i, end=' ')
	for i in range(m - 1, (m + 1) // 2 - 1, -1):
		print(i, end=' ')
	if ans:
		print()


import math
for _ in range(0, int(input())):
	(n, k) = [int(j) for j in input().split()]
	l = []
	for i in range(1, n + 1):
		l.append(i)
	a = math.ceil(k / 2) - 1
	main = l[a:]
	del main[main.index(k)]
	print(len(main))
	d = ''
	for e in main:
		d = str(e) + ' ' + d
	print(d)


t = int(input())
while t > 0:
	(n, k) = list(map(int, input().split()))
	if k % 2 == 0:
		res = [i for i in range(k // 2, n + 1)]
	else:
		res = [i for i in range(k // 2 + 1, n + 1)]
	if k in res:
		res.remove(k)
	print(len(res))
	print(' '.join(map(str, res)))
	t -= 1


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


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


t = int(input())
while t:
	t -= 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	val = ''
	count = 0
	for i in range(k + 1, n + 1):
		count += 1
		val += str(i) + ' '
	for i in range(k - 1, 0, -1):
		if i + i + 1 > k:
			val += str(i) + ' '
			count += 1
	print(count)
	print(val)


def solve_tc():
	(n, k) = map(int, input().split())
	ans = []
	if k % 2 == 1:
		ki = k // 2 + 1
	else:
		ki = k // 2
	for i in range(ki, n + 1):
		if k != i:
			ans.append(i)
	return (ans, len(ans))
t = int(input())
while t > 0:
	t -= 1
	(m, l) = solve_tc()
	print(str(l))
	print(' '.join(list(map(str, m))))


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


def sieve():
	prime = [1] * 1000005
	prime[0] = 0
	prime[1] = 0
	p = 2
	while p * p < 1000005:
		if prime[p] == 1:
			for i in range(p * p, 1000001, p):
				prime[i] = 0
		p += 1
	return prime

def power(x, y):
	res = 1
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x
		y //= 2
		x *= x
	return res
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = []
	if n > k:
		for i in range(k + 1, n + 1):
			l.append(i)
		for i in range((k + 1) // 2, k):
			l.append(i)
		print(len(l))
		print(*l)
	elif k == 1 and n == 1:
		print(0)
	else:
		for i in range((k + 1) // 2, k):
			l.append(i)
		print(len(l))
		print(*l)


N = int(input())
for _ in range(N):
	(n, k) = map(int, input().split())
	number = [i for i in range(1, n + 1) if i != k and (i > k or i * 2 >= k)]
	print(len(number), '\n', *number)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	ret = list(range(k + 1 >> 1, k)) + list(range(k + 1, n + 1))
	print(len(ret))
	print(' '.join(map(str, ret)))


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


cases = input()
for i in range(0, int(cases)):
	ent = input().split(' ')
	n = ent[0]
	k = ent[1]
	res = []
	for i in range(int(k) + 1, int(n) + 1):
		res.append(i)
	if int(k) % 2 == 0:
		for i in range(int(int(k) / 2), int(k)):
			res.append(i)
	else:
		for i in range(int(int(k) / 2) + 1, int(k)):
			res.append(i)
	if len(res) == 0:
		print(0)
	else:
		print(len(res))
		print(str(res).replace('[', '').replace(']', '').replace(',', ''))