N Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right. 

In the test, there are M rounds. In each round, Captain selects one position. Soldier at that position will be numbered 0. All the soldiers to the right of selected position will be numbered one greater than the soldier to his left. All the soldiers to the left of selected position will be numbered one greater than the soldier to his right. 

eg. if N = 6 and selected position is 3, then the numbering will be [3, 2, 1, 0, 1, 2].

After M rounds, Captain asked each soldier to shout out the greatest number he was assigned during the M rounds. In order to check the correctness, Captain asked you to produce the correct values for each soldier (That is the correct value each soldier should shout out).

-----Input-----
The first line of the input contains an integer T denoting the number of test cases.
First line of each test case contains two integers, N and M.
Second line of each test case contains M integers, the positions selected by Captain, in that order.

-----Output-----
For each test case, output one line with N space separated integers.

-----Constraints-----
- 1 ≤ T ≤ 10^4
- 1 ≤ N ≤ 10^5
- 1 ≤ M ≤ 10^5
- 1 ≤ Sum of N over all testcases ≤ 10^5
- 1 ≤ Sum of M over all testcases ≤ 10^5
- 0 ≤ Positions selected by captain ≤ N-1

-----Example-----
Input
2
4 1
1
6 2
2 3

Output
1 0 1 2
3 2 1 1 2 3

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
import sys
input = sys.stdin.readline
for i in range(int(input())):
	(n, m) = (int(i) for i in input().split())
	li = [int(i) for i in input().split()]
	(ma, mi) = (max(li), min(li))
	for i in range(n):
		print(max(ma - i, i - mi), end=' ')
	print()


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	m = list(map(int, input().split()))
	m.sort()
	sm = m[0]
	bg = m[-1]
	for i in range(n):
		print(max(abs(i - sm), abs(i - bg)), end=' ')
	print()


def maximum(a, b):
	if a > b:
		return a
	else:
		return b
for _ in range(int(input())):
	(n, m) = input().split()
	arr = [0] * int(n)
	val = input().split()
	maxi = 0
	mini = int(n) + 1
	for j in val:
		if int(j) > maxi:
			maxi = int(j)
		if int(j) < mini:
			mini = int(j)
	for i in range(int(n)):
		print(maximum(abs(i - mini), abs(maxi - i)), end=' ')
	print()


for t in range(int(input())):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	max1 = max(x)
	min1 = min(x)
	for i in range(n):
		y = max(max1 - i, i - min1)
		print(y, end=' ')
	print()


for i in range(int(input())):
	(n, m) = (int(i) for i in input().split())
	li = [int(i) for i in input().split()]
	(ma, mi) = (max(li), min(li))
	for i in range(n):
		print(max(ma - i, i - mi), end=' ')
	print()


for h in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	s = min(l)
	b = max(l)
	l1 = []
	for i in range(n):
		l1.append(max(abs(i - s), abs(i - b)))
	print(*l1)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().strip().split(' ')))
	l.sort()
	for i in range(n):
		print(max(abs(i - l[-1]), abs(l[0] - i)), end=' ')
	print()


t = int(input())
for i in range(t):
	res = []
	(n, m) = map(int, input().strip().split())
	p = set(map(int, input().strip().split()))
	(l, r) = (min(p), max(p))
	nl = []
	for j in range(n):
		nl.append(str(max(abs(r - j), abs(j - l))))
	res.append(' '.join(nl))
	for h in range(len(res)):
		print(res[h])


t = int(input())
for x in range(t):
	d = []
	(n, m_len) = list(map(int, input().split()))
	m = [int(x) for x in input().split()]
	m.sort()
	(a, b) = (m[0], m[-1])
	for y in range(n):
		d.append(max(y - a, b - y))
	print(*d)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	p = list(map(int, input().split()))
	if m == 1:
		s = p[0]
		b = [0] * n
		b[s] = 0
		for i in range(n):
			if i < s or i > s:
				b[i] = abs(s - i)
		print(*b)
	else:
		t = min(p)
		r = max(p)
		k = []
		r1 = [0] * n
		t1 = [0] * n
		t1[t] = 0
		r1[r] = 0
		for i in range(n):
			if i < t or i > t:
				t1[i] = abs(t - i)
			if i < r or i > r:
				r1[i] = abs(r - i)
		for i in range(n):
			k.append(max(t1[i], r1[i]))
		print(*k)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	pos = list(map(int, input().split()))
	a = max(pos)
	p = a
	x = []
	j = 0
	for i in range(n):
		if i != a and i < a:
			x.append(p)
			p -= 1
		else:
			x.append(j)
			j += 1
	b = min(pos)
	p = b
	y = []
	j = 0
	for i in range(n):
		if i != b and i < b:
			y.append(p)
			p -= 1
		else:
			y.append(j)
			j += 1
	for i in range(len(y)):
		if x[i] > y[i]:
			print(x[i], end=' ')
		else:
			print(y[i], end=' ')
	print()


T = int(input())
ans = []
for _ in range(T):
	(N, M) = [int(i) for i in input().split()]
	P = [int(i) for i in input().split()]
	left_most = N - 1
	right_most = 0
	for i in range(M):
		if P[i] > right_most:
			right_most = P[i]
		if P[i] < left_most:
			left_most = P[i]
	s = ''
	for i in range(N):
		s += str(max(abs(i - left_most), abs(i - right_most))) + ' '
	ans.append(s)
for i in ans:
	print(i)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	ma = max(l)
	mi = min(l)
	for i in range(n):
		y = max(ma - i, i - mi)
		print(y, end=' ')
	print()


test = int(input())
for _ in range(test):
	(n, m) = map(int, input().split())
	indexArray = list(map(int, input().split()))
	mini = min(indexArray)
	maxi = max(indexArray)
	result = n * [0]
	for i in range(n):
		result[i] = max(maxi - i, i - mini)
		print(result[i], end=' ')
	print()