The ugliness of a sequence of size N is defined as the number of pairs of neighboring elements which are not equal to each other. Formally, the ugliness of a sequence increase by 1 if for a value of i, 2 ≤ i ≤ N, the following condition holds true:
A_{i} \neq A_{i-1}.

Examples: 
[1, 2, 2, 3], ugliness is 2.
[2, 1, 2, 3,4], ugliness is 4.

You are given a sequence A of length N consisting of the first K natural numbers only. Each of the first K natural numbers occur at least once in the given sequence. For each value of K, you are supposed to remove all of its occurrences from the original sequence and determine the ugliness of the resulting sequence.

Note:  An empty sequence has ugliness of 0.

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

- First line will contain T, the number of test cases. Then the testcases follow.
- Each testcase consist of two lines of input
- First line contains two integers N, K 
- Second line contains N space-separated integers, where the i^{th} integer denotes the i^{th} element of the sequence A.

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

- For each testcase print K space-separated integers denoting the answer for that testcase.

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

$1 ≤ T ≤ 1000$
$1 ≤ K ≤ N ≤ 10^{5}$
- For each $i$, $1 ≤ A_{i} ≤ K$
- Every number from $1$ to  $K$ appears atleast once
- Sum of N over all cases doesn't exceed $10^{5}$

----- Sample Input 1 ------ 
2
8 2
1 2 1 2 2 2 1 2
8 3
1 2 2 1 1 1 2 3
----- Sample Output 1 ------ 
0 0
1 1 3

----- explanation 1 ------ 
Test case 1:
- By removing 1, we get the sequence: $[2, 2, 2, 2, 2]$. Since all the elements are the same, ugliness is $0$
- By removing 2, we get the sequence: $[1, 1, 1]$. Since all the elements are the same, ugliness is $0$

Test case 2:
- By removing 1, we get the sequence: $[2, 2, 2, 3]$. Since the 3rd and 4th elements are not equal, ugliness is $1$.
- By removing 2, we get the sequence: $[1, 1, 1, 1, 3]$. Since the 3rd and 4th elements are not equal, ugliness is $1$.
- By removing 3, we get the sequence: $[1, 2, 2, 1, 1, 1, 2]$. Since 1st and 2nd, 3rd and 4th, 6th and 7th are not equal, total ugliness is $3$.

Difficulty: MEDIUM_HARD

Solutions:
from sys import stdin
rline = stdin.readline
rfile = stdin.read

def rt(tip=int):
	return tip(rline())

def rts(tip=int, way=rline):
	return [tip(v) for v in way().split()]

def solve():
	T = rt()
	while T > 0:
		T -= 1
		(N, K) = rts()
		A = []
		p = -1
		for v in rts():
			if v != p:
				A.append(v)
				p = v
		N = len(A)
		born_after_remove = [0] * (K + 1)
		current = [0] * (K + 1)
		S = 0
		for n in range(N - 1):
			if n > 0:
				born_after_remove[A[n]] += A[n - 1] != A[n + 1]
			current[A[n]] += 1
			current[A[n + 1]] += 1
			S += 2
		ret = [0] * (K + 1)
		for k in range(1, K + 1):
			ret[k] = (S - 2 * current[k]) // 2 + born_after_remove[k]
		print(' '.join((str(ret[k]) for k in range(1, K + 1))))
solve()


import sys
for _ in range(int(sys.stdin.readline())):
	(n, k) = list(map(int, sys.stdin.readline().split()))
	case = list(map(int, sys.stdin.readline().split()))
	if k == 1:
		print(0)
		continue
	prev = -1
	arr = []
	ugly = -1
	for c in case:
		if c != prev:
			arr.append(c)
			prev = c
			ugly += 1
	out = [ugly] * k
	for a in range(len(arr)):
		before = arr[a - 1]
		now = arr[a]
		if a + 1 == len(arr):
			nex = arr[0]
		else:
			nex = arr[a + 1]
		if a == 0 or a == len(arr) - 1:
			out[now - 1] -= 1
		elif before == nex:
			out[now - 1] -= 2
		else:
			out[now - 1] -= 1
	sys.stdout.write(str(' '.join(list(map(str, out)))) + '\n')


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	d = defaultdict(list)
	for i in range(k):
		d[i + 1] = [0, 0]
	l = -1
	c = 0
	for i in range(n - 1):
		if A[i] != A[i + 1]:
			if l == A[i + 1]:
				d[A[i]][1] += 1
			else:
				d[A[i]][0] += 1
			c += 1
			l = A[i]
	if c >= 1:
		d[A[-1]][0] += 1
	ans = []
	for i in range(k):
		ans.append(c - d[i + 1][0] - d[i + 1][1] * 2)
	print(*ans)


