*Gormint aunty is very upset with the government and Imran wants to prove that his government is not sold out. Gormint aunty gives an ethical problem which only an honest person could solve. Help Imran solve this question.*

You are given two integers N and K. Find the minimum number of colors needed to color a circular array of size N such that the following condition is satisfied:   
For any subarray of size K, there should not be any repeating colors.

Also construct one such array. If there are many possible arrays, you may print any one of them. Each color will be represented by a unique number between 1 and X, where X is the number of distinct colors needed to build this array.

Note: A circular array is one wherein the first element is adjacent to the last. For example, given the circular array [1,2,3], all possible subarrays of size 2 are: [1,2], [2,3], [3,1].

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

- The first line of input will contain a single integer T, denoting the number of test cases.
- The first and only line of each test case contains two space-separated integers N and K, as described in the statement.

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

For each test case, output two lines:
- The first line should contain a single integer X, denoting the minimum number of colors needed to build the array.
- The second line should contain N space-separated integers denoting the elements of the array. Each element of the array should be an integer between 1 and X, denoting the color of this element; and no subarray of this array of length K should contain repeated colors. If there are multiple such arrays, print any of them.

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

$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 5 \cdot 10^{5}$
$1 ≤ K ≤ N$
- The sum of $N$ over all test cases won't exceed $5 \cdot 10^{5}$.

----- Sample Input 1 ------ 
3
5 4
3 1
6 3

----- Sample Output 1 ------ 
5
1 2 3 4 5
1
1 1 1
3
1 2 3 1 2 3
----- explanation 1 ------ 
Test case $1$: All elements of the given array are distinct, so it obviously satisfies the condition.  
It can be shown that in this case, $4$ colors is not enough to construct a solution.

Test case $2$: Every subarray of length $1$ contains a single element, and hence no repeated colors.

Difficulty: VERY_HARD
Tags: Constructive algorithms

Ad-hoc

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	rem = n % k
	rep = n // k
	even = rem // rep
	dis = rem % rep
	ex = rep - dis
	print(k + even + min(dis, 1))
	cycle = list(range(1, k + even + min(dis, 1) + 1))
	extra = list(range(1, k + even + 1))
	carr = cycle * dis + extra * ex
	print(' '.join(map(str, carr)))


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	rem = k + (n % k + n // k - 1) // (n // k)
	ans = [0] * rem
	for i in range(rem):
		ans[i] = i + 1
	res = []
	for j in range(n):
		res.append(ans[j % rem])
	print(rem)
	print(' '.join(map(str, res)))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	x = n // k
	m = n % k
	l = []
	for i in range(x):
		l.append(k)
	if x >= m:
		for i in range(m):
			l[i] += 1
	else:
		while x < m:
			for i in range(x):
				l[i] += m // x
			m = m % x
		for i in range(m):
			l[i] += 1
	res = []
	for i in l:
		for j in range(i):
			res.append(j + 1)
	print(max(l))
	print(*res)


import math
for _ in range(int(input())):
	(N, X) = map(int, input().split())
	res = X + math.ceil(N % X / (N // X))
	print(res)
	i = 1
	while i <= N:
		if i % res == 0:
			print(res, end=' ')
		else:
			print(i % res, end=' ')
		i += 1
	print()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	cols = k + (n % k + n // k - 1) // (n // k)
	print(cols)
	ans = [[i for i in range(1, k + 1)] for _ in range(n // k)]
	n -= k * (n // k)
	for col in range(k + 1, cols + 1):
		for list in ans:
			if n > 0:
				list.append(col)
				n -= 1
	for list in ans:
		print(*list, end=' ')
	print()


import math as m
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ans = []
	t = k + m.ceil(n % k / m.floor(n / k))
	for i in range(1, n // t + 1):
		for j in range(1, t + 1):
			ans.append(j)
	for i in range(1, n % t + 1):
		ans.append(i)
	print(t)
	print(*ans)


for tc in range(int(input())):
	(n, k) = map(int, input().split())
	x = n // k
	mod = n % k
	l = []
	for i in range(x):
		l.append(k)
	if x >= mod:
		for i in range(mod):
			l[i] += 1
	else:
		while x < mod:
			for i in range(x):
				l[i] += mod // x
			mod = mod % x
		for i in range(mod):
			l[i] += 1
	lst = []
	for i in l:
		for j in range(i):
			lst.append(j + 1)
	print(max(l))
	for i in lst:
		print(i, end=' ')
	print()


from sys import stdin
input = stdin.readline

def solve(N, K):
	BLOC = N // K
	remain1 = N % K
	addon = remain1 // BLOC
	remain2 = remain1 % BLOC
	count = K + addon
	if remain2 != 0:
		count += 1
	answer = list(range(1, K + addon + 2)) * remain2 + list(range(1, K + addon + 1)) * (BLOC - remain2)
	assert len(answer) == N
	return (count, answer)
T = int(input().strip())
for problem in range(1, T + 1):
	(N, K) = [int(x) for x in input().strip().split()]
	answer = solve(N, K)
	print(answer[0])
	print(*[a for a in answer[1]])


def min_colors(n, k):
	i = k
	while i <= n:
		if 1 + (n - 1) % i >= k:
			break
		i += 1
	return i
ans = []
nq = int(input())
for _ in range(nq):
	inp = input().split()
	n = int(inp[0])
	k = int(inp[1])
	val = ''
	nCol = k
	aa = list(map(str, list(range(1, k + 1))))
	A = [' '.join(aa)] * (n // k)
	extras = n % k
	while extras > 0:
		nCol += 1
		for i in range(len(A)):
			A[i] = str(nCol) + ' ' + A[i]
			extras += -1
			if extras == 0:
				break
	ans.append(nCol)
	colors = ' '.join(A)
	ans.append(colors.strip())
print(*ans, sep='\n')


import math
t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().strip().split(' ')))
	if k == 1:
		print('1')
		for i in range(n):
			if i == n - 1:
				print('1')
			else:
				print('1', end=' ')
	else:
		ansNum = k + math.ceil(n % k / (n // k))
		print(ansNum)
		val = 0
		for i in range(n):
			val = val % ansNum + 1
			if i == n - 1:
				print(val)
			else:
				print(val, end=' ')