for _ in range(int(input())):
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split())) + ['#']
	B = ['#']
	for i in range(1, N + 1):
		if A[i] != A[i - 1]:
			B.append(A[i - 1])
	B.append('#')
	ht = {}
	for i in range(1, len(B) - 1):
		if B[i] not in ht:
			ht[B[i]] = 0
		if B[i - 1] != B[i + 1]:
			ht[B[i]] += 1
		else:
			ht[B[i]] += 2
	if K == 1:
		print(0)
	else:
		print(' '.join([str(len(B) - 3 - ht[k + 1]) for k in range(K)]))


t = int(input())
for tt in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if k == 1:
		print(0)
		continue
	elif k == 2:
		print('0 0')
		continue
	brr = [arr[0]]
	count = 0
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			brr.append(arr[i])
			count += 1
	temp = {}
	if n > 1:
		if brr[0] != brr[1]:
			temp[brr[0]] = 1
	for i in range(1, len(brr) - 1):
		if brr[i - 1] != brr[i + 1]:
			if brr[i] not in temp.keys():
				temp[brr[i]] = 1
			else:
				temp[brr[i]] += 1
		elif brr[i] not in temp.keys():
			temp[brr[i]] = 2
		else:
			temp[brr[i]] += 2
	m = len(brr)
	if brr[m - 1] != brr[m - 2]:
		if brr[m - 1] not in temp.keys():
			temp[brr[m - 1]] = 1
		else:
			temp[brr[m - 1]] += 1
	result = []
	for i in range(k):
		result.append(count - temp[i + 1])
	print(*result)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ugly = [0] * k
	prev = -1
	same = 0
	for i in range(n - 1):
		if prev != -1 and prev != a[i + 1] and (a[i + 1] != a[i]) and (prev != a[i]):
			ugly[a[i] - 1] -= 1
		if a[i] != a[i + 1]:
			ugly[a[i] - 1] += 1
			ugly[a[i + 1] - 1] += 1
			prev = a[i]
		elif a[i] == a[i + 1]:
			same += 1
	ugly = [n - i - 1 - same for i in ugly]
	print(*ugly)


import math
for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	prev = l[0]
	ind = 0
	d = {}
	for i in range(n):
		if l[i] == prev:
			continue
		else:
			p = [ind, i - 1]
			if prev in d:
				d[prev].append(p)
			else:
				d[prev] = [p]
			prev = l[i]
			ind = i
	p = [ind, n - 1]
	if prev in d:
		d[prev].append(p)
	else:
		d[prev] = [p]
	prev = l[n - 1]
	ind = n - 1
	ugli = 0
	for i in range(1, n):
		if l[i] != l[i - 1]:
			ugli += 1
	ans = []
	for i in range(1, k + 1):
		u = ugli
		for j in d[i]:
			x = j[0]
			y = j[1]
			if x == 0 or y == n - 1:
				u = u - 1
			elif l[x - 1] == l[y + 1]:
				u = u - 2
			else:
				u = u - 1
		ans.append(u)
	if k == 1:
		print(0)
	else:
		print(*ans)


from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	cur = 0
	for i in range(1, n):
		if a[i] != a[i - 1]:
			cur += 1
	x = [0] * (k + 1)
	last = -1
	for i in range(n):
		if i > 0 and a[i] != a[i - 1]:
			x[a[i]] += 1
			if a[i] == last or last == -1:
				x[a[i - 1]] += 1
			last = a[i - 1]
	x = x[1:]
	for i in range(k):
		x[i] = cur - x[i]
	print(*x)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	st = []
	newlis = []
	for i in range(n - 1):
		if lis[i] != lis[i + 1]:
			newlis.append(lis[i])
	newlis.append(lis[-1])
	nnew = len(newlis)
	res = [nnew - 1] * (k + 1)
	if nnew == 1:
		print(0)
	else:
		for i in range(nnew - 2):
			if newlis[i] == newlis[i + 2]:
				res[newlis[i + 1]] -= 2
			else:
				res[newlis[i + 1]] -= 1
		res[newlis[0]] -= 1
		res[newlis[-1]] -= 1
		print(*res[1:])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.append('#')
	ans = []
	for i in range(n):
		if arr[i] != arr[i + 1]:
			ans.append(arr[i])
	n = len(ans)
	check = [0] * (k + 2)
	for i in range(1, n):
		if i == 1:
			(p1, p2) = (min(ans[i], ans[i - 1]), max(ans[i], ans[i - 1]))
			if p1 + 1 == p2:
				check[0] += 1
				check[p1] -= 1
				check[p2 + 1] += 1
			else:
				check[0] += 1
				check[p1] -= 1
				check[p1 + 1] += 1
				check[p2] -= 1
				check[p2 + 1] += 1
		elif ans[i] == ans[i - 2]:
			(p1, p2) = (min(ans[i], ans[i - 1]), max(ans[i], ans[i - 1]))
			if p1 + 1 == p2:
				check[0] += 1
				check[p1] -= 1
				check[p2 + 1] += 1
			else:
				check[0] += 1
				check[p1] -= 1
				check[p1 + 1] += 1
				check[p2] -= 1
				check[p2 + 1] += 1
		else:
			p1 = ans[i]
			check[0] += 1
			check[p1] -= 1
			check[p1 + 1] += 1
	for i in range(1, k + 2):
		check[i] += check[i - 1]
	print(*check[1:k + 1])


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [a[0]]
	for i in range(1, n):
		if a[i] == a[i - 1]:
			continue
		else:
			b.append(a[i])
	us = len(b) - 1
	ct = defaultdict(int)
	for b_i in b:
		ct[b_i] += 1
	usr = defaultdict(int)
	for i in range(len(b)):
		if i + 1 < len(b) and i - 1 >= 0 and (b[i - 1] == b[i + 1]):
			usr[b[i]] += 2
		else:
			usr[b[i]] += 1
	if k == 1:
		print(0)
	else:
		print(' '.join((str(us - usr[i]) for i in range(1, k + 1))))


def funcx(n, k, l1):
	if k == 1:
		print(0)
		return
	if k == 2:
		print(0, 0)
		return
	if k == n:
		for i in range(n):
			print(k - 2, end=' ')
		print()
		return
	else:
		d1 = {}
		d2 = {}
		ld = -1
		i = 1
		t = 0
		while i < n:
			if l1[i] != l1[i - 1]:
				d1[l1[i]] = d1.get(l1[i], 0) + 1
				d1[l1[i - 1]] = d1.get(l1[i - 1], 0) + 1
				t += 1
				if l1[i] != ld and ld != -1:
					d2[l1[i - 1]] = d2.get(l1[i - 1], 0) + 1
				ld = l1[i - 1]
			i += 1
		arr = [t for i in range(k)]
		for i in d1:
			arr[i - 1] -= d1[i]
		for i in d2:
			arr[i - 1] += d2[i]
		print(*arr)
		return
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l1 = [int(i) for i in input().split()]
	funcx(n, k, l1)


from collections import Counter

def solve():
	(size, K) = map(int, input().split())
	array = list(map(int, input().split()))
	dict = {}
	k1 = Counter(array)
	for i in range(size):
		try:
			if dict[array[i]][-1][1] == i - 1:
				dict[array[i]][-1][1] = i
			else:
				dict[array[i]].append([i, i])
		except:
			dict[array[i]] = [[i, i]]
	match = [0 for i in range(K + 1)]
	total = 0
	for i in range(1, size):
		if array[i] == array[i - 1]:
			total += 1
			match[array[i - 1]] += 1
	output = []
	for i in range(1, K + 1):
		ans = total - match[i]
		if size - k1[i] == 0:
			output.append(0)
		else:
			for j in range(len(dict[i])):
				if dict[i][j][0] > 0 and dict[i][j][1] < size - 1:
					if array[dict[i][j][0] - 1] == array[dict[i][j][1] + 1]:
						ans += 1
			output.append(size - k1[i] - 1 - ans)
	return output
remained_test_cases = 1
remained_test_cases = int(input())
while remained_test_cases > 0:
	print(*solve())
	remained_test_cases -= 1


import sys
input = sys.stdin.readline
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip('\r\n')

def solve():
	(n, k) = rl()
	a = rl()
	ans = [0] * k
	t = l = r = 0
	for i in range(n):
		if a[i] == a[r]:
			r = i
			continue
		t += 1
		ans[a[i] - 1] += 1
		ans[a[r] - 1] += 1
		if l > 0 and l < n - 1 and (a[l - 1] != a[r + 1]):
			ans[a[r] - 1] -= 1
		l = r = i
	for i in range(k):
		ans[i] = t - ans[i]
	return ans
for _ in range(ri()):
	print(*solve())


t = int(input())
for i in range(t):
	d = {}
	c = {}
	fin = []
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	f = []
	s = 0
	f.append(l[0])
	for j in range(len(l)):
		if l[j] != f[-1]:
			f.append(l[j])
	for j in f:
		if j not in d.keys():
			d[j] = 1
		else:
			d[j] += 1
	for j in range(1, b + 1):
		c[j] = 0
	for j in range(2, len(f)):
		if f[j] == f[j - 2]:
			c[f[j - 1]] += 1
	for j in d.keys():
		s += d[j]
	for j in range(1, b + 1):
		pr1 = s - d[j]
		pr1 -= c[j]
		if pr1 != 0:
			fin.append(pr1 - 1)
		else:
			fin.append(pr1)
	print(*fin)


def main():
	t = int(input())
	for i in range(t):
		temp = list(map(int, input().split()))
		(n, k) = (temp[0], temp[1])
		a = list(map(int, input().split()))
		if k == 1:
			print(0)
			continue
		umax = 0
		a2 = [a[0]]
		for j in range(1, len(a)):
			if a[j] != a[j - 1]:
				a2.append(a[j])
				umax += 1
		dictt = {}
		for j in range(k):
			dictt[j + 1] = umax
		dictt[a2[0]] -= 1
		dictt[a2[-1]] -= 1
		for j in range(1, len(a2) - 1):
			if a2[j - 1] == a2[j + 1]:
				dictt[a2[j]] -= 2
			else:
				dictt[a2[j]] -= 1
		ans = []
		for j in sorted(dictt.keys()):
			ans.append(str(dictt[j]))
		print(' '.join(ans))
main()


for tc in range(int(input())):
	ls = list(map(int, input().split()))
	lk = list(map(int, input().split()))
	dis = dict()
	newlk = []
	for x in lk:
		if len(newlk) == 0:
			newlk.append(x)
		elif newlk[-1] != x:
			newlk.append(x)
	if len(newlk) == 1:
		print(0)
		continue
	ct = 0
	dis[newlk[0]] = 1
	for x in range(1, len(newlk) - 1):
		if newlk[x] != newlk[x - 1]:
			ct += 1
			if dis.get(newlk[x]) is None:
				dis[newlk[x]] = 1
			else:
				dis[newlk[x]] += 1
		if newlk[x + 1] != newlk[x]:
			if newlk[x + 1] == newlk[x - 1]:
				if dis.get(newlk[x]) is None:
					dis[newlk[x]] = 1
				else:
					dis[newlk[x]] += 1
	if newlk[-1] != newlk[-2]:
		ct += 1
		if dis.get(newlk[-1]) is None:
			dis[newlk[-1]] = 1
		else:
			dis[newlk[-1]] += 1
	res = []
	for x in range(1, ls[1] + 1):
		res.append(ct - dis[x])
	print(*res)


test = int(input())
for t in range(test):
	(n, k) = map(int, input().split())
	ls = [int(i) for i in input().split()]
	ans = [0 * i for i in range(k)]
	tc = 0
	last = ls[0]
	if k == 1:
		print(0)
		continue
	for i in range(1, n):
		c = ls[i]
		p = ls[i - 1]
		if c == p:
			continue
		else:
			tc += 1
			if last == c:
				ans[p - 1] += 2
			else:
				ans[p - 1] += 1
			last = p
	ans2 = [tc for i in range(k)]
	ans[ls[n - 1] - 1] += 1
	a = [x1 - x2 for (x1, x2) in zip(ans2, ans)]
	print(*a)


import sys

def build_arr(arr):
	new = []
	last = -1
	for x in arr:
		if x != last:
			last = x
			new.append(last)
	return new
for _ in range(int(input().strip())):
	(n, k) = [int(x) for x in sys.stdin.readline().strip().split(' ')]
	arr = [int(x) for x in sys.stdin.readline().strip().split(' ')]
	if k == 1:
		print(0)
		continue
	if k == 2:
		print('0 0')
		continue
	arr = build_arr(arr)
	curr = len(arr) - 1
	n = len(arr)
	eat = dict()
	for i in range(1, k + 1):
		eat[i] = 0
	for i in range(n):
		if i == 0 or i == n - 1:
			eat[arr[i]] += 1
		elif arr[i - 1] == arr[i + 1]:
			eat[arr[i]] += 2
		else:
			eat[arr[i]] += 1
	ans = [0] * k
	for i in range(1, k + 1):
		ans[i - 1] = curr - eat[i]
	print(*ans)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

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

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

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

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, k) = mp()
	l = li()
	d = defaultdict(int)
	pre = [0] * n
	suff = [0] * n
	first_ind = defaultdict(lambda x: -1)
	last_ind = defaultdict(lambda x: -1)
	last_ind[l[0]] = 0
	for i in range(1, n):
		pre[i] = pre[i - 1]
		last_ind[l[i]] = i
		if l[i] != l[i - 1]:
			pre[i] += 1
	first_ind[l[-1]] = n - 1
	for i in range(n - 2, -1, -1):
		first_ind[l[i]] = i
		suff[i] = suff[i + 1]
		if l[i] != l[i + 1]:
			suff[i] += 1
	i = 0
	indexes = [-1] * (k + 1)
	while i < n:
		j = i
		if indexes[l[i]] >= 0:
			d[l[i]] += pre[i - 1] - pre[indexes[l[i]] + 1]
		while j < n and l[j] == l[i]:
			j += 1
		if i - 1 >= 0 and j < n and (l[i - 1] != l[j]):
			d[l[i]] += 1
		indexes[l[i]] = j - 1
		i = j
	ANS = []
	for i in range(1, k + 1):
		if first_ind[i] == -1:
			ANS.append(pre[-1])
		else:
			ans = d[i]
			if first_ind[i] != 0:
				ans += pre[first_ind[i] - 1]
			if last_ind[i] != n - 1:
				ans += suff[last_ind[i] + 1]
			ANS.append(ans)
	print(*ANS)
for _ in range(inp()):
	solve()


def rajeev(a):
	b = [a[0]]
	for r in range(1, len(a)):
		if b[-1] == a[r]:
			continue
		else:
			b.append(a[r])
	return b
t = int(input())
for tt in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	c = rajeev(a)
	yy = len(c)
	ss = []
	for rr in range(k + 1):
		ss.append(0)
	for y in range(1, yy - 1):
		if c[y - 1] == c[y + 1]:
			ss[c[y]] += 2
		else:
			ss[c[y]] += 1
	ss[c[0]] += 1
	ss[c[-1]] += 1
	ans = []
	for g in range(1, k + 1):
		if yy - ss[g] - 1 >= 0:
			ans.append(str(yy - ss[g] - 1))
		else:
			ans.append(str(0))
	print(' '.join(ans))


import sys
from collections import deque
from collections import Counter
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
test_case = int(input())
sys.setrecursionlimit(10 ** 6)

def ans():
	(size, k) = ari()
	arr = ari()
	reducearr = []
	intial = arr[0]
	reducearr.append(intial)
	for i in range(1, size):
		if intial != arr[i]:
			reducearr.append(arr[i])
			intial = arr[i]
	maxpossible = 0
	n = len(reducearr)
	for i in range(len(reducearr) - 1):
		if reducearr[i] != reducearr[i + 1]:
			maxpossible += 1
	total = [maxpossible] * (n + 1)
	for i in range(n):
		if i + 1 < n and i - 1 >= 0:
			total[reducearr[i]] -= 2
		elif i - 1 >= 0 or i + 1 < n:
			total[reducearr[i]] -= 1
		if i - 1 >= 0 and i + 1 < n and (reducearr[i + 1] != reducearr[i - 1]):
			total[reducearr[i]] += 1
	print(*total[1:k + 1])
	return

	def doit(ele):
		newarr = []
		for i in reducearr:
			if i != ele:
				newarr.append(i)
		count = 0
		for i in range(len(newarr) - 1):
			if newarr[i] != newarr[i + 1]:
				count += 1
		return count
	result = []
	for i in range(1, n + 1):
		result.append(doit(i))
	print(*result)
	return
for _ in range(test_case):
	ans()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	d = dict()
	start = 0
	end = 0
	last = ar[0]
	for i in range(1, n):
		if ar[i] == last:
			end += 1
		elif last in d:
			d[last].append([start, end])
			start = i
			end = i
			last = ar[i]
		else:
			d[last] = [[start, end]]
			start = i
			end = i
			last = ar[i]
	if last in d:
		d[last].append([start, end])
	else:
		d[last] = [[start, end]]
	count = 0
	for i in range(1, n):
		if ar[i] != ar[i - 1]:
			count += 1
	ans = [0] * k
	for i in range(1, k + 1):
		c = count
		for val in d[i]:
			if val[0] - 1 >= 0:
				if ar[val[0]] != ar[val[0] - 1]:
					c -= 1
			if val[1] + 1 < n:
				if ar[val[1]] != ar[val[1] + 1]:
					c -= 1
			if val[0] - 1 >= 0 and val[1] + 1 < n:
				if ar[val[0] - 1] != ar[val[1] + 1]:
					c += 1
		ans[i - 1] = c
	print(*ans)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	tc = 0
	for i in range(1, n):
		if a[i] != a[i - 1]:
			tc += 1
	if n == 1:
		print(0)
	else:
		d = dict()
		kd = dict()
		nli = []
		for i in range(1, n):
			if a[i] != a[i - 1]:
				nli.append(a[i - 1])
		nli.append(a[-1])
		n = len(nli)
		for i in range(k):
			d[i + 1] = 0
		for i in range(1, n):
			if nli[i] != nli[i - 1]:
				d[nli[i]] += 1
				d[nli[i - 1]] += 1
				if i != n - 1:
					if nli[i - 1] != nli[i + 1] and nli[i] != nli[i + 1]:
						if nli[i] in kd:
							kd[nli[i]] += 1
						else:
							kd[nli[i]] = 1
		ans = []
		for i in range(k):
			if i + 1 in kd:
				ans.append(tc + kd[i + 1] - d[i + 1])
			else:
				ans.append(tc - d[i + 1])
		print(*ans)


def myfunc(n, k, arr):
	ug = 0
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			ug += 1
	m = [True] * n
	for i in range(n - 1):
		if arr[i] == arr[i + 1]:
			m[i] = False
	aux = []
	for i in range(n):
		if m[i]:
			aux.append(arr[i])
	a = [[] for _ in range(k + 1)]
	for i in range(len(aux)):
		a[aux[i]].append(i)
	ans = []
	for i in range(1, k + 1):
		t = 0
		for idx in a[i]:
			if aux[max(idx - 1, 0)] == aux[min(idx + 1, len(aux) - 1)]:
				t += 2
			else:
				t += 1
		ans.append(ug - t)
	if k == 1:
		ans = [0]
	print(*ans)
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	myfunc(n, k, arr)


from collections import defaultdict
from sys import stdin, stdout, setrecursionlimit
(readline, writeline) = (stdin.readline, stdout.write)
setrecursionlimit(100005)
for _ in range(int(readline())):
	(n, k) = map(int, readline().split())
	arr = list(map(int, readline().split()))
	lst = [arr[0]]
	for i in range(1, n):
		if arr[i] != lst[-1]:
			lst.append(arr[i])
	n = len(lst)
	ans = [n - 1] * (k + 1)
	for i in range(n):
		if i + 1 < n:
			ans[lst[i]] -= 1
		if i - 1 >= 0:
			ans[lst[i]] -= 1
		if i + 1 < n and i - 1 >= 0 and (lst[i - 1] != lst[i + 1]):
			ans[lst[i]] += 1
	print(*ans[1:])


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import defaultdict as dd
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
stdmap = lambda : map(int, stdstr().split())
stdarr = lambda : list(map(int, stdstr().split()))
mod = 1000000007
for _ in range(stdint()):
	(n, k) = stdmap()
	arr = stdarr()
	split = [arr[0]]
	total = Counter()
	for i in range(1, n):
		if arr[i] != arr[i - 1]:
			split.append(arr[i])
	total = len(split) - 1
	c = Counter()
	for i in range(1, len(split) - 1):
		if split[i - 1] == split[i + 1]:
			c[split[i]] += 2
		else:
			c[split[i]] += 1
	c[split[0]] += 1
	c[split[-1]] += 1
	res = []
	for i in range(1, k + 1):
		res.append(max(total - c[i], 0))
	print(*res)


def solve(N, K, arr):
	temp = [arr[0]]
	for i in range(1, N):
		if temp[-1] != arr[i]:
			temp.append(arr[i])
	arr = temp
	N = len(temp)
	total = 0
	for i in range(N - 1):
		if arr[i] != arr[i + 1]:
			total += 1
	ans = [total for _ in range(K + 1)]
	for i in range(N):
		if i + 1 < N:
			ans[arr[i]] -= 1
		if i - 1 >= 0:
			ans[arr[i]] -= 1
		if i - 1 >= 0 and i + 1 < N and (arr[i + 1] != arr[i - 1]):
			ans[arr[i]] += 1
	return ' '.join(map(str, ans[1:]))
t = int(input())
for _ in range(t):
	(N, K) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(N, K, arr))


T = int(input())
import collections
for _ in range(T):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	stack = []
	for i in range(n):
		if len(stack) == 0:
			stack.append(ar[i])
		elif stack[-1] == ar[i]:
			continue
		else:
			stack.append(ar[i])
	tot = len(stack) - 1
	d = collections.defaultdict(int)
	for i in range(len(stack)):
		d[stack[i]] = d[stack[i]] + 1
		if i != len(stack) - 1 and i != 0:
			if stack[i + 1] == stack[i - 1]:
				d[stack[i]] = d[stack[i]] + 1
	ans = [0 for i in range(k)]
	for i in range(1, k + 1):
		ans[i - 1] = tot - d[i]
	if len(stack) == 1:
		print(0)
		continue
	for i in range(len(ans)):
		if i != len(ans) - 1:
			print(ans[i], end=' ')
		else:
			print(ans[i])


import sys
input = sys.stdin.readline
from collections import defaultdict
num_test_cases = int(input())
for _ in range(num_test_cases):
	(length, num_unique_digits) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	reduced_arr = [arr[0]]
	for x in arr[1:]:
		if x != reduced_arr[-1]:
			reduced_arr += [x]
	base_ugliness = len(reduced_arr) - 1
	discount = defaultdict(int)
	discount[reduced_arr[0]] = 1
	for i in range(1, len(reduced_arr) - 1):
		x = reduced_arr[i]
		if reduced_arr[i - 1] == reduced_arr[i + 1]:
			discount[x] += 2
		else:
			discount[x] += 1
	if len(reduced_arr) > 1:
		discount[reduced_arr[-1]] += 1
	ans = [max(base_ugliness - discount[x], 0) for x in range(1, num_unique_digits + 1)]
	print(*ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	if n == 1:
		arr = [int(input())]
	else:
		arr = list(map(int, input().split()))
	i = 0
	curr = arr[i]
	fin = [curr]
	total_ugliness = 0
	while i < n:
		if curr != arr[i]:
			total_ugliness += 1
			curr = arr[i]
			fin.append(curr)
		i += 1
	if curr != arr[i - 1]:
		total_ugliness += 1
		curr = arr[i - 1]
		fin.append(curr)
	pos = [None] * (k + 1)
	for i in range(len(fin)):
		if not pos[fin[i]]:
			pos[fin[i]] = [i]
		else:
			pos[fin[i]].append(i)
	op = []
	for i in range(1, k + 1):
		temp = 0
		for j in pos[i]:
			if j - 1 > -1 and j + 1 < len(fin):
				if fin[j - 1] == fin[j + 1]:
					temp += 1
		op.append(max(0, total_ugliness - temp - len(pos[i])))
	print(*op)