The round carousel consists of $n$ figures of animals. Figures are numbered from $1$ to $n$ in order of the carousel moving. Thus, after the $n$-th figure the figure with the number $1$ follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger and so on). The type of animal of the $i$-th figure equals $t_i$. [Image] The example of the carousel for $n=9$ and $t=[5, 5, 1, 15, 1, 5, 5, 1, 1]$. 

You want to color each figure in one of the colors. You think that it's boring if the carousel contains two different figures (with the distinct types of animals) going one right after another and colored in the same color.

Your task is to color the figures in such a way that the number of distinct colors used is the minimum possible and there are no figures of the different types going one right after another and colored in the same color. If you use exactly $k$ distinct colors, then the colors of figures should be denoted with integers from $1$ to $k$.


-----Input-----

The input contains one or more test cases.

The first line contains one integer $q$ ($1 \le q \le 10^4$) — the number of test cases in the test. Then $q$ test cases follow. One test case is given on two lines.

The first line of the test case contains one integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of figures in the carousel. Figures are numbered from $1$ to $n$ in order of carousel moving. Assume that after the $n$-th figure the figure $1$ goes.

The second line of the test case contains $n$ integers $t_1, t_2, \dots, t_n$ ($1 \le t_i \le 2 \cdot 10^5$), where $t_i$ is the type of the animal of the $i$-th figure.

The sum of $n$ over all test cases does not exceed $2\cdot10^5$.


-----Output-----

Print $q$ answers, for each test case print two lines.

In the first line print one integer $k$ — the minimum possible number of distinct colors of figures.

In the second line print $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le k$), where $c_i$ is the color of the $i$-th figure. If there are several answers, you can print any.


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

Output
2
1 2 1 2 2
2
2 1 2 1 2 1
3
2 3 2 3 1
1
1 1 1

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Constructive algorithms

Greedy algorithms

Dynamic programming

Mathematics


Solutions:
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 300010
MOD = 10 ** 9 + 7
spf = [i for i in range(MAXN)]
spf[0] = spf[1] = -1

def sieve():
	for i in range(2, MAXN, 2):
		spf[i] = 2
	for i in range(3, int(MAXN ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def fib(n, m):
	if n == 0:
		return [0, 1]
	else:
		(a, b) = fib(n // 2)
		c = a % m * (b % m * 2 - a % m) % m
		d = a % m * (a % m) % m + b % m * b % m % m
		if n % 2 == 0:
			return [c, d]
		else:
			return [d, c + d]

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	n = int(input())
	a = arrIN()
	if len(set(a)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		x = [1, 2] * (n // 2)
		print(2)
		print(*x)
	else:
		f = 0
		for i in range(n):
			if a[i] == a[(i + 1) % n]:
				f = 1
				break
		if not f:
			print(3)
			x = [1, 2] * (n // 2) + [3]
			print(*x)
		else:
			col = [0] * n
			col[n - 1] = 1
			f = 0
			for i in range(n):
				if f or a[i] != a[i - 1]:
					col[i] = 1 if col[i - 1] == 2 else 2
				else:
					col[i] = col[i - 1]
					f = 1
			print(2)
			print(*col)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt
import math
from itertools import permutations

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		if a.count(a[0]) == n:
			print(1)
			print('1 ' * n)
		elif n % 2 == 0:
			print(2)
			print('1 2 ' * (n // 2))
		elif a[-1] == a[0]:
			print(2)
			print('1 ' + '2 1 ' * ((n - 2) // 2) + '2 1')
		elif a[0] == a[1]:
			print(2)
			print('1 1 ' + '2 1 ' * ((n - 2) // 2) + '2')
		else:
			ind = -1
			for i in range(n - 1):
				if a[i] == a[i + 1]:
					ind = i
					break
			if ind != -1:
				c = [i % 2 + 1 for i in range(ind)]
				(s1, s2) = (0, 0)
				if c[-1] == 1:
					c.append(2)
					c.append(2)
					(s1, s2) = (2, 1)
				else:
					c.append(1)
					c.append(1)
					(s1, s2) = (1, 2)
				for i in range(n - len(c)):
					if i % 2:
						c.append(s1)
					else:
						c.append(s2)
				print(2)
				print(*c)
			else:
				print(3)
				(a, b) = ([], [3, 1, 2])
				for i in range(1, n + 1):
					a.append(b[i % 3])
				if n % 3 == 1:
					(a[0], a[1]) = (2, 1)
				print(*a)
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()


for _ in range(int(input())):
	N = int(input())
	L = list(map(int, input().split()))
	r = ['2' if i % 2 else '1' for i in range(N)]
	if len(set(L)) == 1:
		ans = [1] * N
		print(1)
		print(*ans)
	else:
		if N % 2 == 0:
			ans = [1, 2] * (N // 2)
			print(2)
			print(*ans)
		if N % 2 != 0:
			if L[N - 1] == L[0]:
				ans = [1, 2] * (N // 2)
				ans.append(1)
				print(2)
				print(*ans)
			else:
				FLAG = 0
				for i in range(N):
					if L[i] == L[i - 1]:
						FLAG = 1
						break
				if FLAG:
					r[i:] = r[i - 1:-1]
					print(2)
					print(*r)
				else:
					print(3)
					r[N - 1] = 3
					print(*r)


import sys
(*data,) = sys.stdin.read().split('\n')[::-1]

def input():
	return data.pop()

def fprint(*args, **kwargs):
	print(*args, **kwargs, flush=True)

def eprint(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
for _ in range(int(input())):
	n = int(input())
	(*arr,) = map(int, input().split())
	color = 0
	mx = 1
	if len(set(arr)) == 1:
		print(1)
		print(*[1] * n)
	elif n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
	else:
		colors = [0] * n
		i = 0
		is2 = False
		color = 0
		while i < n:
			if arr[i] != arr[(i + 1) % n] or is2:
				colors[i] = color + 1
				i += 1
			else:
				colors[(i + 1) % n] = colors[i] = color + 1
				is2 = True
				i += 2
			color = (color + 1) % 2
		if not is2:
			colors[-1] = 3
		print(max(colors))
		print(*colors)


from functools import reduce
import operator
import itertools
from bisect import bisect_left
t = int(input())

def solve():
	l = int(input())
	n = list(map(int, input().split(' ')))
	if len(set(n)) == 1:
		print('1')
		print(' '.join(['1'] * l))
		return
	hs = False
	rp = 0
	for (i, v) in enumerate(n):
		if v == n[i - 1]:
			hs = True
			rp = i
			n = n[i:] + n[:i]
			break
	if hs:
		print('2')
		ans = ['1', '2'] * (l // 2) + (['1'] if l % 2 else [])
		print(' '.join(ans[-rp:] + ans[:-rp]))
	else:
		print('3' if l % 2 else '2')
		print(' '.join(['1', '2'] * (l // 2) + (['3'] if l % 2 else [])))
for i in range(t):
	solve()


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	s = set(arr)
	if len(s) == 1:
		print(1)
		print('1 ' * n)
		continue
	if n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
		continue
	flag = True
	ind = -1
	for i in range(n):
		if arr[i] == arr[(i + 1) % n]:
			flag = False
			ind = i
			break
	if flag == False:
		arr = [1 for i in range(n)]
		if ind == n - 1:
			for i in range(1, n):
				arr[i] = 3 - arr[i - 1]
		else:
			for i in range(1, ind + 1):
				arr[i] = 3 - arr[i - 1]
			arr[ind + 1] = arr[ind]
			for i in range(ind + 2, n):
				arr[i] = 3 - arr[i - 1]
		print(2)
		print(*arr)
	else:
		res = '1 2 3 '
		res = res * (n // 3)
		if n % 3 == 1:
			res += '2'
		if n % 3 == 2:
			res += '1 2'
		print(3)
		print(res)


for t in range(int(input())):
	(n, t) = (int(input()), list(map(int, input().split())))
	if len(set(t)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		for i in range(n):
			if t[i - 1] == t[i]:
				break
		else:
			print(3)
			print('1 2 ' * (n // 2) + '3')
			continue
		print(2)
		if i == 0:
			s = '1 '
		else:
			s = '1 1 '
		c = 1
		for j in range(i - 2, -1, -1):
			s = ('2 ' if c == 1 else '1 ') + s
			c = 2 if c == 1 else 1
		c = 1
		for j in range(i + 1, n):
			s += '2 ' if c == 1 else '1 '
			c = 2 if c == 1 else 1
		print(s)


for _ in range(int(input())):
	n = int(input())
	T = list(map(int, input().split()))
	nc = 1
	C = [0] * n
	p = -1
	for i in range(1, n):
		if T[i - 1] != T[i]:
			C[i] = 1 - C[i - 1]
			nc = 2
		else:
			C[i] = C[i - 1]
			p = i
	if T[0] != T[n - 1]:
		if C[0] == C[n - 1]:
			if p == -1:
				C[0] = 2
				nc = 3
			else:
				C[p] = 1 - C[p - 1]
				for i in range(p + 1, n):
					if T[i - 1] != T[i]:
						C[i] = 1 - C[i - 1]
					else:
						C[i] = C[i - 1]
	print(nc)
	print(' '.join([str(i + 1) for i in C]))


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		T = [int(x) for x in input().split()]
		changed = 0
		for (a, b) in zip(T, T[1:]):
			if a != b:
				changed += 1
		if T[0] != T[-1]:
			changed += 1
		ans = [1]
		prev = T[0]
		ans1 = set()
		ans1.add(1)
		changed2 = 0
		for (i, t) in enumerate(T[1:]):
			if i == N - 2:
				if prev == t:
					if t == T[0]:
						ans.append(ans[i])
					elif ans[i] == 1:
						ans.append(2)
						ans1.add(2)
					else:
						ans.append(ans[i])
				elif t == T[0]:
					if ans[i] == 1:
						ans.append(2)
						ans1.add(2)
					else:
						ans.append(1)
						ans1.add(1)
				elif ans[i] == 1:
					ans.append(2)
					ans1.add(2)
				else:
					ans.append(3)
					ans1.add(3)
			elif prev == t:
				if (changed - changed2) % 2 == 0:
					ans.append(1)
					ans1.add(1)
				else:
					ans.append(2)
					ans1.add(2)
				prev = t
			else:
				changed2 += 1
				if ans[i] >= 2:
					ans.append(1)
					ans1.add(1)
				else:
					ans.append(2)
					ans1.add(2)
				prev = t
		print(len(ans1))
		print(*ans)
main()


t = int(input())

def solve():
	cnt = int(input())
	animals = [int(x) for x in input().split()]
	prev = animals[0]
	currcnt = 1
	can_be_even = animals[0] == animals[-1] or cnt % 2 == 0
	for i in range(1, cnt):
		if animals[i] == prev:
			can_be_even = True
		prev = animals[i]
	if all([x == animals[0] for x in animals]):
		print(1)
		print(*['1' for i in range(cnt)])
	elif cnt % 2 == 0 or animals[0] == animals[-1]:
		print(2)
		res = []
		curr_col = 0
		prev = -1
		comp = False
		for i in range(cnt):
			res.append(curr_col + 1)
			curr_col = (curr_col + 1) % 2
		print(' '.join(map(str, res)))
	elif can_be_even:
		print(2)
		res = []
		curr_col = 0
		prev_col = 0
		prev = -1
		comp = False
		for i in range(cnt):
			if not comp and animals[i] == prev:
				res.append(res[-1])
				comp = True
			else:
				res.append(curr_col + 1)
				curr_col = (curr_col + 1) % 2
			prev = animals[i]
		print(' '.join(map(str, res)))
	else:
		print(3)
		res = [3]
		curr_col = 0
		for i in range(cnt - 1):
			res.append(curr_col + 1)
			curr_col = (curr_col + 1) % 2
		print(' '.join(map(str, res)))
for i in range(t):
	solve()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	s = [1] * n
	flag = True
	for i in range(n):
		if i > 0:
			if a[i] == a[i - 1]:
				s[i] = s[i - 1]
			else:
				s[i] = 3 - s[i - 1]
			if s[i] != 1:
				flag = False
	if s[0] != s[-1] or a[0] == a[-1]:
		if flag:
			return (1, s)
		else:
			return (2, s)
	for i in range(n):
		if i > 0 and a[i] == a[i - 1]:
			s[i - 1] = 1
			s[i] = 2
			for j in range(i - 2, -1, -1):
				if a[j] == a[j + 1]:
					s[j] = s[j + 1]
				else:
					s[j] = 3 - s[j + 1]
			for j in range(i + 1, n, 1):
				if a[j] == a[j - 1]:
					s[j] = s[j - 1]
				else:
					s[j] = 3 - s[j - 1]
			break
	if s[0] != s[-1] or a[0] == a[-1]:
		return (2, s)
	s[-1] = 3
	return (3, s)
T = int(input())
for _ in range(T):
	(k, s) = solve()
	print(k)
	print(*s)


T = int(input())
for case in range(T):
	l = int(input())
	arr = [int(x) for x in input().split(' ')]
	if len(set(arr)) == 1:
		print(1)
		print(' '.join(['1'] * len(arr)))
	elif len(arr) % 2 == 0:
		print(2)
		print(' '.join(['1', '2'] * (len(arr) // 2)))
	else:
		ret = ['1', '2'] * (len(arr) // 2)
		arr = arr + [arr[0]]
		key = False
		pos = 0
		for i in range(len(arr) - 1):
			if arr[i] == arr[i + 1]:
				key = True
				pos = i
				break
		if key == True:
			if pos != len(arr) - 2:
				ret = ret[:pos] + [ret[pos]] + ret[pos:]
			else:
				ret = ['2'] + ret
		else:
			ret.append('3')
		print(len(set(ret)))
		print(' '.join(ret))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	prev = arr[-1]
	switch = 0
	for e in arr:
		if e != prev:
			switch += 1
		prev = e
	if switch == 0:
		print(1)
		print(*[1 for _ in range(n)])
		continue
	anti = switch & 1 == 1
	res = []
	curr = 1
	prev = arr[-1]
	for e in arr:
		if anti and e == prev:
			curr = 1 - curr
			anti = False
		elif e != prev:
			curr = 1 - curr
		res.append(curr + 1)
		prev = e
	if anti:
		print(3)
		res[-1] = 3
	else:
		print(2)
	print(*res)


def main():
	import sys
	input = sys.stdin.readline
	p = int(input())
	for _ in range(p):
		n = int(input())
		t = list(map(int, input().split()))
		if len(set(t)) == 1:
			print(1)
			print(*[1] * n)
			continue
		ans = [0] * n
		flag = 0
		for i in range(n):
			if t[i - 1] == t[i]:
				j = i
				flag = 1
				break
		if flag:
			print(2)
			c = 1
			ans[j] = c
			for i in range(n - 1):
				if t[(j + i) % n] != t[(j + i + 1) % n]:
					c = -c + 3
				ans[(j + i + 1) % n] = c
		elif n % 2 == 0:
			print(2)
			for i in range(n):
				ans[i] = i % 2 + 1
		else:
			print(3)
			ans[-1] = 3
			for i in range(n - 1):
				ans[i] = i % 2 + 1
		print(*ans)
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	if arr == [arr[0] for i in range(n)]:
		print(1)
		print(*[1 for i in range(n)])
		continue
	ans = [1]
	for i in range(1, n - 1):
		if arr[i] == arr[i - 1]:
			ans.append(ans[-1])
		else:
			ans.append(3 - ans[-1])
	if arr[-1] == arr[-2] and arr[-1] == arr[0]:
		ans.append(ans[-1])
		print(2)
		print(*ans)
	elif arr[-1] == arr[-2] and arr[-1] != arr[0]:
		ans.append(3 - ans[0])
		print(2)
		print(*ans)
		k = 2
	elif arr[-1] != arr[-2] and arr[-1] == arr[0]:
		ans.append(3 - ans[-1])
		print(2)
		print(*ans)
		k = 2
	elif ans[-1] == ans[0]:
		ans.append(3 - ans[0])
		print(2)
		print(*ans)
	else:
		need = 1
		for i in range(1, n - 1):
			if ans[i] == ans[i - 1]:
				ans = [ans[j] for j in range(i)] + [3 - ans[j] for j in range(i, n - 1)]
				ans.append(3 - ans[0])
				k = 2
				need = 0
				break
		if need == 0:
			print(2)
			print(*ans)
		else:
			print(3)
			print(*ans + [3])


def all_eq(x):
	for i in range(len(x) - 1):
		if x[i] != x[i + 1]:
			return False
	return True

def check(x):
	for i in range(len(x) - 1):
		if x[i] == x[i + 1]:
			return (True, i)
	if x[0] == x[-1]:
		return (True, -1)
	return (False, -1)
x = int(input())
y = []
m = []
for i in range(x):
	y.append([])
	a = int(input())
	s = str(input()).split(' ')
	if all_eq(s):
		y[i] = ['1'] * a
		m.append(1)
		continue
	elif a % 2 == 0:
		y[i] = ['1', '2'] * int(a / 2)
		m.append(2)
		continue
	z = check(s)
	if z[0]:
		m.append(2)
		if z[1] == -1:
			y[i] = ['1', '2'] * int((a - 1) / 2) + ['1']
		elif z[1] % 2 == 0:
			y[i] = ['1', '2'] * int(z[1] / 2) + ['1'] + ['1', '2'] * int((a - z[1] - 1) / 2)
		else:
			y[i] = ['1', '2'] * int((z[1] + 1) / 2) + ['2'] + ['1', '2'] * int((a - z[1] - 2) / 2)
	else:
		m.append(3)
		y[i] = ['1', '2'] * int((a - 1) / 2) + ['3']
for i in range(x):
	print(m[i])
	print(' '.join(y[i]))


def sos(n, x):
	y = x[:]
	y.append(x[0])
	for i in range(n):
		if y[i] == y[i + 1]:
			return i
	return -1
for t in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	if x.count(x[0]) == n:
		k = 1
		s = '1' * n
	elif n % 2 == 0:
		k = 2
		s = '12' * (n // 2)
	else:
		c = sos(n, x)
		if c == -1:
			k = 3
			s = '12' * (n // 2) + '3'
		else:
			k = 2
			if c % 2 == 0:
				s = '12' * (c // 2) + '1' + '12' * ((n - c - 1) // 2)
			else:
				s = '12' * ((c + 1) // 2) + '2' + '12' * ((n - c - 2) // 2)
	print(k)
	z = list(s)
	print(' '.join(z))


from functools import reduce
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(N, r) = (2, ['2' if i % 2 else '1' for i in range(n)])
	if len(set(l)) == 1:
		N = 1
		r = ['1'] * n
	elif n % 2 == 0 or l[0] == l[-1]:
		N = 2
	else:
		t = 0
		for i in range(1, n):
			if l[i] == l[i - 1]:
				t = 1
				break
		if t == 0:
			N = 3
			r[-1] = '3'
		else:
			N = 2
			r[i:] = r[i - 1:-1]
			r[-1] = '2'
	print(N)
	print(*r)


import itertools
for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		print(1)
		print(' '.join(['1'] * n))
	elif n % 2 == 0:
		print(2)
		print(' '.join(['1', '2'] * (n // 2)))
	elif not any((t[i] == t[i + 1] for i in range(n - 1))) and t[0] != t[-1]:
		print(3)
		print(' '.join(['1', '2'] * (n // 2) + ['3']))
	else:
		print(2)
		res = ['1', '2'] * (n // 2)
		for i in range(n - 1):
			if t[i] == t[i + 1]:
				res.insert(i, res[i])
				break
		else:
			res += ['1']
		print(' '.join(res))


q = int(input())
for i in range(q):
	n = int(input())
	arr = input().split()
	T1 = 1
	T2 = True
	ans1 = [1]
	ans2 = [1]
	for j in range(1, n):
		if arr[j] != arr[j - 1]:
			T1 *= -1
		if T1 == 1:
			ans1.append(1)
		else:
			ans1.append(2)
	T1 = 1
	for j in range(1, n):
		if arr[j - 1] == arr[j] and T2:
			T1 *= -1
			T2 = False
		if arr[j] != arr[j - 1]:
			T1 *= -1
		if T1 == 1:
			ans2.append(1)
		else:
			ans2.append(2)
	if max(arr) == min(arr):
		print(1)
		print(' '.join(map(str, [1] * n)))
	if arr[0] == arr[-1] and max(arr) != min(arr):
		print(2)
		print(' '.join(map(str, ans1)))
	if arr[0] != arr[-1] and ans1[-1] != ans1[0]:
		print(2)
		print(' '.join(map(str, ans1)))
	elif arr[0] != arr[-1] and ans2[-1] != ans2[0]:
		print(2)
		print(' '.join(map(str, ans2)))
	if arr[0] != arr[-1] and ans2[-1] == ans2[0] and (ans1[-1] == ans1[0]):
		print(3)
		print(' '.join(map(str, ans1[:-1] + [3])))


z = int(input())
for i in range(z):
	n = int(input())
	m = list(map(int, input().split()))
	k = 0
	item = 1
	answermas = [1]
	ind = -1
	for i in range(1, n):
		if m[i] != m[i - 1]:
			k += 1
			if item == 1:
				item = 2
			else:
				item = 1
		elif ind == -1:
			ind = i
		answermas.append(item)
	if k == 0:
		answer = 1
	elif k % 2 == 0 and m[0] != m[-1] and (k == n - 1):
		answer = 3
		answermas[-1] = 3
	else:
		answer = 2
		if k % 2 == 0 and m[0] != m[-1]:
			r = 0
			for i in range(ind, n):
				if answermas[i] == 1:
					answermas[i] = 2
				else:
					answermas[i] = 1
	print(answer)
	print(*answermas)


for _ in range(int(input())):
	n = int(input())
	L = input().split()
	r = ['2' if i % 2 else '1' for i in range(n)]
	if len(set(L)) == 1:
		print(1)
		print(*['1'] * n)
	elif n % 2 == 0:
		print(2)
		print(*r)
	elif L[0] == L[-1]:
		print(2)
		print(*r)
	else:
		c = 2
		T = 0
		for i in range(1, n):
			if L[i] == L[i - 1]:
				T = 1
				break
		if T:
			print(2)
			r[i:] = r[i - 1:-1]
			r[-1] = '2'
			print(*r)
		else:
			print(3)
			r[-1] = '3'
			print(*r)


t = int(input())
for test_case in range(t):
	n = int(input())
	ts = list(map(int, input().split(' ')))
	if ts.count(ts[0]) == n:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		changes = 0
		for i in range(n - 1):
			if ts[i] != ts[i + 1]:
				changes += 1
		if ts[0] != ts[n - 1]:
			changes += 1
		changed = False
		if changes % 2 == 0:
			changed = True
		output2 = [0 for i in range(n)]
		output2[0] = 1
		num = 1
		for i in range(n - 2):
			if ts[i] == ts[i + 1]:
				if not changed:
					num = 3 - num
					changed = True
			else:
				num = 3 - num
			output2[i + 1] = num
		if ts[n - 2] == ts[n - 1]:
			if not changed:
				num = 3 - num
				changed = True
			print(2)
		elif not changed:
			num = 3
			print(3)
		else:
			print(2)
			num = 3 - num
		output2[n - 1] = num
		for i in output2:
			print(i, end=' ')
		print()


import sys, math, cmath
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	n = inp()
	a = inlt()
	q = 1
	w = [1]
	for i in range(1, len(a) - 1):
		if a[i] == a[i - 1]:
			w.append(q)
		else:
			w.append(2 if q == 1 else 1)
			q = 2 if q == 1 else 1
	if a[0] == a[-1] == a[-2]:
		w.append(q)
	elif a[0] != a[-1] and a[-1] != a[-2]:
		if q == 2:
			w.append(3)
		else:
			w.append(2)
	elif a[0] != a[-1]:
		w.append(2)
	elif q == 2:
		w.append(1)
	else:
		w.append(2)
	ww = list(w)
	if max(w) == 3 and len(w) % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	elif max(w) == 3 and len(w) % 2 != 0:
		ww = [1]
		c = 0
		q = 1
		for i in range(1, len(a)):
			if a[i] == a[i - 1] and c == 0:
				ww.append(q)
				c = 1
			else:
				ww.append(2 if q == 1 else 1)
				q = 2 if q == 1 else 1
		if a[-1] != a[0] and ww[-1] == ww[0]:
			print(max(w))
			print(*w)
		else:
			print(max(ww))
			print(*ww)
	else:
		print(max(w))
		print(*w)


t = int(input())
for case_num in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	color = [1] * n
	if len(set(a)) == 1:
		print(1)
		print(' '.join(map(str, color)))
	else:
		one = [False] * n
		two = [False] * n
		one[0] = True
		for i in range(n - 1):
			if a[i] == a[i + 1]:
				color[i + 1] = color[i]
			else:
				color[i + 1] = 3 - color[i]
		if a[0] == a[n - 1] or color[0] != color[n - 1]:
			print(2)
			print(' '.join(map(str, color)))
		else:
			backup = color.copy()
			color[n - 1] = 2
			i = n - 2
			while i >= 0 and a[i] != a[i + 1] and (color[i] == color[i + 1]):
				color[i] = 3 - color[i + 1]
				i -= 1
			if color[0] == 1:
				print(2)
				print(' '.join(map(str, color)))
			else:
				backup[n - 1] = 3
				print(3)
				print(' '.join(map(str, backup)))


import sys
import random
t = int(input())
g = sys.stdin.readlines()
y = 0
for _ in range(t):
	n = int(g[y])
	y += 1
	a = list(map(int, g[y].split()))
	y += 1
	q = 1
	color = [0] * n
	save = -1
	for i in range(n):
		if a[i - 1] != a[i]:
			q = 2
			color[i] = (color[i - 1] + 1) % q
		else:
			color[i] = color[i - 1]
			save = i
	if a[0] != a[-1] and color[0] == color[-1]:
		if save == -1:
			q = 3
			color[-1] = 2
		else:
			color[save:] = [(i + 1) % 2 for i in color[save:]]
	print(q)
	color = [i + 1 for i in color]
	print(*color)


import sys
import os
from io import BytesIO, IOBase
from collections import Counter, deque
import math

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def ddd():
	return collections.defaultdict(collections.defaultdict(int))
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')
for _ in range(ii()):
	n = ii()
	a = li()
	t = 0
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			t += 1
	if a[-1] != a[0]:
		t += 1
	if t == 0:
		print(1)
		res = [1 for i in range(n)]
		print(*res)
		continue
	if t & 1 == 0:
		print(2)
		res = [0 for i in range(n)]
		f = 1
		res[0] = 1
		for i in range(1, n):
			if a[i] != a[i - 1]:
				f = 3 - f
			res[i] = f
		print(*res)
	elif n > t:
		print(2)
		f1 = 0
		f = 1
		res = [0 for i in range(n)]
		res[0] = 1
		for i in range(1, n):
			if a[i] == a[i - 1]:
				if f1 == 0:
					f1 = 1
					f = 3 - f
			else:
				f = 3 - f
			res[i] = f
		print(*res)
	else:
		print(3)
		res = [0 for i in range(n)]
		f = 1
		res[0] = 1
		for i in range(1, n):
			if a[i] != a[i - 1]:
				f = 3 - f
			res[i] = f
		res[-1] = 3
		print(*res)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = []
	if len(set(a)) == 1:
		c = [1] * n
	else:
		c = [1 if i % 2 == 0 else 2 for i in range(n)]
		if c[0] == c[-1] and a[0] != a[-1]:
			for i in range(1, n):
				if a[i] == a[i - 1]:
					c[i] = c[i - 1]
					for j in range(i + 1, n):
						c[j] = 3 - c[j - 1]
					break
			else:
				c[-1] = 3
	print(len(set(c)))
	print(*c)


for i in range(int(input())):
	n = int(input())
	l = [int(j) for j in input().split()]
	c = 0
	for j in range(n):
		if l[j] != l[(j + 1) % n]:
			c += 1
	if c == 0:
		print(1)
		print(' '.join(['1' for j in range(n)]))
	elif n % 2 == 0:
		print(2)
		print(''.join(['1 2 ' for j in range(n // 2)]))
	else:
		for j in range(n):
			if l[j] == l[(j + 1) % n]:
				print(2)
				print(*([1, 2] * n)[:j + 1][::-1] + ([1, 2] * n)[:n - j - 1])
				break
		else:
			print(3)
			print(''.join(['1 2 ' for j in range(n // 2)]) + '3')


def toggle(n):
	if n == 1:
		return 2
	else:
		return 1
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if len(set(lis)) == 1:
		print(1)
		for i in range(len(lis)):
			print(1, end=' ')
		print()
	elif len(lis) % 2 == 0:
		print(2)
		for i in range(len(lis) // 2):
			print(1, 2, end=' ')
		print()
	else:
		gotcha = -1
		for i in range(len(lis) - 1):
			if lis[0] == lis[-1]:
				gotcha = len(lis) - 1
				break
			elif lis[i] == lis[i + 1] and gotcha == -1:
				gotcha = i
				break
		if gotcha == -1:
			print(3)
			for i in range((len(lis) - 1) // 2):
				print(1, 2, end=' ')
			print(3, end=' ')
			print()
		elif gotcha == len(lis) - 1:
			print(2)
			for i in range(len(lis) // 2):
				print(1, 2, end=' ')
			print(1, end=' ')
			print()
		else:
			print(2)
			start = 1
			for i in range(len(lis)):
				print(start, end=' ')
				if i == gotcha:
					start = toggle(start)
				start = toggle(start)
			print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	same = True
	for i in range(n):
		same &= arr[i] == arr[0]
	if same:
		print(1)
		for i in range(n):
			print(1, end=' ')
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			print(1 if i % 2 == 0 else 2, end=' ')
	else:
		for i in range(n):
			if arr[i] == arr[(i + 1) % n]:
				ans = [0 for j in range(n)]
				val = 1
				for j in range(i + 1, n):
					ans[j] = val
					val ^= 3
				val = 1
				for j in range(i, -1, -1):
					ans[j] = val
					val ^= 3
				print(2)
				for i in range(n):
					print(ans[i], end=' ')
				break
		else:
			print(3)
			for i in range(n - 1):
				print(1 if i % 2 == 0 else 2, end=' ')
			print(3, end=' ')
	print()


import os
import 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')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	car = list(map(int, input().split()))
	diffvals = set(car)
	if len(diffvals) == 1:
		print(1)
		print(' '.join(['1' for k in range(n)]))
	else:
		noreps = [car[0]]
		replist = [1]
		for s in range(1, n):
			if car[s] == car[s - 1]:
				replist[-1] += 1
			else:
				replist.append(1)
				noreps.append(car[s])
		greatestsofar = 0
		exists = 0
		for b in range(len(replist)):
			if replist[b] >= 2:
				greatestsofar = b
				exists = 1
		ind1 = 0
		ind2 = 0
		ind1 = sum(replist[0:greatestsofar])
		ind2 = ind1 + replist[greatestsofar] - 1
		if len(noreps) == n:
			if n % 2 == 0:
				print(2)
				print(' '.join([str(m % 2 + 1) for m in range(n)]))
			elif n % 2 == 1:
				if car[0] == car[-1]:
					print(2)
					print(' '.join([str(m % 2 + 1) for m in range(n)]))
				else:
					outputlist = [m % 3 + 1 for m in range(n)]
					diffs = set([1, 2, 3])
					diffs.discard(outputlist[0])
					diffs.discard(outputlist[-2])
					outputlist[-1] = list(diffs)[0]
					print(3)
					print(' '.join(map(str, outputlist)))
		else:
			print(2)
			if (n + exists - replist[greatestsofar]) % 2 == 0 or car[0] == car[-1]:
				output = []
				for b in range(n):
					if b <= ind1:
						output.append(str(b % 2 + 1))
					elif b > ind1 and b <= ind2:
						output.append(output[-1])
					elif b > ind2:
						output.append(str(int(output[-1]) % 2 + 1))
				print(' '.join(output))
			elif (n + exists - replist[greatestsofar]) % 2 == 1 and car[0] != car[-1]:
				output1 = []
				for b in range(n):
					if b <= ind1:
						output1.append(str(b % 2 + 1))
					elif b > ind1 and b <= ind2:
						if b == ind1 + 1:
							output1.append(str(int(output1[-1]) % 2 + 1))
						else:
							output1.append(output1[-1])
					elif b > ind2:
						output1.append(str(int(output1[-1]) % 2 + 1))
				print(' '.join(output1))


q = int(input())
for test_case in range(q):
	n = int(input())
	arr = list(map(int, input().split()))
	paint_list = [0 for i in range(n)]
	paint_list[0] = 1
	colors = 1
	if arr[n - 1] == arr[0] or arr[n - 2] == arr[n - 1]:
		for t in range(1, n):
			if paint_list[t - 1] == 1 and arr[t] != arr[t - 1]:
				colors = 2
				paint_list[t] = 2
			else:
				paint_list[t] = 1
		if arr[n - 1] != arr[0]:
			colors = 2
			paint_list[n - 1] = 2
	elif n % 2 == 0:
		colors = 2
		paint_list = [1, 2] * (n // 2)
	else:
		found_consecutive_matching = False
		for t in range(1, n - 1):
			if not found_consecutive_matching and arr[t] == arr[t - 1]:
				found_consecutive_matching = True
				paint_list[t] = paint_list[t - 1]
			else:
				paint_list[t] = 3 - paint_list[t - 1]
		if paint_list[n - 2] == paint_list[0]:
			paint_list[n - 1] = 2
			colors = 2
		else:
			paint_list[n - 1] = 3
			colors = 3
	print(colors)
	print(' '.join((str(x) for x in paint_list)))


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	Query.append((N, A))
for (N, A) in Query:
	if len(set(A)) == 1:
		la = 1
		ans = ['1'] * N
	elif N % 2 == 0:
		la = 2
		ans = [str(i % 2 + 1) for i in range(N)]
	else:
		ind = -1
		for i in range(N):
			if A[i - 1] == A[i]:
				ind = i
		if ind == -1:
			la = 3
			ans = [str(i % 2 + 1) for i in range(N)]
			ans[-1] = '3'
		else:
			la = 2
			ans = [str(i % 2 + 1) if i < ind else str((i + 1) % 2 + 1) for i in range(N)]
	print(la)
	print(' '.join(ans))


t = int(input())
for i in range(t):
	n = int(input())
	sp = list(map(int, input().split()))
	f = len(set(sp))
	if f == 1:
		print(1)
		print('1 ' * n)
		continue
	flag = False
	for j in range(1, n):
		if sp[j] == sp[j - 1]:
			flag = True
			break
	if sp[-1] == sp[0]:
		flag = True
		j = 0
	if flag:
		print(2)
		if n % 2 == 0:
			for x in range(n):
				print(1 + x % 2, end=' ')
		else:
			for x in range(n):
				if x >= j:
					print(1 + (x - 1) % 2, end=' ')
				else:
					print(1 + x % 2, end=' ')
		print()
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		print(3)
		print('1 2 ' * (n // 2) + '3')


import sys
input = sys.stdin.readline

def nextColor(prevColor):
	if prevColor == 1:
		return 2
	else:
		return 1
for f in range(int(input())):
	n = int(input())
	t = list(map(int, input().split(' ')))
	coloring = [1]
	ans = 1
	for go in range(1, n):
		if go != n - 1:
			if t[go] != t[go - 1]:
				coloring.append(nextColor(coloring[go - 1]))
				ans = 2
			else:
				coloring.append(coloring[go - 1])
		elif t[go - 1] != t[go] and t[go] != t[0]:
			if coloring[go - 1] == coloring[0]:
				coloring.append(nextColor(coloring[go - 1]))
				ans = 2
			else:
				coloring.append(3)
				ans = 3
		elif t[go] != t[go - 1]:
			if coloring[go - 1] == coloring[0]:
				coloring.append(nextColor(coloring[go - 1]))
				ans = 2
			else:
				coloring.append(coloring[0])
		elif t[go] != t[0]:
			if coloring[go - 1] == coloring[0]:
				coloring.append(nextColor(coloring[0]))
				ans = 2
			else:
				coloring.append(coloring[go - 1])
		else:
			coloring.append(coloring[go - 1])
	if ans == 3:
		flipped = False
		for j in range(1, n - 1):
			if coloring[j] == coloring[j - 1] and flipped == False:
				coloring[j] = nextColor(coloring[j])
				flipped = True
			elif flipped == True:
				coloring[j] = nextColor(coloring[j])
		if flipped == True:
			coloring[n - 1] = nextColor(coloring[n - 2])
			ans = 2
	print(ans)
	coloring = list(map(str, coloring))
	print(' '.join(coloring))


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		carr = [1 for i in range(n)]
	else:
		carr = [i % 2 + 1 for i in range(n)]
		if carr[-1] == carr[0] and arr[-1] != arr[0]:
			carr[-1] = 3
			for i in reversed(range(1, n)):
				if arr[i] == arr[i - 1]:
					carr[i] = carr[i - 1]
					for j in range(i + 1, n):
						carr[j] = carr[j - 1] % 2 + 1
					break
	print(len(set(carr)))
	print(*carr)


for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ans = ['2' if i % 2 else '1' for i in range(n)]
	aa = 2
	if len(set(lis)) == 1:
		print(1)
		print('1 ' * n)
	else:
		if n % 2 == 0 or lis[0] == lis[-1]:
			aa = 2
		else:
			c = 0
			for i in range(1, n):
				if lis[i] == lis[i - 1]:
					c = 1
					break
			if c == 1:
				ans[i:] = ans[i - 1:-1]
				ans[-1] = 2
			else:
				aa = 3
				ans[-1] = 3
		print(aa)
		print(*ans)


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left, bisect_right
import threading
from collections import Counter
arr = []

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		ans = [1] * n
		cnt = 1
		c = Counter(arr)
		if len(list(c.items())) != 1:
			cnt = 2
			for i in range(n):
				ans[i] = i % 2 + 1
			if n % 2 != 0:
				ind = 1
				while ind < n + 10 and arr[ind % n] != arr[(ind - 1) % n]:
					ind += 1
				if arr[ind % n] != arr[(ind - 1) % n]:
					cnt = 3
					ans[-1] = 3
				else:
					ans[ind % n] = ans[(ind - 1) % n] = 1
					p = 2
					for i in range(1, n - 1):
						ans[(ind + i) % n] = p
						p = 3 - p
		print(cnt)
		print(*ans)
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()


T = int(input())
while T > 0:
	n = int(input())
	t = map(int, input().split())
	t = list(t)
	cn = 2
	c = []
	flag = 0
	f = 1
	for x in range(n):
		c.append(f)
		if f == 1:
			f = 2
		else:
			f = 1
	for x in range(0, n - 1):
		if t[x] != t[x + 1]:
			flag = 1
			break
	if flag == 0:
		print(1)
		for x in range(n):
			print(1, end=' ')
	elif n % 2 == 0:
		print(cn)
		for x in c:
			print(x, end=' ')
		print()
	elif t[n - 1] == t[0]:
		print(cn)
		for x in c:
			print(x, end=' ')
		print()
	else:
		for x in range(0, n - 1):
			if t[x] == t[x + 1]:
				for y in range(x + 1, n):
					if c[y] == 1:
						c[y] = 2
					else:
						c[y] = 1
				break
		else:
			cn = 3
			c[n - 1] = 3
		print(cn)
		for x in c:
			print(x, end=' ')
		print()
	T -= 1


q = int(input())
for i in range(q):
	n = int(input())
	T = input().split()
	same = 1
	twin = 0
	k = -1
	if T[0] == T[n - 1]:
		twin = 1
		k = n - 1
	for j in range(n - 1):
		if T[j] != T[j + 1]:
			same = 0
		if T[j] == T[j + 1]:
			twin = 1
			k = j
	if same == 1:
		print('1')
		print(('1 ' * n).rstrip())
	elif n % 2 == 0:
		print('2')
		print(('1 2 ' * (n // 2)).rstrip())
	elif twin == 1:
		print('2')
		if k % 2 != 0:
			print(('1 2 ' * ((k + 1) // 2) + '2 ' + '1 2 ' * ((n - k - 2) // 2)).rstrip())
		else:
			print(('1 2 ' * (k // 2) + '1 ' + '1 2 ' * ((n - k - 1) // 2)).rstrip())
	else:
		print('3')
		print('1 2 ' * (n // 2) + '3')


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	same = 0
	different = 0
	for j in range(0, n - 1):
		if s[j] == s[j + 1]:
			same = 1
		else:
			different = 1
	if s[0] == s[n - 1]:
		same = 1
	else:
		different = 1
	if same == 1:
		if different == 0:
			numcolours = 1
		else:
			numcolours = 2
			if n % 2 == 1:
				version = 1
			else:
				version = 2
	elif n % 2 == 1:
		numcolours = 3
	else:
		numcolours = 2
		version = 2
	print(numcolours)
	if numcolours == 1:
		for j in range(0, n):
			print(1)
	if numcolours == 2:
		if version == 1:
			temp = 1
			flag = 0
			for j in range(0, n):
				print(temp)
				if flag == 0 and s[j] == s[(j + 1) % n]:
					flag = 1
					continue
				temp = 3 - temp
		if version == 2:
			for j in range(n // 2):
				print(1)
				print(2)
	if numcolours == 3:
		for j in range(n // 2):
			print(1)
			print(2)
		print(3)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
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))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def sqr(n):
	return sqrt(n) ** 2 == float(n)

def chk_nb(i, j):
	tem = [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]
	c = 0
	for i in tem:
		if i in ans:
			c += 1
	if c % 2:
		return True

def solve():
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		if len(set(arr)) == 1:
			print(1)
			print(*[1] * n)
			continue
		elif n % 2 == 0:
			print(2)
			print(*[1, 2] * (n // 2))
			continue
		ans = [0] * n
		ans[0] = 1
		dic = [0, 2, 1]
		flag = 1
		for i in range(1, n):
			if arr[i] == arr[i - 1] and flag:
				flag = 0
				ans[i] = ans[i - 1]
			else:
				ans[i] = dic[ans[i - 1]]
		col = 2
		if flag and arr[0] != arr[-1]:
			ans[-1] = 3
			col = 3
		print(col)
		print(*ans)
solve()


q = int(input())
for loop in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	dic = {}
	for i in t:
		dic[i] = 1
	if len(dic) == 1:
		k = 1
		res = [1] * n
	elif n % 2 == 0:
		k = 2
		res = []
		for i in range(n):
			if i % 2 == 0:
				res.append(1)
			else:
				res.append(2)
	else:
		flag = 0
		res = []
		for i in range(n):
			if flag == 0 and t[i - 1] == t[i]:
				flag = 1
			res.append((i + flag) % 2)
		if flag == 0:
			res[-1] = 2
			k = 3
		else:
			k = 2
		for i in range(n):
			res[i] += 1
	print(k)
	print(*res)


for _ in range(int(input())):
	x = int(input())
	mylist = list(map(int, input().split()))
	amr = set(mylist)
	size = len(amr)
	out = []
	if size == 1:
		out = [1] * x
	else:
		out = [i % 2 + 1 for i in range(x)]
		if mylist[-1] != mylist[0] and x % 2 != 0:
			for i in range(1, x):
				if mylist[i] == mylist[i - 1]:
					out.insert(i, out[i - 1])
					out.pop(-1)
					break
			else:
				out[-1] = 3
	print(len(set(out)))
	print(*out)


T = int(input())
for _ in range(1, T + 1):
	a = int(input())
	n = [int(x) for x in input().split()]
	if len(set(n)) == 1:
		print(1)
		print(*[1] * a)
		continue
	if a % 2 == 0:
		print(2)
		print(*[1, 2] * (a // 2))
		continue
	else:
		for i in range(a):
			prev = i - 1 if i > 0 else a - 1
			if n[prev] == n[i]:
				print(2)
				print(*([1, 2] * a)[:i] + ([2, 1] * a)[i:a])
				break
		else:
			print(3)
			print(*[1, 2] * (a // 2) + [3])
			continue


from sys import stdin, stdout

def main():
	Q = int(stdin.readline())
	for _ in range(Q):
		N = int(stdin.readline())
		A = list(map(int, stdin.readline().replace('\n', '').split()))
		if len(set(A)) == 1:
			stdout.write('1\n')
			ans = '1 ' * N
			stdout.write(ans[:len(ans) - 1] + '\n')
		elif N == 2:
			stdout.write('2\n1 2\n')
		else:
			ans = []
			val = '2'
			if (N - 2) % 2 != 0:
				if A[N - 2] != A[N - 1] and A[N - 1] != A[0]:
					countSame = 0
					i = 0
					while i <= N - 3:
						if countSame == 0 and A[i] == A[i + 1]:
							countSame = 1
							if i % 2 == 0:
								ans.append(1)
								ans.append(1)
							else:
								ans.append(2)
								ans.append(2)
							i += 1
						elif countSame == 0:
							if i % 2 == 0:
								ans.append(1)
							else:
								ans.append(2)
						elif i % 2 == 0:
							ans.append(2)
						else:
							ans.append(1)
						i += 1
					if countSame == 0:
						ans.append(2)
						ans.append(3)
						val = '3'
					elif i == N - 1:
						ans.append(2)
					else:
						ans.append(1)
						ans.append(2)
				elif A[N - 2] == A[N - 1] and A[N - 1] != A[0]:
					i = 0
					while i <= N - 2:
						if i % 2 == 0:
							ans.append(1)
						else:
							ans.append(2)
						i += 1
					ans.append(2)
				elif A[N - 2] != A[N - 1] and A[N - 1] == A[0] or (A[N - 2] == A[N - 1] and A[N - 1] == A[0]):
					i = 0
					while i <= N - 2:
						if i % 2 == 0:
							ans.append(1)
						else:
							ans.append(2)
						i += 1
					ans.append(1)
			else:
				i = 0
				while i <= N - 2:
					if i % 2 == 0:
						ans.append(1)
					else:
						ans.append(2)
					i += 1
				ans.append(2)
			stdout.write(val + '\n')
			print(*ans)
main()


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	cnt = 0
	for j in a:
		if j == a[0]:
			cnt += 1
	if cnt == n:
		print(1)
		print(*[1] * n)
	else:
		j = 0
		if a[0] != a[-1]:
			while j < n and a[j] != a[j - 1]:
				j += 1
		else:
			j = 0
		if j >= n:
			if n % 2 == 0:
				for j in range(n):
					if j % 2 == 0:
						b[j] = 1
					else:
						b[j] = 2
				print(2)
				print(*b)
			else:
				for j in range(n):
					if j % 2 == 0:
						b[j] = 1
					else:
						b[j] = 2
				b[-1] = 3
				print(3)
				print(*b)
		else:
			cur = 1
			for jj in range(j, j + n):
				el = jj % n
				b[el] = cur
				if cur == 1:
					cur = 2
				else:
					cur = 1
			print(2)
			print(*b)


for t in range(int(input())):
	n = int(input())
	v = list(map(int, input().split()))
	(a, b, c, d) = ([1] * n, [1] * n, [1] * n, [1] * n)

	def r(i):
		return (i + 1) % n
	i = 0
	while i < n and v[i] != v[r(i)]:
		i += 1
	if i < n:
		b[i] = b[r(i)] = 2
		(j, z) = (r(r(i)), 1)
		while j != i:
			b[j] = z
			j = r(j)
			z = 3 - z
	for i in range(0, n, 2):
		c[i] = d[i] = 2
	d[-1] = 3

	def work(u):
		ok = 1
		for i in range(n - 1):
			ok &= v[i] == v[i + 1] or u[i] != u[i + 1]
		ok &= v[-1] == v[0] or u[-1] != u[0]
		ok |= len(u) == 1
		return ok
	if work(a):
		print('1\n', *a)
	elif work(b):
		print('2\n', *b)
	elif work(c):
		print('2\n', *c)
	else:
		print('3\n', *d)


q = int(input())
for _ in range(q):
	n = int(input())
	t = [int(x) for x in input().split()]
	if min(t) == max(t):
		print('1', '1 ' * n, sep='\n')
		continue
	if n % 2 == 0:
		print('2', '1 2 ' * (n // 2), sep='\n')
		continue
	has_rep = False
	current_color = 0
	s = ''
	for i in range(n - 1):
		s += str(current_color + 1) + ' '
		if t[i] == t[i + 1] and (not has_rep):
			has_rep = True
		else:
			current_color = int(not current_color)
	if has_rep:
		s += str(current_color + 1) + ' '
		ans = 2
	elif t[-1] == t[0]:
		s += '1'
		ans = 2
	else:
		s += '3'
		ans = 3
	print(ans, s, sep='\n')


for _ in range(int(input())):
	n = int(input())
	ts = list(map(int, input().split()))
	if n % 2 == 0:
		if len(set(ts)) == 1:
			print(1)
			print(' '.join(map(str, [1] * n)))
		else:
			print(2)
			print(' '.join(map(str, [1, 2] * (n // 2))))
	else:
		c = 1
		col = [c]
		first = ts[0]
		prev = first
		for t in ts[1:]:
			if t != prev:
				c = 2 if c == 1 else 1
			col.append(c)
			prev = t
		if t != first and col[0] == c:
			r = True
		else:
			r = False
		c = 1
		col = [c]
		first = ts[0]
		prev = first
		for t in ts[1:]:
			if t != prev:
				c = 2 if c == 1 else 1
			elif r:
				r = False
				c = 2 if c == 1 else 1
			col.append(c)
			prev = t
		if t != first and col[0] == c:
			c = 3
			col[0] = c
		print(max(col))
		print(' '.join(map(str, col)))


for case in range(int(input())):
	n = int(input())
	values = [int(x) for x in input().split()]
	same_count = 0
	same_count_index = -1
	for i in range(n):
		if values[i] == values[(i + 1) % n]:
			same_count += 1
			same_count_index = i + 1
	if same_count == n:
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()
	elif same_count == 0:
		if n % 2 == 0:
			print(2)
			for i in range(n // 2):
				print('1 2 ', end='')
			print()
		else:
			print(3)
			for i in range(n // 2):
				print('1 2 ', end='')
			print('3')
	else:
		answer = [1]
		for i in range(1, n):
			if values[i] == values[i - 1]:
				answer.append(answer[-1])
			elif answer[-1] == 1:
				answer.append(2)
			else:
				answer.append(1)
		if values[0] != values[n - 1] and answer[0] == answer[n - 1]:
			answer = [1]
			for i in range(1, n):
				if values[i] == values[i - 1] and i != same_count_index:
					answer.append(answer[-1])
				elif answer[-1] == 1:
					answer.append(2)
				else:
					answer.append(1)
		print(2)
		for x in answer:
			print(x, end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	t = [int(i) for i in input().split()]
	a = [1]
	for i in range(1, n):
		if t[i] == t[i - 1]:
			a.append(a[i - 1])
		elif a[-1] == 2:
			a.append(1)
		else:
			a.append(2)
	if a[n - 1] == a[0] and t[n - 1] != t[0]:
		flag = 0
		ind = -1
		for i in range(1, n):
			if a[i - 1] == a[i]:
				flag = 1
				ind = i
		if flag == 1:
			for i in range(ind, n):
				a[i] = 3 - a[i]
			print(max(a))
			print(*a)
		else:
			a[n - 1] = 3
			print(3)
			print(*a)
	else:
		print(max(a))
		print(*a)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = len(set(a))
	i = 0
	k = 0
	if l == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0 or a[0] == a[-1]:
		print(2)
		print('1 2 ' * (n // 2) + '1' * (n % 2))
	else:
		while i < n - 1:
			if a[i] == a[i + 1]:
				k = i + 1
				break
			i += 1
		if k:
			print(2)
			x = [1, 2] * (n // 2) + [1]
			if k % 2 == 0:
				print(*x[:k] + x[k + 1:] + [2])
			else:
				print(*x[:k] + x[k:][::-1])
		else:
			print(3)
			print('1 2 ' * (n // 2) + '3')


t = int(input())
for j in range(t):
	n = int(input())
	a = tuple(map(int, input().split()))
	b = [1] * n
	switch = True
	if a.count(a[0]) < n:
		for i in range(1, n):
			if n % 2 == 0:
				if b[i - 1] == 1:
					b[i] = 2
			elif a[i - 1] == a[i] and switch == True:
				b[i] = b[i - 1]
				switch = False
			elif b[i - 1] == 1:
				b[i] = 2
		if n % 2 == 1 and switch == True and (a[-1] != a[0]):
			b[-1] = 3
	print(max(b))
	print(*b)


t = int(input())

def x(L, n):
	count = 1
	for i in range(1, n):
		if L[i] != L[i - 1]:
			count += 1
	return count
for _ in range(t):
	n = int(input())
	L = list(map(int, input().split()))
	l = len(set(L))
	if l == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		count = 2
		s = '1 2 ' * int(n // 2)
		print(count)
		print(s)
	elif L[-1] == L[0]:
		count = 2
		s = '1 2 ' * int(n // 2)
		s += '1'
		print(count)
		print(s)
	elif x(L, n) == n:
		count = 3
		s = '1 2 ' * int(n // 2)
		s += '3'
		print(count)
		print(s)
	else:
		s = '1 '
		p = 1
		count = 1
		co = 0
		for i in range(1, n):
			if L[i] == L[i - 1] and co == 0:
				s += str(p)
				s += ' '
				co += 1
			else:
				p = p % 2
				p += 1
				s += str(p)
				s += ' '
		print(2)
		print(s)


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	elif t[-1] != t[0]:
		ans = [0] * n
		for j in range(n):
			if t[j] == t[(j + 1) % n]:
				ans[j] = ans[(j + 1) % n] = 1
				for k in range(2, n):
					ans[(j + k) % n] = 2 if k % 2 == 0 else 1
				print(2)
				print(' '.join(map(str, ans)))
				break
		else:
			print(3)
			print('1 2 ' * (n // 2) + '3')
	else:
		print(2)
		print('1 2 ' * (n // 2) + '1')


import sys
import heapq

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

def iinput():
	return int(input())

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

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

def main():

	def pro(v, p):
		q[v] = p
		for u in g[v]:
			if u == p:
				continue
			pro(u, v)

	def dfs(v, p):
		for i in w[v]:
			e[i] += 1
			if e[i] == t[i]:
				res[i] = True
		for u in g[v]:
			if u == p:
				continue
			dfs(u, v)
		for i in w[v]:
			e[i] -= 1
	n = iinput()
	q = rlinput()
	fl = False
	for i in range(n):
		if q[i] == q[i - 1]:
			fl = True
			break
	if len(set(q)) == 1:
		print(1)
		print(*[1] * n)
	elif q[0] != q[n - 1] and q[n - 2] != q[n - 1] and n % 2:
		if fl:
			print(2)
			fl = True
			w = []
			res = [1]
			for i in range(n):
				if q[i] == q[i - 1] and fl:
					fl = False
					if i:
						res.append(res[-1])
					else:
						w.append(1)
				elif i:
					res.append(res[-1] % 2 + 1)
			if w:
				print(*res[:-1] + w)
			else:
				print(*res)
		else:
			print(3)
			res = [1]
			for i in range(n - 2):
				res.append(res[-1] % 2 + 1)
			res.append(3)
			print(*res)
	else:
		print(2)
		if n % 2:
			res = [1]
			for i in range(1, n - 1):
				res.append(res[-1] % 2 + 1)
			if q[n - 1] != q[0]:
				res.append(2)
			else:
				res.append(res[-1] % 2 + 1)
			print(*res)
		else:
			print(*[i % 2 + 1 for i in range(n)])
for i in range(iinput()):
	main()


import sys, os, io
from sys import stdin
import math
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
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')
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

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
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

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

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve():
	n = ii()
	a = li()
	if len(set(a)) == 1:
		print(1)
		print(*[1] * n)
		return
	if n % 2 == 0 or a[0] == a[-1]:
		print(2)
		ans = []
		for i in range(n):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(2)
		print(*ans)
		return
	ans = []
	for i in range(n):
		if i % 2 == 0:
			ans.append(1)
		else:
			ans.append(2)
	temp = 0
	for i in range(1, n):
		if a[i] == a[i - 1] and temp == 0:
			ans[i] = ans[i - 1]
			temp = 1
		elif temp == 1:
			if ans[i] == 1:
				ans[i] = 2
			else:
				ans[i] = 1
	if temp == 1:
		print(2)
	else:
		print(3)
	if temp == 0:
		ans[-1] = 3
	print(*ans)
t = 1
t = ii()
for _ in range(t):
	solve()


def one():
	global a
	for i in range(1, len(a)):
		if a[0] != a[i]:
			return 1
	return 0

def two():
	global a
	if a[0] == a[-1]:
		return len(a) - 1
	for i in range(len(a) - 1):
		if a[i] == a[i + 1]:
			return i
	return -1

def xxx():
	global a
	n = len(a)
	if one() == 0:
		print('1')
		print('1 ' * n)
	elif n % 2 == 0:
		print('2')
		print('1 2 ' * (n // 2))
	else:
		x = two()
		if x == -1:
			print('3')
			print('3 ' + '1 2 ' * (n // 2))
		else:
			print('2')
			if x == len(a) - 1:
				print('1 2 ' * (n // 2) + '1')
			else:
				r = 1
				for i in range(len(a)):
					print(r, end=' ')
					if i != x:
						r = 3 - r
				print()
for i in range(int(input())):
	xz = input()
	a = list(map(int, input().split()))
	xxx()


def solve(n, a):
	if len(set(a)) == 1:
		return [1] * n
	arr = [1 if x % 2 == 0 else 2 for x in range(n)]
	if n % 2 != 0 and a[0] != a[-1]:
		for j in range(1, n):
			if a[j] == a[j - 1]:
				arr[j] = arr[j - 1]
				for k in range(j + 1, n):
					arr[k] = 3 - arr[k - 1]
				break
		else:
			arr[-1] = 3
	return arr
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = solve(n, a)
	print(max(ans))
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	x = len(set(l))
	if x == 1:
		print(1)
		for i in range(n):
			print(1, end=' ')
	elif n % 2 == 0:
		print(2)
		for i in range(n // 2):
			print(1, 2, end=' ')
	else:
		c = -1
		for i in range(n - 1):
			if l[i] == l[i + 1]:
				c = i
				break
		if c == -1 and l[0] != l[n - 1]:
			print(3)
			for i in range((n - 1) // 2):
				print(1, 2, end=' ')
			print(3, end=' ')
		elif l[0] != l[n - 1]:
			print(2)
			for i in range(n - 1):
				if i % 2 == 0:
					print(1, end=' ')
					if i == c:
						print(1, end=' ')
				else:
					print(2, end=' ')
					if i == c:
						print(2, end=' ')
		else:
			print(2)
			for i in range((n - 1) // 2):
				print(1, 2, end=' ')
			print(1, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	List = list(map(int, input().split()))
	w = [1]
	flag = 0
	cnt = -1
	for i in range(1, n):
		if List[i] != List[i - 1]:
			if w[-1] == 1:
				w.append(2)
			else:
				w.append(1)
		else:
			cnt = i
			w.append(w[-1])
		if i == n - 1:
			if w[-1] == w[0]:
				if List[-1] != List[0]:
					if cnt == -1:
						w[-1] = 3
						flag = 1
					else:
						for i in range(cnt, n):
							if w[i] == 1:
								w[i] = 2
							else:
								w[i] = 1
	if 2 in w and flag:
		print(3)
	elif 2 in w:
		print(2)
	else:
		print(1)
	for j in w:
		print(j, end=' ')
	print(' ')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n,) = I()
	a = I()
	ans = [0] * n
	color = 0
	if len(set(a)) == 1:
		print(1)
		print('1 ' * n)
		continue
	shift = 1
	for i in range(n):
		ans[i] = color
		color ^= 1
		if i and a[i] == a[i - 1] and n % 2 and shift:
			shift = 0
			color ^= 1
			ans[i] = ans[i - 1]
	if a[-1] == a[-2] != a[0]:
		for i in range(3):
			if ans[0] != i:
				ans[-1] = i
				break
	elif a[0] == a[-1] != a[-2]:
		for i in range(3):
			if ans[-2] != i:
				ans[-1] = i
				break
	elif a[0] != a[-1] != a[-2]:
		for i in range(3):
			if ans[-2] != i and ans[0] != i:
				ans[-1] = i
				break
	elif a[0] == a[-1] == a[-2]:
		ans[-1] = ans[-2]
	print(max(ans) + 1)
	print(*[i + 1 for i in ans])


q = int(input())
for queries in range(q):
	n = int(input())
	xs = list(map(int, input().split()))
	if len(set(xs)) == 1:
		print('1')
		print('1 ' * (n - 1) + '1')
	else:
		if n % 2 == 1:
			found = False
			colours = [1, 2] * (n // 2)
			for i in range(n):
				if xs[i] == xs[i - 1]:
					print('2')
					colours.insert(i, colours[i - 1])
					print(*colours)
					found = True
					break
			if not found:
				print('3')
				print('2 3 ' * (n // 2) + '1')
		if n % 2 == 0:
			print('2')
			print('1 2 ' * (n // 2))


from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

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

def LS():
	return [list(x) for x in sys.stdin.readline().split()]

def S():
	res = list(sys.stdin.readline())
	if res[-1] == '\n':
		return res[:-1]
	return res

def IR(n):
	return [I() for i in range(n)]

def LIR(n):
	return [LI() for i in range(n)]

def SR(n):
	return [S() for i in range(n)]

def LSR(n):
	return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
	t = I()
	for _ in range(t):
		n = I()
		a = LI()
		if len(set(a)) == 1:
			print(1)
			print(*[1] * n)
			continue
		f = [1 if not i & 1 else 2 for i in range(n)]
		if not n & 1:
			print(max(f))
			print(*f)
			continue
		if a[0] != a[-1]:
			a += a
			for i in range(n):
				if a[i] == a[i + 1]:
					f = [f[j] if j <= i else 3 - f[j] for j in range(n)]
					break
			else:
				f[-1] = 3
		print(max(f))
		print(*f)
	return
solve()


q = int(input())
for test in range(0, q):
	n = int(input())
	t = input().split()
	if t[0] == t[n - 1]:
		c = 0
		for i in range(0, n - 1):
			if t[i] != t[i + 1]:
				c = 1
				break
		if c == 1:
			print(2)
			for i in range(0, n):
				print(i % 2 + 1, end=' ')
		else:
			print(1)
			for i in range(0, n):
				print(1, end=' ')
		print()
	else:
		if n % 2 == 0:
			print(2)
			for i in range(0, n):
				print(i % 2 + 1, end=' ')
		else:
			c = -1
			for i in range(0, n - 1):
				if t[i] == t[i + 1]:
					c = i + 1
					break
			if c != -1:
				print(2)
				for i in range(0, c):
					print(i % 2 + 1, end=' ')
				for i in range(c, n):
					print((i + 1) % 2 + 1, end=' ')
			else:
				print(3)
				for i in range(0, n - 1):
					print(i % 2 + 1, end=' ')
				print(3, end='')
		print()


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	b = 0
	for i in range(n - 1):
		if t[i] == t[i + 1]:
			b = i + 1
			break
	t = t[b:] + t[:b]
	c = [0]
	for i in range(1, n - 1):
		if t[i] == t[i - 1]:
			c += [c[-1]]
		else:
			c += [1 - c[-1]]
	if t[0] == t[-2]:
		if t[0] == t[-1]:
			c += [c[0]]
		elif c[0] != c[-1]:
			c += [2]
		else:
			c += [1 - c[-1]]
	elif c[0] == c[-1]:
		c += [1 - c[-1]]
	elif t[0] == t[-1]:
		c += [c[0]]
	elif t[-1] == t[-2]:
		c += [c[-1]]
	else:
		c += [2]
	c = c[-b:] + c[:-b]
	print(len(set(c)))
	print(*(i + 1 for i in c))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().strip().split()]
	res = [0 for i in range(n)]
	count = 1
	cc = 1
	res[0] = 1
	flag = False
	for i in range(1, n):
		prev = a[i - 1]
		curr = a[i]
		if curr == prev:
			flag = True
			ind = i
			res[i] = res[i - 1]
		else:
			if count == 1:
				count += 1
			if cc == 1:
				res[i] = 2
				cc = 2
			else:
				res[i] = 1
				cc = 1
	if res[0] != res[-1] or a[0] == a[-1]:
		print(count)
		print(*res)
	elif flag:
		for i in range(ind, n):
			if res[i] == 1:
				res[i] = 2
			else:
				res[i] = 1
		print(count)
		print(*res)
	else:
		print(3)
		res[-1] = 3
		print(*res)


def solve():
	n = int(input())
	types = list(map(int, input().split()))
	one_type = True
	consecutive_type = None
	for i in range(1, n):
		if types[i] == types[i - 1]:
			consecutive_type = i
		else:
			one_type = False
	if one_type:
		print(1)
		print(*[1] * n)
	else:
		c = [i % 2 + 1 for i in range(n)]
		maxc = 2
		if n % 2 == 1:
			if types[-1] == types[-2]:
				c[-1] = c[-2]
			elif types[-1] == types[0]:
				c[-1] = c[0]
			elif consecutive_type is not None:
				for i in range(consecutive_type, n):
					c[i] = c[i] % 2 + 1
			else:
				c[-1] = 3
				maxc = 3
		print(maxc)
		print(*c)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


N = int(input())
for _ in range(N):
	n = int(input())
	data = input()
	split = data.split(' ')
	numbers = []
	for x in split:
		numbers.append(int(x))
	different = False
	for i in range(n):
		if numbers[i] != numbers[0]:
			different = True
	s = [1] * n
	if not different:
		print(1)
		for x in s:
			print(x, end=' ')
		print('')
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				s[i] = 2
		for x in s:
			print(x, end=' ')
		print('')
	elif numbers[0] == numbers[n - 1]:
		print(2)
		for i in range(n):
			s[i] = 1 + i % 2
		for x in s:
			print(x, end=' ')
		print('')
	else:
		poz = -1
		for i in range(n - 1):
			if numbers[i] == numbers[i + 1]:
				poz = i
				break
		if poz == -1:
			print(3)
			if n % 3 != 1:
				for i in range(n):
					s[i] = 1 + i % 3
				for x in s:
					print(x, end=' ')
				print('')
			else:
				for i in range(n - 1):
					s[i] = 1 + i % 2
				s[n - 1] = 3
				for x in s:
					print(x, end=' ')
				print('')
		else:
			print(2)
			for i in range(poz + 1):
				s[i] = 1 + i % 2
			for i in range(poz + 1, n):
				s[i] = 2 - i % 2
			for x in s:
				print(x, end=' ')
			print('')


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

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

def num():
	return int(input())
from itertools import repeat, groupby
q = num()
for _ in repeat(None, q):
	n = num()
	ts = list(line())
	l = len(list(groupby(ts)))
	alert = l % 2 and ts[0] != ts[-1]
	w = ts[0]
	c = 1
	ans = [1]
	cls = 1
	for t in ts[1:]:
		if alert or t != w:
			cls = 2
			if t == w:
				alert = 0
			c = 3 - c
		ans.append(c)
		w = t
	if alert:
		cls = 3
		ans[0] = 3
	print(cls)
	print(' '.join(map(str, ans)))


q = int(input())
while q:
	n = int(input())
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		print(1)
		print(*[1 for i in range(n)])
	elif n % 2 == 0 or t[0] == t[n - 1]:
		print(2)
		ls = [0 for i in range(n)]
		for i in range(n):
			if i % 2 == 0:
				ls[i] = 1
			else:
				ls[i] = 2
		print(*ls)
	else:
		ls = [0 for i in range(n)]
		ls[0] = 1
		for i in range(1, n):
			if t[i] == t[i - 1]:
				ls[i] = ls[i - 1]
			elif ls[i - 1] == 1:
				ls[i] = 2
			else:
				ls[i] = 1
		if ls[0] == ls[n - 1]:
			ls = [0 for i in range(n)]
			ls[0] = 1
			flag = True
			for i in range(1, n):
				if t[i] == t[i - 1]:
					if flag:
						if ls[i - 1] == 1:
							ls[i] = 2
						else:
							ls[i] = 1
						flag = False
					else:
						ls[i] = ls[i - 1]
				elif ls[i - 1] == 1:
					ls[i] = 2
				else:
					ls[i] = 1
			if flag:
				ls[n - 1] = 3
				print(3)
				print(*ls)
			else:
				print(2)
				print(*ls)
		else:
			print(2)
			print(*ls)
	q -= 1


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if len(set(l)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		flag = 1
		count = 0
		temp = [1]
		for i in range(1, n):
			if flag:
				if l[i] == l[i - 1]:
					temp.append(count % 2 + 1)
					flag = 0
				else:
					count += 1
					temp.append(count % 2 + 1)
			else:
				count += 1
				temp.append(count % 2 + 1)
		if flag and l[0] != l[-1]:
			temp[-1] = 3
			print(3)
		else:
			print(2)
		print(*temp, sep=' ')


from sys import stdin
input = stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	A = [int(j) for j in input().split()]
	power = False
	j = 0
	ans = []
	color = 1
	b = 0
	while j < n:
		a = A[j]
		b += 1
		k = j + 1
		ans.append(color)
		while k < n and A[k] == A[j]:
			if not power:
				power = True
			k += 1
			ans.append(color)
		color = color % 2 + 1
		j = k
	if ans[-1] == ans[0] and A[0] != A[-1] and (b > 1):
		if not power:
			ans[-1] = 3
		else:
			j = 0
			while j < n:
				a = ans[j]
				k = j + 1
				if ans[k] == ans[j]:
					while k < n and ans[k] == ans[j]:
						k += 1
					else:
						start = k - 1
						for p in range(k - 1, n):
							ans[p] = ans[p] % 2 + 1
						break
				j = k
	print(max(ans))
	for j in ans:
		print(j, end=' ')
	print()


import os
import 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')
n = int(input())
for i in range(n):
	n1 = int(input())
	l = list(map(int, input().split()))
	t = 0
	for j in range(1, n1):
		if l[j] != l[j - 1]:
			t = 1
			break
	if t == 0:
		print(1)
		for j in range(n1):
			print(1, end=' ')
		continue
	if n1 % 2 == 0 or l[-1] == l[0]:
		print(2)
		for j in range(n1):
			if j % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		continue
	a = [0] * n1
	a[-1] = 2
	a[0] = 1
	f = 2
	ind = -1
	for j in range(1, n1 - 1):
		if l[j] == l[j - 1]:
			ind = j
			a[j] = a[j - 1]
		else:
			a[j] = 3 - a[j - 1]
	if l[-2] != l[-1] and a[-2] == a[-1]:
		if ind == -1:
			a[-1] = 3
			f = 3
		else:
			a[ind] = 3 - a[ind - 1]
			for j in range(ind + 1, n1 - 1):
				if l[j] == l[j - 1]:
					a[j] = a[j - 1]
				else:
					a[j] = 3 - a[j - 1]
	print(f)
	print(*a, sep=' ')


for _ in range(int(input())):
	n = int(input())
	types = list(map(int, input().split()))
	if len(set(types)) == 1:
		print(1)
		for e in range(n):
			print(1, end=' ')
	elif not n & 1:
		print(2)
		for i in range(n):
			print(i % 2 + 1, end=' ')
	else:
		done = 0
		for i in range(n):
			if types[i] == types[(i + 1) % n]:
				(ans, pos, j) = ([0] * n, i + 1, 0)
				while pos < n:
					ans[pos] = j + 1
					j ^= 1
					pos += 1
				(j, pos) = (0, i)
				while pos >= 0:
					ans[pos] = j + 1
					pos -= 1
					j ^= 1
				print(2)
				for i in ans:
					print(i, end=' ')
				done = 1
				break
		if not done:
			print(3)
			for i in range(n - 1):
				print(i % 2 + 1, end=' ')
			print(3, end='')
	print()


a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	z.append(z[-1])
	save = 0
	col = 1
	flag = 0
	ans = [1]
	for i in range(1, len(z)):
		if z[i] == z[i - 1]:
			ans.append(ans[-1])
		elif ans[-1] == 1:
			ans.append(2)
			col = 2
		else:
			ans.append(1)
	for i in range(1, len(ans)):
		if ans[i] == ans[i - 1]:
			save = i
			flag = 1
			break
	if ans[-1] != 1 or (ans[-1] == 1 and z[0] == z[-1]):
		ans = ans[0:len(ans) - 1]
		print(col)
		print(' '.join(map(str, ans)))
	elif flag == 0 or (flag == 1 and save == len(ans) - 1):
		ans[-2] = 3
		col = 3
		ans = ans[0:len(ans) - 1]
		print(col)
		print(' '.join(map(str, ans)))
	else:
		if ans[save] == 1:
			ans[save] = 2
		else:
			ans[save] = 1
		for i in range(save + 1, len(ans)):
			if z[i] == z[i - 1]:
				ans[i] = ans[i - 1]
			elif ans[i - 1] == 1:
				ans[i] = 2
			else:
				ans[i - 1] == 2
				ans[i] = 1
		ans = ans[0:len(ans) - 1]
		print(col)
		print(' '.join(map(str, ans)))


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	a = [int(y) for y in a]
	col = [1]
	c = 1
	z = -1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			c = c % 2 + 1
			col += [c]
		else:
			col += [c]
			z = i
	if a[n - 1] != a[0] and col[n - 1] == 1:
		if z != -1:
			for i in range(z, n):
				if col[i] == 1:
					col[i] = 2
				else:
					col[i] = 1
		else:
			col[n - 1] = 3
	print(max(col))
	col = [str(y) for y in col]
	print(' '.join(col))


tnum = int(input())
for test in range(tnum):
	n = int(input())
	t = [int(i) for i in input().split()]
	if all((x == t[0] for x in t)):
		print(1)
		print(' '.join(['1' for i in range(n)]))
	elif all((t[i] != t[(i + 1) % n] for i in range(n))) and n % 2 == 1:
		ans = [1, 2] * (n // 2)
		ans.append(3)
		print(3)
		print(' '.join([str(j) for j in ans]))
	elif n % 2 == 0:
		ans = [1, 2] * (n // 2)
		print(2)
		print(' '.join([str(j) for j in ans]))
	else:
		ans = [1, 2] * (n // 2)
		ans.append(1)
		i = 0
		while t[i] != t[(i - 1) % n]:
			i = i + 1
		ansr = [ans[(k - i) % n] for k in range(n)]
		print(2)
		print(' '.join([str(j) for j in ansr]))


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	k = 0
	c = [0] * n
	repeat_index = -1
	for i in range(-1, n - 1):
		if t[i] == t[i + 1]:
			repeat_index = i + 1
			break
	if repeat_index > -1:
		k = 1
		color = 1
		c[repeat_index] = color
		for i in range(repeat_index - n, repeat_index - 1):
			if t[i] == t[i + 1]:
				color = 1
			else:
				k = 2
				color = 3 - color
			c[i + 1] = color
	else:
		k = 2
		for i in range(0, n, 2):
			c[i] = 1
		for i in range(1, n, 2):
			c[i] = 2
		if n % 2:
			k = 3
			c[-1] = 3
	print(k)
	print(' '.join((str(i) for i in c)))


for _ in range(int(input())):
	n = int(input())
	li = [int(i) for i in input().split()]
	same = True
	x = li[0]
	for i in range(1, n):
		if x != li[i]:
			same = False
			break
	if same:
		print(1)
		for i in range(n):
			print('1', end=' ')
		print('')
	elif n % 2 == 0:
		print(2)
		for i in range(n // 2):
			print('1 2', end=' ')
		print('')
	else:
		p = -1
		for i in range(n - 1):
			if li[i] == li[i + 1]:
				p = i
				break
		if p == -1:
			if li[0] == li[n - 1]:
				print(2)
				for i in range(n):
					if i % 2 == 0:
						print('1', end=' ')
					else:
						print('2', end=' ')
				print('')
			else:
				print(3)
				for i in range(n // 2):
					print('1 2', end=' ')
				print(3)
		else:
			print(2)
			for i in range(p + 1):
				if i % 2 == 0:
					print('1', end=' ')
				else:
					print('2', end=' ')
			for i in range(p + 1, n):
				if i % 2 == 0:
					print('2', end=' ')
				else:
					print('1', end=' ')
			print('')


def changed(colors, types, n):
	index = -1
	for i in range(n - 1, 0, -1):
		if types[i] == types[i - 1]:
			index = i - 1
			break
	if index == -1:
		colors[n - 1] = 3
		return True
	for i in range(index + 1, n):
		if colors[i - 1] == 1:
			colors[i] = 2
		else:
			colors[i] = 1
	return False

def solve(types, n, ans):
	colors = []
	colors.append(1)
	k = 1
	for i in range(1, n):
		if types[i] != types[i - 1]:
			k += 1
			if colors[-1] == 1:
				colors.append(2)
			else:
				colors.append(1)
		else:
			colors.append(colors[-1])
	k = min(k, 2)
	if colors[n - 1] == colors[0] and types[n - 1] != types[0]:
		if changed(colors, types, n):
			k += 1
	ans.append([k])
	ans.append(colors)

def main():
	ans = []
	q = int(input())
	for i in range(q):
		n = int(input())
		types = list(map(int, input().split()))
		solve(types, n, ans)
	for i in ans:
		for j in i:
			print(j, end=' ')
		print()
main()


import sys
input = sys.stdin.readline
n = int(input())

def mTypes(types):
	t = types[0]
	for x in types:
		if t != x:
			return False
	return True

def pair(types):
	return len(types) % 2 == 0

def mTypesAcc(types):
	t = types[-1]
	i = 0
	for x in types:
		if x == t:
			return (True, i)
		else:
			t = x
		i += 1
	return (False, -1)

def main():
	taille = int(input())
	types = list(map(int, input().split()))
	if mTypes(types):
		return ([1 for i in range(taille)], 1)
	if pair(types):
		return ([((-1) ** i + 1) // 2 + 1 for i in range(taille)], 2)
	(b, i) = mTypesAcc(types)
	if b:
		c = []
		if i == 0:
			return ([((-1) ** i + 1) // 2 + 1 for i in range(taille)], 2)
		else:
			c.append(1)
			for j in range(1, taille):
				if i == j:
					c.append(c[-1])
				elif c[-1] == 1:
					c.append(2)
				else:
					c.append(1)
			return (c, 2)
	else:
		c = [((-1) ** i + 1) // 2 + 1 for i in range(taille)]
		c[0] = 3
		return (c, 3)
for i in range(n):
	(c, t) = main()
	print(t)
	print(*c)


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	arr = [int(i) for i in input().split()]
	ff = [0] * n
	ff[0] = 1
	kk = -1
	qq = 1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			ff[i] = ff[i - 1]
			kk = i
		else:
			qq = 2
			ff[i] = 3 - ff[i - 1]
	if ff[n - 1] == ff[0] and kk != -1 and (arr[n - 1] != arr[0]):
		for i in range(kk, n):
			ff[i] = 3 - ff[i]
	elif ff[n - 1] == ff[0] and kk == -1 and (arr[n - 1] != arr[0]):
		qq = 3
		ff[n - 1] = 3
	print(qq)
	print(*ff)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	li = list(map(int, input().split()))
	dic = {}
	m = 0
	ok = -1
	for i in range(n):
		if li[i] == li[i - 1] and ok == -1:
			ok = i
		if li[i] in dic.keys():
			continue
		m = m + 1
		dic[li[i]] = m
	if m <= 2:
		print(m)
		for i in range(n):
			print(dic[li[i]], end=' ')
	elif n % 2 == 0:
		print(2)
		for i in range(0, n, 2):
			print(1, 2, end=' ')
	elif ok > -1:
		print(2)
		cnt = 1
		for i in range(n):
			if i != ok:
				cnt = cnt + 1
			print(cnt % 2 + 1, end=' ')
	else:
		print(3)
		for i in range(n - 1):
			print(i % 2 + 1, end=' ')
		print(3, end=' ')
	print('')


import sys

def __whatColor__(tripletAnimals, tripletColors):
	(a1, a2, a3) = tuple(tripletAnimals)
	(c1, c2, c3) = tuple(tripletColors)
	if a1 == a2 and a2 == a3:
		return c1
	if a1 == a2:
		if c3 == 1:
			return 2
		else:
			return 1
	if a2 == a3:
		if c1 == 1:
			return 2
		else:
			return 1
	if c1 == c3:
		if c1 == 1:
			return 2
		else:
			return 1
	return 3

def findColors():
	figures = int(sys.stdin.readline())
	animals = sys.stdin.readline().strip().split()
	maxColors = 1
	colored = [0] * figures
	pos = 0
	max_color = 1
	while pos < figures:
		if animals[pos] == animals[pos - 1]:
			colored[pos] = 1
		elif colored[pos - 1] == 1:
			colored[pos] = 2
			max_color = 2
		else:
			colored[pos] = 1
		if True:
			False
		pos += 1
	if figures > 2:
		color = __whatColor__([animals[-2], animals[-1], animals[0]], [colored[-2], colored[-1], colored[0]])
		if color == 3:
			pos = figures - 1
			while pos > 0 and animals[pos] != animals[pos - 1]:
				pos -= 1
			if pos > 0:
				while pos < figures:
					if colored[pos] == 1:
						colored[pos] = 2
					else:
						colored[pos] = 1
					pos += 1
				color = __whatColor__([animals[-2], animals[-1], animals[0]], [colored[-2], colored[-1], colored[0]])
		colored[-1] = color
		max_color = max(colored)
	print(max_color)
	print(' '.join(map(str, colored)))
queries = int(sys.stdin.readline())
for query in range(queries):
	findColors()


def dif(n, a):
	if a.count(a[0]) == n:
		print('1')
		print('1 ' * n)
	elif n % 2 == 0:
		print('2')
		print('1 2 ' * int(n / 2))
	elif a[0] == a[-1]:
		i = 0
		f1 = 1
		print('2')
		while i < n:
			if f1 == 1:
				print('1 ', end='')
			else:
				print('2 ', end='')
			f1 *= -1
			i += 1
		print('')
	else:
		f = 0
		j = 0
		for i in range(n - 1, 0, -1):
			if a[i] == a[i - 1]:
				f = 1
				j = i
				break
		if f == 0:
			f1 = 1
			print('3')
			i = 0
			while i < n - 1:
				if f1 == 1:
					print('1 ', end='')
				else:
					print('2 ', end='')
				f1 *= -1
				i += 1
			print('3')
		else:
			f1 = 1
			print('2')
			i = 0
			while i < n:
				if i == j:
					f1 *= -1
				if f1 == 1:
					print('1 ', end='')
				else:
					print('2 ', end='')
				f1 *= -1
				i += 1
			print('')
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dif(n, a)


from sys import stdin
input = lambda : stdin.readline()
from math import ceil
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	z = []
	for i in range(n):
		if i % 2:
			z.append(1)
		else:
			z.append(2)
	if len(set(l)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0 or l[0] == l[-1]:
		print(2)
		print(*z)
	else:
		flag = 0
		for i in range(1, n):
			if l[i] == l[i - 1]:
				k = i
				flag = 1
		if flag:
			print(2)
			print(*z[:k], z[k - 1], *z[k:-1])
		else:
			print(3)
			print(*z[:-1], 3)


def fill(start, color, color_2):
	global res
	global tek
	global te
	res[start] = color
	for i in range(start, n - 1):
		if a[i] == a[i + 1]:
			res[i + 1] = res[i]
			tek = True
			te = i + 1
		elif res[i] == color:
			res[i + 1] = color_2
		else:
			res[i + 1] = color
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = [1] * n
	result = 1
	tek = False
	te = -1
	for i in range(1, n):
		if a[i] != a[i - 1]:
			result = 2
			break
	if result == 1:
		print(result)
		print('1 ' * n)
	else:
		fill(0, 1, 2)
		if a[-1] != a[0] and res[-1] == res[0]:
			if not tek:
				res[-1] = 3
				print(3)
				print(*res)
			else:
				if res[te] == 1:
					fill(te, 2, 1)
				else:
					fill(te, 1, 2)
				print(2)
				print(*res)
		else:
			print(2)
			print(*res)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	flag = 0
	p1 = -1
	p2 = -1
	if arr[0] == arr[n - 1]:
		p1 = n - 1
		p2 = 0
	for i in range(n):
		if arr[i] != arr[0]:
			flag = 1
			break
	for i in range(n):
		if i > 0:
			if arr[i - 1] == arr[i]:
				p1 = i - 1
				p2 = i
				break
	if flag == 1:
		if n % 2 == 0:
			ans = '1 2'
			ans += ' 1 2' * (n // 2 - 1)
			print(2)
			print(ans)
		elif p1 == n - 1 and p2 == 0:
			ans = '1 2 ' * (n // 2) + '1'
			print(2)
			print(ans)
		elif p1 != -1:
			if p1 % 2 == 1:
				ans = '2'
				ans += ' 1 2' * (p1 // 2)
				ans += ' 1 1'
				ans += ' 2 1' * ((n - p2 - 1) // 2)
				print(2)
				print(ans)
			else:
				ans = '1 2 ' * (p1 // 2)
				ans += '1 1'
				ans += ' 2 1' * ((n - p2 - 1) // 2)
				ans += ' 2'
				print(2)
				print(ans)
		else:
			ans = '1 2 ' * (n // 2)
			ans += '3'
			print(3)
			print(ans)
	else:
		ans = '1'
		ans += ' 1' * (n - 1)
		print(1)
		print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input().split()
	all_same = True
	has_dubs = False
	r = []
	prev = None
	cur_color = 1
	for c in a:
		if not prev:
			r.append(str(cur_color))
		elif c == prev:
			has_dubs = True
			r.append(str(cur_color))
		elif c != prev:
			all_same = False
			cur_color = cur_color % 2 + 1
			r.append(str(cur_color))
		prev = c
	k = 2
	if all_same:
		k = 1
	elif r[0] == r[-1] and a[0] != a[-1]:
		if not has_dubs:
			r[-1] = '3'
			k = 3
		else:
			r = []
			prev = None
			first_dup = True
			for c in a:
				if not prev:
					prev = c
					r.append(str(cur_color))
				elif c == prev:
					if first_dup:
						cur_color = cur_color % 2 + 1
					first_dup = False
					r.append(str(cur_color))
				elif c != prev:
					all_same = False
					cur_color = cur_color % 2 + 1
					r.append(str(cur_color))
				prev = c
	print(k)
	print(' '.join(r))


from collections import *
for i in range(int(input())):
	(n, a, cur, mem) = (int(input()), list(map(int, input().split())), 1, defaultdict(int))
	(ans, dis) = ([], set(a.copy()))
	if len(dis) == 1:
		ans = [1] * n
	elif n % 2 == 0 or a[0] == a[-1]:
		for j in range(n):
			ans.append(cur)
			cur = 1 if cur == 2 else 2
	else:
		flag = 1
		for j in range(n):
			if j > 0 and a[j] == a[j - 1] and flag:
				flag = 0
			else:
				cur = 1 if cur == 2 else 2
			ans.append(cur)
		if flag:
			ans[-1] = 3
	print(len(set(ans)))
	print(*ans)


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if all((a[i] == a[0] for i in range(n))):
		print(1)
		print(*[1] * n)
		return
	else:
		if n % 2 == 0:
			b = [0] * n
			for i in range(n):
				b[i] = i % 2 + 1
			print(2)
			print(*b)
			return
		index = -1
		for i in range(n):
			if a[i - 1] == a[i]:
				index = i
				break
		if index < 0:
			print(3)
			b = [0] * n
			for i in range(n):
				b[i] = i % 2 + 1
			b[-1] = 3
			print(*b)
			return
		else:
			print(2)
			b = [0] * n
			cnt = 1
			for j in range(i, n + i - 1):
				b[j % n] = cnt
				cnt += 1
				if cnt > 2:
					cnt -= 2
			b[i - 1] = 1
			print(*b)
			return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


q = int(input())
for _ in range(q):
	n = int(input())
	t = [int(s) for s in input().split()]
	max_color = 1
	diff = False
	same = -1
	for (i, a) in enumerate(t):
		if t[(i - 1) % n] != a:
			diff = True
		if t[(i - 1) % n] == a:
			same = i
	if diff:
		if len(t) % 2 == 0:
			print(2)
			print(' '.join(['1', '2'] * (len(t) // 2)))
		elif same == -1:
			print(3)
			print(' '.join(['1', '2'] * ((len(t) - 1) // 2) + ['3']))
		else:
			print(2)
			s = []
			first = False
			for i in range(len(t)):
				if not first and t[i] == t[(i - 1) % n]:
					first = True
				s.append(str((i + int(first)) % 2 + 1))
			print(' '.join(s))
	else:
		print(1)
		print(' '.join(['1'] * len(t)))


t = int(input())
for i in range(t):
	n = int(input())
	c = list(map(int, input().split()))
	if c.count(c[0]) == n:
		print(1)
		print(*[1 for j in range(n)])
	elif n % 2 == 0:
		print(2)
		print(*[j % 2 + 1 for j in range(n)])
	else:
		color = 1
		clist = [1]
		typelast_index = []
		k = 2
		for j in range(1, n - 1):
			if c[j] != c[j - 1]:
				typelast_index.append(j - 1)
				color = 3 - color
			clist.append(color)
		if clist[n - 2] == 1 or c[n - 1] == c[n - 2]:
			clist.append(2)
		elif c[n - 1] == c[0]:
			clist.append(1)
		else:
			typelast_index.append(n - 2)
			for j in range(len(typelast_index) - 1, -1, -1):
				ind = typelast_index[j]
				if ind != 0 and c[ind] == c[ind - 1]:
					for l in range(ind, n - 1):
						clist[l] = 3 - clist[l]
					clist.append(2)
					break
			if len(clist) == n - 1:
				clist.append(3)
				k = 3
		print(k)
		print(*clist)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print('1')
		for _ in range(n):
			print('1', end=' ')
		print()
		return
	if n % 2 == 0:
		print('2')
		for i in range(n):
			if i % 2 == 0:
				print('1', end=' ')
			else:
				print('2', end=' ')
		print()
		return
	else:
		arr = [0 for _ in range(n)]
		for i in range(n):
			if a[i] == a[(i + 1) % n]:
				arr[(i + 1) % n] = 1
				arr[i] = 1
				cnt = 0
				for j in range(i + 2, n):
					if cnt % 2 == 0:
						arr[j] = 2
					else:
						arr[j] = 1
					cnt += 1
				cnt = 0
				for j in range(i - 1, -1, -1):
					if cnt % 2 == 0:
						arr[j] = 2
					else:
						arr[j] = 1
					cnt += 1
				print('2')
				for i in range(n):
					print(arr[i], end=' ')
				print()
				return
		print('3')
		for i in range(n - 1):
			if i % 2 == 0:
				print('1', end=' ')
			else:
				print('2', end=' ')
		print('3')
		return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


import math

def divisiblity(a, b):
	c = a % b
	if c == 0:
		return 0
	return b - c

def beautiful_string(n, k):
	a = int((math.sqrt(8 * k + 1) - 1) / 2) + 1
	b = k - int(a * (a - 1) / 2)
	if b == 0:
		s = 'a' * (n - a) + 'bb' + 'a' * (a - 2)
		return s
	else:
		s = 'a' * (n - a - 1) + 'b' + 'a' * (a - b) + 'b' + 'a' * (b - 1)
		return s

def ternary_xor(x):
	a = ''
	b = ''
	c = True
	for i in x:
		if i == '0':
			a += '0'
			b += '0'
		elif i == '1':
			if c:
				a += '1'
				b += '0'
				c = False
			else:
				a += '0'
				b += '1'
		elif c:
			a += '1'
			b += '1'
		else:
			a += '0'
			b += '2'
	return (a, b)

def coloring(x):
	if len(set(x)) == 1:
		return (1, [1] * len(x))
	if len(x) % 2 == 0:
		return (2, [1, 2] * int(len(x) / 2))
	else:
		i = 0
		while i < len(x):
			if x[i] == x[i - 1]:
				break
			i += 1
		if i == len(x):
			return (3, [1, 2] * int(len(x) / 2) + [3])
		elif i == 0:
			return (2, [1, 2] * int(len(x) / 2) + [1])
		elif i % 2 == 1:
			return (2, [1, 2] * int(i / 2) + [1, 1] + [2, 1] * int((len(x) - i - 1) / 2) + [2])
		else:
			return (2, [1, 2] * (int(i / 2) - 1) + [1, 2, 2] + [1, 2] * int((len(x) - i - 1) / 2))
cases = int(input())
for _ in range(cases):
	l = input()
	x = list(map(int, input().split()))
	(c, y) = coloring(x)
	print(c)
	print(*y)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	ans2 = []
	ans3 = []
	f = 0
	ind = 0
	for i in range(1, n):
		if a[i] == a[i - 1]:
			f = 1
			ind = i
			break
	for i in range(n):
		if i % 2 == 0:
			ans.append(1)
			ans2.append(1)
		else:
			ans.append(2)
			ans2.append(2)
		if i == n - 1:
			ans2[-1] = 3
		if i < ind:
			if i % 2 == 0:
				ans3.append(1)
			else:
				ans3.append(2)
		elif i % 2 == 0:
			ans3.append(2)
		else:
			ans3.append(1)
	if len(set(a)) == 1:
		print(1)
		print(*[1] * n)
	elif a[0] == a[-1]:
		print(2)
		print(*ans)
	elif ans[-1] == ans[0]:
		if f == 0:
			print(3)
			print(*ans2)
		elif f == 1:
			print(2)
			print(*ans3)
	else:
		print(2)
		print(*ans)


import bisect
import os
import io
from collections import Counter
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce
from collections import deque
import threading

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

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	n = iinput()
	a = rlinput()
	if len(set(a)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		got = False
		ans = []
		for i in range(n):
			ans.append(i % 2 + 1)
		for i in range(n):
			if a[i] == a[(i + 1) % n]:
				got = True
				ans[i] = 1
				ans[(i + 1) % n] = 1
				for j in range(1, n - 1):
					ans[(j + i + 1) % n] = j % 2 + 1
				break
		if got:
			print(2)
			print(*ans)
		else:
			print(3)
			ans[-1] = 3
			print(*ans)


q = int(input())
while q > 0:
	n = int(input())
	t = [int(x) for x in input().split(' ')]
	if len(set(t)) == 1:
		print('1')
		print(' '.join(['1'] * n))
	elif n % 2 == 0:
		print('2')
		print(' '.join(['2 1'] * (n // 2)))
	else:
		t += [t[0]]
		R = [[t[i], t[i + 1]] for i in range(n)]
		L = [len(set(x)) for x in R]
		if min(L) == 1:
			print('2')
			N = ['2' for i in range(n)]
			j = L.index(1)
			if j < n - 1:
				N[j] = '1'
				N[j + 1] = '1'
				i = 0
				for i in range(j):
					if i % 2 == j % 2:
						N[i] = '1'
						i = i + 1
					else:
						i = i + 1
				i = j + 1
				for i in range(j + 1, n):
					if i % 2 == (j + 1) % 2:
						N[i] = '1'
						i = i + 1
					else:
						i = i + 1
			else:
				N[j] = '1'
				N[0] = '1'
				for i in range(1, j):
					if i % 2 == 1:
						N[i] = '2'
						i = i + 1
					else:
						N[i] = '1'
						i = i + 1
			print(' '.join(N))
		else:
			print('3')
			print(' '.join(['1 2'] * (n // 2) + ['3']))
	q = q - 1


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()
res = ['YES', 'NO']
for _ in range(ii()):
	n = ii()
	f = 1
	a = li()
	for i in range(1, n):
		if a[i] != a[i - 1]:
			f = 0
			break
	if f:
		print(1)
		print(*[1] * n)
	else:
		f = 2
		s = [1, 2] * (n // 2)
		if n % 2:
			if a[-1] == a[0]:
				s.append(1)
			else:
				s.append(2)
				f = 3
				for i in range(n - 2, -1, -1):
					if a[i] == a[i + 1]:
						f = 2
						break
					if s[i + 1] == 2:
						s[i] = 1
					else:
						s[i] = 2
				if f == 3:
					s[0] = 3
		print(f)
		print(*s)


q = int(input())
for i in range(q):
	n = int(input())
	t = [int(i) for i in input().split()]
	t.append(t[0])
	ans = [0] * (n + 1)
	ans[0] = 1
	ans[-1] = 1
	if len(set(t)) == 1:
		ans = [1] * n
		print(1)
		print(*ans)
	else:
		for i in range(1, len(ans) - 2):
			if t[i] == t[i - 1]:
				if (i + n - 1) % 2 == 0:
					ans[i] = 2
				elif (i + n - 1) % 2 == 1:
					ans[i] = 1
			else:
				ans[i] = 2 * ans[i - 1] % 3
		if t[-2] == t[-3]:
			if ans[-3] != ans[-1]:
				ans[-2] = ans[-3]
			else:
				ans[-2] = 2
		elif t[-2] == t[-1]:
			if ans[-3] != ans[-1]:
				ans[-2] = ans[-1]
			else:
				ans[-2] = 2
		elif t[-2] != t[-1] and t[-2] != t[-3]:
			if ans[-3] != ans[-1]:
				ans[-2] = 3
			else:
				ans[-2] = 2
		if t[-2] == t[-1] and t[-2] == t[-3]:
			ans[-2] = ans[-3]
		print(max(ans))
		print(*ans[:len(ans) - 1])


def do_it(n, t):
	front = ['1']
	back = ['2']
	single = t.count(t[0])
	if single == n:
		return (1, ['1'] * n)
	for i in range(1, n):
		if t[i] == t[i - 1]:
			golden = i
			for j in range(1, n - golden):
				if back[j - 1] == '1':
					back.append('2')
				else:
					back.append('1')
			return (2, front + back[::-1])
		elif front[-1] == '1':
			front.append('2')
		else:
			front.append('1')
	if n % 2 == 0 or t[0] == t[-1]:
		return (2, front)
	front[-1] = '3'
	return (3, front)

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		t = list(map(int, input().split()))
		(m, l) = do_it(n, t)
		print(m)
		print(' '.join(l))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = set(a)
	if len(b) == 1:
		print('1')
		for i in range(n):
			print('1', end=' ')
	elif n % 2 == 1 and a[0] != a[-1] and (a[-1] != a[-2]):
		check = False
		for i in range(n - 1):
			if a[i] == a[i + 1]:
				check = True
				C = i
				break
		if check == True:
			print('2')
			for i in range(C + 1):
				if i % 2 == 0:
					ab = 1
					print('1', end=' ')
				else:
					ab = 2
					print('2', end=' ')
			print(ab, end=' ')
			for i in range(C + 2, n):
				if i % 2 == 0:
					print('2', end=' ')
				else:
					print('1', end=' ')
		else:
			print('3')
			for i in range((n - 1) // 2):
				print('1 2 ', end='')
			print('3', end='')
	elif n % 2 == 1 and a[0] != a[-1] and (a[-1] == a[-2]):
		print('2')
		for i in range((n - 1) // 2):
			print('1 2 ', end='')
		print('2', end='')
	else:
		print('2')
		for i in range(1, n + 1):
			if i % 2 == 0:
				print('2', end=' ')
			else:
				print('1', end=' ')
	print('')


t = int(input())
for q in range(0, t):
	n = int(input())
	t = list(map(int, input().split()))
	arr = [0] * n
	arr[0] = 1
	flag = True
	for i in range(1, n):
		if t[i] == t[i - 1]:
			arr[i] = arr[i - 1]
		else:
			flag = False
			if arr[i - 1] == 1:
				arr[i] = 2
			else:
				arr[i] = 1
	if flag:
		print(1)
		print(*arr)
	elif arr[0] != arr[n - 1] or (arr[0] == arr[n - 1] and t[0] == t[n - 1]):
		print(2)
		print(*arr)
	else:
		flag = True
		for j in range(1, n):
			if t[j] == t[j - 1] and flag:
				flag = False
				if arr[j - 1] == 1:
					arr[j] = 2
				else:
					arr[j] = 1
			elif t[j] == t[j - 1] and (not flag):
				arr[j] = arr[j - 1]
			elif arr[j - 1] == 1:
				arr[j] = 2
			else:
				arr[j] = 1
		if not flag:
			print(2)
			print(*arr)
		else:
			for i in range(0, n - 1):
				arr[i] = 3
				if arr[i] != arr[i + 1]:
					break
			print(3)
			print(*arr)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

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))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def lcm(a, b):
	return abs(a // gcd(a, b) * b)

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

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

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def arr1d(n, v):
	return [v] * n

def arr2d(n, m, v):
	return [[v] * m for _ in range(n)]

def arr3d(n, m, p, v):
	return [[[v] * p for _ in range(m)] for i in range(n)]

def solve():
	n = N()
	ar = lis()
	perm = [1, 2, 3]
	m = 4
	for tempar in permutate(perm):
		n_temp = list(tempar).copy()
		color = [0] * n
		for i in range(n):
			if i == 1:
				n_temp.sort()
			for j in range(3):
				if ar[i] != ar[i - 1] and n_temp[j] == color[i - 1] or (ar[i] != ar[(i + 1) % n] and n_temp[j] == color[(i + 1) % n]):
					continue
				color[i] = n_temp[j]
				break
		ans = len(set(color))
		if ans < m:
			m = ans
			answer = color
	print(m)
	print(*answer)
testcase(int(inp()))


from itertools import groupby

def go():
	n = int(input())
	x = list(map(int, input().split()))
	if all((xx == x[0] for xx in x)):
		return '1\n' + ' '.join(['1'] * n)
	if n % 2 == 0:
		return '2\n' + ' '.join(['1', '2'] * (n // 2))
	prev = x[-1]
	done = False
	ans = []
	cur = 0
	for xx in x:
		if prev == xx and (not done):
			done = True
		else:
			cur = (cur + 1) % 2
		ans.append(str(cur + 1))
		prev = xx
	if not done:
		ans[0] = '3'
		v = '3'
	else:
		v = '2'
	return v + '\n' + ' '.join(ans)
t = int(input())
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	m = 0
	for i in range(n):
		m += min(1, t[i] ^ t[(i + 1) % n])
	if m == 0:
		k = 1
		c = [1] * n
	elif m % 2 == 0:
		k = 2
		c = [1]
		for i in range(n - 1):
			if t[i] ^ t[i + 1]:
				c.append(c[-1] ^ 3)
			else:
				c.append(c[-1])
	elif m == n:
		k = 3
		c = [1 + i % 2 for i in range(n)]
		c[0] = 3
	else:
		k = 2
		f = 0
		c = [1]
		for i in range(n - 1):
			if t[i] ^ t[i + 1]:
				c.append(c[-1] ^ 3)
			elif not f:
				c.append(c[-1] ^ 3)
				f = 1
			else:
				c.append(c[-1])
	print(k)
	print(*c)


t = int(input())
for i in range(t):
	n = int(input())
	t = list(map(int, input().strip().split()))
	c = [0] * n
	noDistinct = 1
	prev = t[0]
	for i in range(1, n):
		if t[i] != t[0]:
			noDistinct = 2
			break
	if noDistinct == 1:
		c = [1 for i in range(n)]
	if noDistinct == 2:
		if n % 2 == 0:
			for i in range(n):
				if i % 2 == 0:
					c[i] = 1
				else:
					c[i] = 2
		else:
			flag = 0
			for i in range(n - 1):
				if i % 2 == 0:
					c[i] = 1
				else:
					c[i] = 2
				if t[i] == t[i + 1]:
					flag = 1
					x = i
					break
			if flag == 0:
				if t[n - 1] == t[0]:
					c[n - 1] = c[0]
				else:
					c[n - 1] = 3
					noDistinct = 3
			else:
				c[x + 1] = c[x]
				for i in range(x + 2, n):
					if i % 2 == 0:
						c[i] = 2
					else:
						c[i] = 1
	print(noDistinct)
	for i in range(n):
		print(c[i], end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	color = []
	st = set(ar)
	ct = 0
	if len(st) == 1:
		ct = 1
		color = ['1'] * n
	elif len(ar) % 2 == 0:
		ct = 2
		color = ['1', '2'] * (n // 2)
	else:
		ind = -1
		for i in range(1, n):
			if ar[i] == ar[i - 1]:
				ind = i
				break
		if ind == -1:
			ct = 3
			color = ['1', '2'] * (n // 2)
			if ar[0] == ar[n - 1]:
				ct = 2
				color.append('1')
			else:
				color.append('3')
		else:
			prev = '2'
			ct = 2
			for i in range(n):
				if i == ind:
					color.append(color[i - 1])
				else:
					if prev == '2':
						prev = '1'
					else:
						prev = '2'
					color.append(prev)
	print(ct)
	print(' '.join(color))


for _ in range(int(input())):
	n = int(input())
	x = input().split()
	y = x[1:]
	y.append(x[0])
	eq = sum((u == v for (u, v) in zip(x, y)))
	ne = n - eq
	if ne == 0:
		print(1)
		print(*[1] * n)
	elif ne % 2 == 0:
		print(2)
		res = []
		cur = 1
		for (u, v) in zip(x, y):
			res.append(cur)
			if u != v:
				cur = 3 - cur
		print(*res)
	elif eq > 0:
		print(2)
		res = []
		spl = True
		cur = 1
		for (u, v) in zip(x, y):
			res.append(cur)
			if u != v:
				cur = 3 - cur
			elif spl:
				cur = 3 - cur
				spl = False
		print(*res)
	else:
		print(3)
		print(1, *[2, 3] * (n // 2))


def isValid(l, col):
	n = len(l)
	for i in range(n):
		prev = (i - 1 + n) % n
		nex = (i + 1) % n
		if l[i] != l[prev] and col[i] == col[prev]:
			return False
		if l[i] != l[nex] and col[i] == col[nex]:
			return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if len(set(l)) == 1:
		col = [0 for k in range(n)]
	else:
		col = [k % 2 for k in range(n)]
	dup = -1
	for j in range(n):
		nex = (j + 1) % n
		if l[j] == l[nex]:
			dup = j
			break
	ans = isValid(l, col)
	if not ans and dup != -1:
		for k in range(dup + 1, n):
			col[k] = 1 - col[k]
	ans = ans or isValid(l, col)
	if not ans:
		col[n - 1] = 2
	print(max(col) + 1)
	for c in col:
		print(c + 1, end=' ')
	print()


t = int(input())
for v in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	se = set(li)
	if len(se) == 1:
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()
		continue
	if n % 2 == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print()
	else:
		flag = False
		li.append(li[0])
		for i in range(1, n + 1):
			if li[i] == li[i - 1]:
				myind = i
				flag = True
				break
		if flag:
			i = 0
			print(2)
			while i <= myind and i < n:
				if i == myind:
					print(prev, end=' ')
				elif i % 2 == 0:
					print(1, end=' ')
					prev = 1
				else:
					print(2, end=' ')
					prev = 2
				i += 1
			i = myind + 1
			while i < n:
				if prev == 2:
					print(1, end=' ')
					prev = 1
				elif prev == 1:
					print(2, end=' ')
					prev = 2
				i += 1
			print()
		else:
			print(3)
			for i in range(n):
				if i == n - 1:
					print(3, end=' ')
				elif i % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
			print()


q = int(input())
for qq in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		col = 1
		sol = [0] * n
	elif len(t) % 2 == 0:
		col = 2
		sol = [0, 1] * (len(t) // 2)
	else:
		col = 2
		sol = [0, 1] * (len(t) // 2) + [0]
		if t[0] != t[-1]:
			coup = -1
			t.append(t[0])
			for i in range(len(t) - 1):
				if t[i] == t[i + 1]:
					coup = i + 1
					break
			if coup > -1:
				for i in range(coup, len(t) - 1):
					sol[i] = (sol[i] + 1) % 2
			else:
				col = 3
				sol[-1] = 2
	print(col)
	print(' '.join(map(lambda x: str(x + 1), sol)))


from collections import defaultdict as dd, deque as dq
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	res = []
	d = dd(int)
	for i in l:
		d[i] += 1
	ty = 2
	ll = list(set(l))
	lol = 0
	if len(ll) == 2:
		ty = 2
		for i in l:
			if i == ll[0]:
				res.append(1)
			else:
				res.append(2)
	elif len(ll) == 1:
		ty = 1
		res = [1] * n
	elif n % 2 == 0:
		for i in range(n):
			if i % 2 == 0:
				res.append(1)
			else:
				res.append(2)
	else:
		ty = 2
		if l[-1] == l[0]:
			for i in range(n):
				if i % 2 == 0:
					res.append(1)
				else:
					res.append(2)
		else:
			i = 1
			j = n - 1
			res = [0] * n
			res[0] = 1
			res[n - 1] = 2
			lol = 0
			while i < n - 1:
				if l[i] == l[i - 1] and lol == 0:
					lol = 1
					res[i] = res[i - 1]
				elif l[i] == l[i - 1] and lol == 1:
					res[i] = 3 - res[i - 1]
				else:
					res[i] = 3 - res[i - 1]
				i += 1
			if lol == 0:
				for i in range(1, n):
					if l[i] != l[i - 1] and res[i] == res[i - 1]:
						res[i] = 3
						ty += 1
						break
	print(ty)
	print(*res)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 1
	b = 0
	check = True
	for j in range(1, n):
		if a[j - 1] != a[j]:
			ans = 2
			b = 1 - b
		else:
			check = False
			ind = j
	if a[n - 1] == a[0]:
		b = 1 - b
		check = False
		ind = 0
	if b == 0 and check and (ans != 1):
		ans = 3
	answer = [0] * n
	answer[0] = 1
	for j in range(1, n):
		if a[j] != a[j - 1]:
			answer[j] = 3 - answer[j - 1]
		else:
			answer[j] = answer[j - 1]
			if not check and ans == 2 and (j == ind) and (b == 0):
				answer[j] = 3 - answer[j - 1]
	if ans == 3:
		answer[-1] = 3
	print(ans)
	print(*answer)


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	k = [1]

	def chkList(lst):
		return len(set(lst)) == 1
	flag = 0
	if chkList(l) == True:
		print(1)
		print('1 ' * len(l))
	elif len(l) % 2 == 0:
		print(2)
		print('1 2 ' * int(len(l) / 2))
	else:
		s = ''
		if l[0] == l[-1]:
			flag = 2
		else:
			for i in range(1, len(l)):
				if l[i] == l[i - 1]:
					flag = 1
					pos = i
					break
				else:
					continue
		if flag == 2:
			print(2)
			print('1 2 ' * int((len(l) - 1) / 2) + '1')
		elif flag == 1:
			print(2)
			for i in range(1, len(l)):
				if flag == 1 and pos == i:
					k.append(k[-1])
					flag = 0
				elif k[-1] == 1:
					k.append(2)
				else:
					k.append(1)
			for i in k:
				s += str(i) + ' '
			print(s)
		else:
			print(3)
			print('1 2 ' * int((len(l) - 1) / 2), end='')
			print(3)


def areallequal(arr):
	x = arr[0]
	for i in range(len(arr)):
		if arr[i] != x:
			return 0
	return 1
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	if areallequal(li):
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()
	else:
		k = 2
		lo = [1]
		curr = li[0]
		currcol = 1
		for i in range(1, n):
			if li[i] == curr:
				lo.append(currcol)
			elif currcol == 1:
				currcol = 2
				curr = li[i]
				lo.append(2)
			else:
				currcol = 1
				curr = li[i]
				lo.append(1)
		if lo[0] == lo[n - 1] and li[0] != li[n - 1]:
			done = 0
			for i in range(n - 1):
				if li[i] == li[i + 1]:
					t = i + 1
					done = 1
			if done:
				for i in range(t, n):
					if lo[i] == 2:
						lo[i] = 1
					else:
						lo[i] = 2
			if done == 0:
				k += 1
				lo[n - 1] = 3
		print(k)
		for i in lo:
			print(i, end=' ')
		print()


from sys import stdin, stdout
import collections, heapq, bisect, math
input = stdin.readline

def rint():
	return int(input())

def rstr():
	return input().strip()

def rlstr():
	return list(input().strip().split())

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

def main():
	n = rint()
	fig = rlint()
	flag = True
	for i in range(n - 1):
		if fig[i] != fig[i + 1]:
			flag = False
			break
	if flag:
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()
		return
	if n % 2 == 0:
		print(2)
		p = 1
		for i in range(n):
			print(p + 1, end=' ')
			p = 1 - p
		print()
		return
	for i in range(n):
		if fig[i] == fig[(i + 1) % n]:
			res = [0] * n
			p = 1
			for j in range(i + 1, n):
				res[j] = p + 1
				p = 1 - p
			p = 1
			for j in range(i, -1, -1):
				res[j] = p + 1
				p = 1 - p
			print(2)
			for i in range(n):
				print(res[i], end=' ')
			print()
			return
	print(3)
	p = 1
	for i in range(n - 1):
		print(p + 1, end=' ')
		p = 1 - p
	print(3)
for _ in range(rint()):
	main()


def com(x):
	if x == 1:
		return 2
	else:
		return 1
import sys
for t in range(int(sys.stdin.readline().strip())):
	n = int(sys.stdin.readline().strip())
	l = [int(j) for j in sys.stdin.readline().split()]
	ans = [1]
	n_inv = 0
	for i in range(n):
		if l[i] != l[i - 1]:
			n_inv += 1
	if n_inv % 2 == 1:
		flag = True
	l.append(l[0])
	for i in range(1, n + 1):
		if l[i] != l[i - 1]:
			ans.append(com(ans[i - 1]))
		elif n_inv % 2 == 0:
			ans.append(ans[i - 1])
		else:
			ans.append(com(ans[i - 1]))
			n_inv += 1
	if ans[0] == ans[-1]:
		ans = ans[:-1]
	else:
		ans[0] = 3
		ans = ans[:-1]
	print(len(set(ans)))
	ans = ' '.join([str(i) for i in ans])
	sys.stdout.write(ans)
	sys.stdout.write('\n')


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	if len(set(s)) == 1:
		print(1)
		print(*[1 for i in range(n)])
	elif n % 2 == 0:
		print(2)
		print(*[i % 2 + 1 for i in range(n)])
	elif s[0] == s[-1]:
		print(2)
		print(*[i % 2 + 1 for i in range(n)])
	else:
		was = False
		ans = [1]
		for i in range(1, n):
			if s[i - 1] == s[i] and (not was):
				ans.append(ans[-1])
				was = True
			else:
				ans.append(ans[-1] % 2 + 1)
		if was:
			print(2)
			print(*ans)
		else:
			print(3)
			print(*[i % 2 + 1 for i in range(n - 1)] + [3])


import itertools
for testcase in range(int(input())):
	n = int(input())
	figures = list(map(int, input().split()))
	last = figures[-1]
	has_same = False
	same_pos = None
	all_same = True
	even = n % 2 == 0
	for (ix, i) in enumerate(figures):
		if last == i:
			has_same = True
			if same_pos is None:
				same_pos = ix
		else:
			all_same = False
		last = i
	if all_same:
		print(1)
		print(*[1] * n)
	elif even:
		print(2)
		print(*[1, 2] * (n // 2))
	elif has_same:
		print(2)
		sol = [None] * n
		sol[same_pos] = 1
		sol[same_pos - 1] = 1
		x = same_pos
		two = True
		while 1:
			x += 1
			x %= n
			if sol[x] is not None:
				break
			sol[x] = [1, 2][two]
			two = not two
		print(*sol)
	else:
		print(3)
		sol = [1, 2, 3] * (n // 3)
		p = n % 3
		if p == 1:
			sol.append(2)
		elif p == 2:
			sol.extend((1, 2))
		print(*sol)


from sys import stdin
for case in range(int(stdin.readline())):
	n = int(stdin.readline())
	car = [int(x) for x in stdin.readline().split()]
	if car.count(car[0]) == n:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		tu = False
		ind = -1
		for x in range(n):
			if car[x] == car[x - 1]:
				tu = True
				ind = x
				break
		if tu:
			print(2)
			l = [0 for x in range(n)]
			for x in range(ind, ind + n - 2, 2):
				l[x % n] = '1'
				l[(x + 1) % n] = '2'
			l[ind - 1] = '1'
			print(' '.join(l))
		else:
			print(3)
			print('1 2 ' * (n // 2) + '3')


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(item) for item in input().split()]
	kind = len(set(a))
	if kind == 1:
		ans = [1] * n
		print(1)
		print(*ans)
		continue
	a.append(a[0])
	l = 0
	has_sequence = False
	for (i, (a1, a2)) in enumerate(zip(a, a[1:])):
		if a1 == a2:
			l = i
			has_sequence = True
			break
	if not has_sequence:
		if n % 2 == 0:
			ans = [1, 2] * (n // 2)
			print(2)
			print(*ans)
		else:
			ans = [1, 2] * (n // 2) + [3]
			print(3)
			print(*ans)
		continue
	if n % 2 == 0:
		ans = [1, 2] * (n // 2)
		print(2)
		print(*ans)
	else:
		ans = [1, 2] * (n // 2)
		if l == n - 1:
			ans.append(ans[0])
		else:
			ans.insert(l, ans[l])
		print(2)
		print(*ans)


import math, sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	l = list(map(int, sys.stdin.readline().split()))
	if len(set(l)) == 1:
		print(1)
		ans = [1] * n
		print(*ans)
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print('1', end=' ')
			else:
				print('2', end=' ')
		print()
	else:
		flag = 0
		ans = []
		c = 0
		for i in range(n - 1):
			if l[i] == l[i + 1]:
				if len(ans) == 0:
					ans.append(1)
					ans.append(1)
				elif ans[-1] == 1:
					ans.append(2)
					ans.append(2)
				else:
					ans.append(1)
					ans.append(1)
				flag = 1
				c = i + 1
				break
			elif len(ans) == 0:
				ans.append(1)
			elif ans[-1] == 1:
				ans.append(2)
			else:
				ans.append(1)
		if flag == 0:
			if l[0] == l[-1]:
				ans.append(1)
				print(2)
			else:
				ans.append(3)
				print(3)
			print(*ans)
		else:
			for i in range(c + 1, n):
				if ans[-1] == 1:
					ans.append(2)
				else:
					ans.append(1)
			print(2)
			print(*ans)


x = int(input())
for a in range(0, x):
	y = int(input())
	x1 = input().split()
	d = []
	l = 1
	s = ''
	if len(set(x1)) == 1:
		print(1)
		s = '1 ' * y
	elif y % 2 == 0 or x1[-1] == x1[0]:
		print(2)
		s = '1 2 ' * int(y / 2)
		if y % 2 == 1:
			s += '1 '
	else:
		f = True
		for c in range(0, y):
			d.append(l)
			if c != y - 1:
				if not x1[c] == x1[c + 1] or not f:
					l = 3 - l
				elif f:
					f = False
		if not f:
			print(2)
		elif d[-1] == d[0]:
			print(3)
			d[-1] = 3
	for each in d:
		s += str(each) + ' '
	print(s[:-1])


from sys import stdin, stdout
res = ['1'] * int(2 * 100000.0 + 5)

def reverse(index, length):
	for i in range(index, length):
		if res[i] == '1':
			res[i] = '2'
		else:
			res[i] = '1'
q = int(stdin.readline())
while q:
	n = int(stdin.readline())
	t = list(stdin.readline().strip().split(' '))
	start = 0
	i = 0
	flip = False
	colors = 1
	last = -1
	while i < len(t):
		while i < len(t) and t[start] == t[i]:
			if start != i:
				last = i
			i += 1
		if flip:
			if colors == 1:
				colors = 2
			res[start:start + (i - start)] = ['2'] * (i - start)
		else:
			res[start:start + (i - start)] = ['1'] * (i - start)
		flip = not flip
		start = i
	if t[0] != t[-1] and res[n - 1] == '1':
		if last != -1:
			reverse(last, n)
		else:
			res[n - 1] = '3'
			colors = 3
	stdout.write(str(colors))
	stdout.write('\n')
	stdout.write(' '.join(res[:n]))
	stdout.write('\n')
	q -= 1


R = lambda : map(int, input().split())
t = int(input())

def solve(a, n):
	s = set(a)
	if len(s) == 1:
		print(1)
		print(*[1 for _ in range(n)])
		return
	if n % 2 == 0:
		print(2)
		print(*[1 + k % 2 for k in range(n)])
		return
	found = -1
	for i in range(n):
		if a[i] == a[i - 1]:
			found = i
			break
	if found == -1:
		print(3)
		ans = [1 + k % 2 for k in range(n)]
		ans[-1] = 3
		print(*ans)
		return
	print(2)
	ans = [1] * n
	for i in range(found, found + n, 2):
		ans[i % n] = 2
	print(*ans)
	return
for _ in range(t):
	n = int(input())
	a = list(R())
	solve(a, n)


from sys import stdin

def isSame(ts):
	it = iter(ts)
	next(it)
	return all(map(lambda p: p[0] == p[1], zip(iter(ts), it)))

def oddRingStart(n, ts):
	for x in range(0, n):
		if ts[x] == ts[(x + 1) % n]:
			return x
	return -1

def solve(n, ts):
	if isSame(ts):
		return ('1', ['1'] * n)
	if n % 2 == 0:
		return ('2', [1, 2] * (n // 2))
	pos = oddRingStart(n, ts)
	if pos == -1:
		return ('3', [1, 2] * (n // 2) + [3])
	res = [1, 2] * (n // 2) + [1]
	L = len(res) - pos - 1
	return ('2', res[L:] + res[:L])
input()
for (a, b) in zip(*[iter(stdin)] * 2):
	n = int(a)
	ts = list(map(int, b.split()))
	(T, res) = solve(n, ts)
	print(T)
	print(*res)


import io
import os
from collections import Counter, defaultdict, deque

def makeRepeat(arr):
	repeat = [[arr[0], 0]]
	for x in arr:
		if x == repeat[-1][0]:
			repeat[-1][1] += 1
		else:
			repeat.append([x, 1])
	return repeat

def solve(N, T):
	if len(set(T)) == 1:
		return '1' + '\n' + ' '.join(('1' for i in range(N)))
	repeats = makeRepeat(T)
	assert len(repeats) > 1
	rot = 0
	if repeats[-1][0] == repeats[0][0]:
		rot = repeats[-1][1]
		repeats[0][1] += repeats[-1][1]
		repeats.pop()
	colors = []
	greaterThanOne = None
	for (i, (_, count)) in enumerate(repeats):
		if count > 1:
			greaterThanOne = i
		color = i % 2
		colors.append([color] * count)
	if len(repeats) % 2 == 1:
		if greaterThanOne is None:
			colors[-1][-1] = 2
		else:
			colors[greaterThanOne][-1] ^= 1
			for i in range(greaterThanOne + 1, len(colors)):
				for j in range(0, len(colors[i])):
					colors[i][j] ^= 1
	colors = deque([x + 1 for l in colors for x in l])
	k = len(set(colors))
	assert k <= 3
	colors.rotate(-rot)
	return str(k) + '\n' + ' '.join(map(str, colors))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
Q = int(input())
for q in range(Q):
	(N,) = [int(x) for x in input().split()]
	T = [int(x) for x in input().split()]
	ans = solve(N, T)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	temp = [i for i in arr]
	temp.sort()
	if temp[0] == temp[-1]:
		print(1)
		ans = [1] * n
		print(*ans)
	elif n % 2 == 0:
		print(2)
		ans = [1, 2] * (n // 2)
		print(*ans)
	else:
		flag = 0
		for i in range(n - 1):
			if arr[i] == arr[i + 1]:
				flag = 1
				che = i + 1
				break
		if flag == 1 or arr[0] == arr[-1]:
			if flag == 1:
				print(2)
				ans = [1, 2] * (n // 2)
				ans.insert(che, ans[che - 1])
				print(*ans)
			else:
				print(2)
				ans = [1, 2] * (n // 2)
				ans.append(1)
				print(*ans)
		else:
			print(3)
			ans = [1, 2] * (n // 2)
			ans += [3]
			print(*ans)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	if ar == [ar[0]] * n:
		print(1)
		print(*[1] * n)
	elif n % 2 == 0 or (n % 2 != 0 and ar[0] == ar[-1]):
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
	else:
		flag = True
		for j in range(1, n):
			if ar[j] == ar[j - 1]:
				flag = False
				break
		if flag:
			print(3)
			print('1 2 ' * ((n - 1) // 2) + '3')
		else:
			print(2)
			li = [1]
			for i in range(1, j):
				if li[-1] == 1:
					li.append(2)
				else:
					li.append(1)
			li.append(li[-1])
			for i in range(j + 1, n):
				if li[-1] == 1:
					li.append(2)
				else:
					li.append(1)
			print(*li)


from heapq import *
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	q = II()
	for _ in range(q):
		n = II()
		tt = LI()
		cc = [0] * n
		cc[0] = 1
		cnt = 1
		same = -1
		for i in range(1, n):
			if tt[i - 1] == tt[i]:
				cc[i] = cc[i - 1]
				same = i
			else:
				cc[i] = 3 - cc[i - 1]
				cnt = 2
		if tt[0] != tt[-1] and cc[0] == cc[-1]:
			if same == -1:
				cnt = 3
				for i in range(n):
					if cc[i] == 2:
						break
					cc[i] = 3
			else:
				cc[same] = 3 - cc[same]
				for i in range(same + 1, n):
					if tt[i - 1] == tt[i]:
						cc[i] = cc[i - 1]
					else:
						cc[i] = 3 - cc[i - 1]
		print(cnt)
		print(*cc)
main()


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 998244353

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k))))
from collections import deque, defaultdict
import heapq

def solution(a, n):
	if len(set(a)) == 1:
		return '1\n' + '1 ' * n
	if n % 2 == 0:
		return '2\n' + '1 2 ' * (n // 2)
	if a[-1] == a[0]:
		return '2\n' + '1 2 ' * (n // 2) + '1'
	sol = [1]
	done = False
	for i in range(1, n):
		if a[i] == a[i - 1] and (not done):
			sol.append(sol[-1])
			done = True
			continue
		sol.append(3 - sol[-1])
	if done == True:
		return '2\n' + ' '.join(map(str, sol))
	return '3\n' + '1 2 ' * (n // 2) + '3'

def main():
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		x = solution(a, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


DEBUG = False
if DEBUG:
	import sys
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	pre = l[0]
	flag = True
	flag2 = -1
	for i in range(n):
		if l[(i - 1) % n] == l[i]:
			flag2 = i
		if l[i] != pre:
			flag = False
	if flag:
		return (1, [0] * n)
	if n % 2 == 0:
		return (2, [0, 1] * (n // 2))
	if flag2 != -1:
		c = [0] * n
		for i in range(1, n, 2):
			c[(i + flag2) % n] = 1
		c[(flag2 + n - 1) % n] = 0
		return (2, c)
	c = [1]
	for i in range(1, n):
		if i == n - 1:
			c.append(2)
		else:
			c.append((c[-1] + 1) % 2)
	return (3, c)
t = int(input())
for _ in range(t):
	(k, c) = solve()
	print(k)
	print(' '.join([str(i + 1) for i in c]))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	n = val()
	l = li()
	l1 = []
	ind = 1
	if len(Counter(l)) == 1:
		print(1)
		l = [1] * n
		print(*l)
		continue
	for i in range(len(l)):
		l1.append(ind)
		ind = 3 - ind
	if l[-1] != l[0]:
		if l1[-1] == l1[0]:
			toggle = -1
			for j in range(1, n):
				if l[j] == l[j - 1]:
					l1.pop(j)
					l1.append(3 - l1[0])
					break
				if j == n - 1:
					l1[j] = 3
	print(max(l1))
	print(*l1)


def f(n, t):
	c = 1
	clist = [0] * n
	clist[0] = 1
	if len(set(t)) == 1:
		print(c)
		return '1 ' * n
	if n % 2 == 0:
		print(2)
		return '1 2 ' * (n // 2)
	if t[-1] == t[0]:
		print(2)
		return '1 2 ' * (n // 2) + '1'
	s = ''
	for i in range(n - 2):
		if t[i] == t[i + 1]:
			print(2)
			if (i + 1) % 2 != 0:
				return '1 2 ' * ((i + 1) // 2) + '1 1 ' + '2 1 ' * (n // 2 - (i + 1) // 2 - 1) + '2'
			else:
				return '1 2 ' * ((i + 1) // 2 - 1) + '1 ' + '2 2 ' + '1 2 ' * (n // 2 - (i + 1) // 2)
	if t[-2] == t[-1]:
		print(2)
		return '1 2 ' * (n // 2) + '2'
	print(3)
	return '1 2 ' * (n // 2) + '3'

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		t = [int(i) for i in input().split()]
		print(f(n, t))
main()


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ansArray = [0 for i in range(n)]
	switch = -1
	maxV = 1
	ansArray[0] = 1
	for i in range(n - 1):
		if x[i] == x[i + 1]:
			switch = i
			ansArray[i + 1] = ansArray[i]
		elif ansArray[i] == 2:
			ansArray[i + 1] = 1
		else:
			ansArray[i + 1] = 2
			maxV = 2
	if x[-1] != x[0] and ansArray[-1] == ansArray[0]:
		if switch == -1:
			ansArray[-1] = 3
			maxV = 3
			switch = -1
	else:
		switch = -1
	print(maxV)
	for i in range(n):
		if switch != -1 and i > switch:
			if ansArray[i] == 2:
				print(1, end=' ')
			else:
				print(2, end=' ')
		else:
			print(ansArray[i], end=' ')
	print()


T = int(input())
n = [0] * T
k = [0] * T
ns = [0] * T
for t in range(T):
	n[t] = int(input())
	ns[t] = [int(i) for i in input().split(' ')]

def ans(n, ns):
	wo = False
	if n % 2 == 1:
		wo = True
	if len(set(ns)) == 1:
		print(1)
		return '1 ' * n
	c = ['1']
	cc = 0
	for i in range(1, n):
		if ns[i] == ns[i - 1] and wo:
			c.append(str(cc + 1))
			wo = False
		else:
			cc ^= 1
			c.append(str(cc + 1))
	if wo and ns[-1] == ns[0]:
		wo = False
	if wo:
		c[-1] = '3'
		print(3)
	else:
		print(2)
	return ' '.join(c)
for t in range(T):
	print(ans(n[t], ns[t]))


t = int(input())
for _ in range(t):
	n = int(input())
	figure = [int(i) for i in input().split()]
	if figure.count(figure[0]) == n:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			print(i % 2 + 1, end=' ')
		print()
	else:
		flg = -1
		for i in range(n):
			if figure[i] == figure[i - 1]:
				flg = i
				break
		if flg != -1:
			print(2)
			for i in range(n):
				if i < flg:
					print(i % 2 + 1, end=' ')
				else:
					print((i + 1) % 2 + 1, end=' ')
			print()
		else:
			print(3)
			for i in range(n - 1):
				print(i % 2 + 1, end=' ')
			print(3)


q = int(input())
for j in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	colours = [1] * n
	count = 0
	for i in range(n):
		if t[i] != t[(i + 1) % n]:
			count += 1
	if count == 0:
		print(1)
	elif n % 2 == 0:
		print(2)
		for i in range(1, n):
			if i % 2 == 0:
				colours[i] = 1
			else:
				colours[i] = 2
	elif count != n:
		print(2)
		a = True
		for i in range(n):
			if t[i] == t[i - 1] and a:
				colours[i] = colours[i - 1]
				a = False
			else:
				colours[i] = 3 - colours[i - 1]
	else:
		print(3)
		for i in range(1, n):
			if i % 2 == 0:
				colours[i] = 1
			else:
				colours[i] = 2
		colours[-1] = 3
	print(*colours)


def solve(n, animals):
	ok = True
	if animals[0] != animals[n - 1]:
		ok = False
	i = 1
	while ok and i < n:
		if animals[i - 1] != animals[i]:
			ok = False
		i += 1
	if ok:
		print(1)
		print(' '.join(['1'] * n))
	elif n % 2 == 0:
		print(2)
		ans = ['1'] * n
		for i in range(1, n, 2):
			ans[i] = '2'
		print(' '.join(ans))
	else:
		dp = [[False] * 2 for _ in range(n)]
		dp[0][0] = True
		for i in range(1, n):
			if animals[i] != animals[i - 1]:
				dp[i][0] = dp[i - 1][1]
				dp[i][1] = dp[i - 1][0]
			else:
				dp[i][0] = dp[i - 1][1] | dp[i - 1][0]
				dp[i][1] = dp[i - 1][1] | dp[i - 1][0]
		if dp[n - 1][1] or (dp[n - 1][0] and animals[0] == animals[n - 1]):
			print(2)
			j = 1 if dp[n - 1][1] else 0
			ans = [str(1 + j)]
			for i in range(n - 2, -1, -1):
				if animals[i + 1] == animals[i] and dp[i][j]:
					ans.append(str(1 + j))
				else:
					ans.append(str(2 - j))
					j = 1 - j
			print(' '.join(ans[::-1]))
		else:
			print(3)
			ans = ['1'] * n
			for i in range(1, n, 2):
				ans[i] = '2'
			ans[0] = '3'
			print(' '.join(ans))
for _ in range(int(input())):
	n = int(input())
	animals = [int(num) for num in input().strip().split()]
	solve(n, animals)


for _ in range(int(input())):
	n = int(input())
	typea = list(map(int, input().split()))
	if len(set(typea)) == 1:
		print(1)
		print(*[1] * n)
		continue
	val = 1
	for i in range(n):
		val = typea[i % n] ^ typea[(i + 1) % n]
		pos1 = i
		pos2 = (i + 1) % n
		if val == 0:
			break
	if n % 2 == 0:
		print(2)
		for i in range(n):
			print(1 + i % 2, end=' ')
		print()
	elif val == 0:
		print(2)
		a = 1
		b = 2
		for i in range(n):
			if i == pos2:
				print(b, end=' ')
			else:
				print(a, end=' ')
				(a, b) = (b, a)
		print()
	else:
		print(3)
		for i in range(n - 1):
			print(1 + i % 2, end=' ')
		print(3)


t = int(input())
for _ in range(t):
	n = int(input())
	k = 1
	a = list(map(int, input().split()))
	c = [1] * n
	fli = 0
	for i in range(1, n):
		if a[i] != a[i - 1]:
			c[i] = 3 - c[i - 1]
			k = 2
		else:
			c[i] = c[i - 1]
			fli = i
	if a[0] != a[-1] and c[0] == c[-1]:
		if fli:
			for i in range(fli, n):
				c[i] = 3 - c[i]
		else:
			c[0] = k + 1
			k += 1
	print(k)
	print(' '.join([str(x) for x in c]))


q = int(input())
for Case in range(q):
	n = int(input())
	status = False
	figType = list(map(int, input().split(' ')))
	result = [1]
	for i in range(1, len(figType)):
		if figType[i] == figType[i - 1]:
			result.append(result[-1])
			status = True
			index = i
		elif result[-1] == 1:
			result.append(2)
		else:
			result.append(1)
	if result[-1] == result[0] and figType[-1] != figType[0]:
		if status:
			if result[index - 1] == 1:
				result[index] = 2
			else:
				result[index] = 1
			for i in range(index + 1, len(figType)):
				if figType[i] == figType[i - 1]:
					result[i] = result[i - 1]
				elif result[i - 1] == 1:
					result[i] = 2
				else:
					result[i] = 1
		else:
			result[-1] = 3
	k = 1
	if 2 in result:
		k = 2
	if 3 in result:
		k = 3
	print(k)
	for i in range(len(result)):
		if i == len(result) - 1:
			print(result[i])
		else:
			print(result[i], end=' ')


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	r = []
	if all((x == t[0] for x in t)):
		r = [1] * n
	elif n % 2 == 0:
		r = [1, 2] * (n // 2)
	else:
		r = [1, 2] * (n // 2)
		k = -1
		for i in range(n):
			if t[i] == t[i - 1]:
				k = i
		if k != -1:
			val = 1 if k % 2 == 1 else 2
			r.insert(k, val)
		else:
			r.append(3)
	print(max(r))
	print(' '.join(map(str, r)))


from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
import os
import 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')

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		arr = list(RL())
		tp = len(set(arr))
		if tp == 1:
			print(1)
			print(*[1] * n)
		elif n % 2 == 0:
			print(2)
			print(*([1, 2] * n)[:n])
		else:
			res = [0] * n
			tag = True
			res[0] = 0
			for i in range(1, n):
				if arr[i] == arr[i - 1] and tag:
					tag = False
					res[i] = res[i - 1]
				else:
					res[i] = res[i - 1] ^ 1
			res = [i + 1 for i in res]
			if tag and arr[0] != arr[-1]:
				print(3)
				res[-1] = 3
				print(*res)
			else:
				print(2)
				print(*res)
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	ans = [1]
	for i in range(1, n):
		if t[i] != t[i - 1]:
			if ans[-1] == 1:
				ans.append(2)
			else:
				ans.append(1)
		else:
			ans.append(ans[-1])
	if ans[-1] == ans[0] and t[0] != t[-1]:
		done = False
		for i in range(n - 1, 0, -1):
			if ans[i] == ans[i - 1]:
				done = True
			if ans[i] == 1:
				ans[i] = 2
			else:
				ans[i] = 1
			if done:
				break
		if not done:
			ans[0] = 3
	print(max(ans))
	print(' '.join(list(map(str, ans))))


def solve(ans):
	length = int(input())
	li = [int(x) for x in input().split()]
	for i in range(length - 1):
		if li[i] != li[i + 1]:
			break
	else:
		ans.append(1)
		temp = [1 for i in range(length)]
		ans.append(temp)
		return
	if length % 2 == 0:
		ans.append(2)
		temp = [1, 2] * (length // 2)
		ans.append(temp)
	else:
		temp = []
		if li[i] == li[-1]:
			ans.append(2)
			temp = [1, 2] * ((length - 1) // 2) + [1]
			ans.append(temp)
		else:
			temp = [1]
			for i in range(1, length):
				if li[i] == li[i - 1]:
					ans.append(2)
					temp.append(temp[-1])
					for j in range(i + 1, length):
						if temp[-1] == 1:
							temp.append(2)
						else:
							temp.append(1)
					ans.append(temp)
					break
				elif temp[-1] == 1:
					temp.append(2)
				else:
					temp.append(1)
			else:
				temp[-1] = 3
				ans.append(3)
				ans.append(temp)
	return
n = int(input())
ans = []
for i in range(n):
	solve(ans)
for i in range(2 * n):
	if i % 2 == 0:
		print(ans[i])
	else:
		for ele in ans[i]:
			print(ele, end=' ')
		print()


for i in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	if t.count(t[0]) == n:
		print(1)
		print(' '.join((repr(e) for e in [1] * n)))
	elif n % 2 == 0:
		print(2)
		print(' '.join((repr(e) for e in [1, 2] * int(n / 2))))
	else:
		flag = 0
		for j in range(n):
			if t[j] == t[(j + 1) % n]:
				flag = 1
				break
		if flag == 1:
			print(2)
			if j == n - 1:
				print(' '.join((repr(e) for e in [1, 2] * int(n / 2) + [1])))
			elif j % 2 == 0:
				a = [2, 1] * int(j / 2) + [2] + [2, 1] * int(n / 2 - j / 2)
				print(' '.join((repr(e) for e in a)))
			else:
				a = [1, 2] * int(j / 2 + 1) + [2] + [1, 2] * int(n / 2 - j / 2 - 1)
				print(' '.join((repr(e) for e in a)))
		else:
			print(3)
			print(' '.join((repr(e) for e in [1, 2] * int(n / 2) + [3])))


from sys import stdin, stdout
import math

def main():
	t = int(input())
	while t:
		n = int(input())
		l = list(map(int, input().split()))
		s = list(set(l))
		s_len = len(s)
		j = -1
		if l[0] == l[n - 1]:
			j = 0
		for i in range(1, n):
			if l[i] == l[i - 1]:
				j = i
				break
		if s_len == 1:
			ans = 1
			c = [1] * n
		else:
			c = [0] * n
			if n % 2 == 0:
				c[0] = 1
				ans = 2
				for i in range(1, n):
					if c[i - 1] == 1:
						c[i] = 2
					else:
						c[i] = 1
			elif j == -1:
				c[0] = 1
				ans = 3
				for i in range(1, n):
					if c[i - 1] == 1:
						c[i] = 2
					else:
						c[i] = 1
				c[n - 1] = 3
			else:
				c[0] = 1
				ans = 2
				for i in range(1, n):
					if i == j:
						c[i] = c[i - 1]
					elif c[i - 1] == 1:
						c[i] = 2
					else:
						c[i] = 1
		print(ans)
		for i in range(n):
			print(c[i], end=' ')
		print()
		t -= 1
main()


from sys import stdin, stdout
import collections
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	a = set(arr)
	if len(a) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	elif arr[-1] != arr[0]:
		temp = -1
		for i in range(n - 1):
			if arr[i] == arr[i + 1]:
				temp = i
				break
		else:
			print(3)
			print('1 2 ' * (n // 2) + '3')
		if temp != -1:
			print(2)
			if temp % 2 == 0:
				print('1 2 ' * (temp // 2) + '1 ' + '1 2 ' * (n // 2 - temp // 2))
			else:
				print('1 2 ' * (temp // 2 + 1) + '2 ' + '1 2 ' * (n // 2 - temp // 2 - 1))
	else:
		print(2)
		print('1 2 ' * (n // 2) + '1')


q = int(input())
for i in range(q):
	n = int(input())
	an = input().split(' ')
	res = []
	color = 1
	c = an[0]
	same = True
	for i in range(n):
		if an[i] != c:
			same = False
		res.append(color)
		if an[i] != an[(i + 1) % n]:
			color = 3 - color
	if same:
		print('1')
		print('1 ' * n)
	else:
		if an[0] != an[-1] and res[0] == res[-1]:
			i = 0
			double = False
			for i in range(n):
				if res[i] == res[i - 1] and an[i] == an[i - 1]:
					double = True
					break
				else:
					prev = res[i]
			if double:
				for j in range(i):
					res[j] = 3 - res[j]
				print('2')
			else:
				for i in range(n):
					if res[i] == 1:
						res[i] = 3
					else:
						break
				print('3')
		else:
			print('2')
		s = ''
		for i in res:
			s += str(i) + ' '
		print(s[:-1])


q = int(input())
for _ in range(q):
	n = int(input())
	types = list(map(int, input().split()))
	same = set(types)
	if len(same) == 1:
		ans = '1 ' * n
		print(1)
		print(ans)
		continue
	if n % 2 == 0:
		ans = [1 if i % 2 == 0 else 2 for i in range(n)]
		print(2)
		print(*ans, sep=' ')
	else:
		pair_exists = 0
		idx = -1
		ans = list(bytearray(n))
		for i in range(1, n):
			if types[i] == types[i - 1]:
				pair_exists = 1
				idx = i
				break
		if idx == -1 and types[0] == types[n - 1]:
			idx = 0
			pair_exists = 1
		if pair_exists == 0:
			curr = 1
			for i in range(n - 1):
				ans[i] = curr
				curr = 2 if curr == 1 else 1
			ans[n - 1] = 3
			print(3)
			print(*ans, sep=' ')
		else:
			curr = 1
			for i in range(n):
				if i == idx and idx != 0:
					ans[i] = ans[i - 1]
					curr = ans[i - 1]
					curr = 2 if curr == 1 else 1
				else:
					ans[i] = curr
					curr = 2 if curr == 1 else 1
			print(2)
			print(*ans, sep=' ')


t = int(input())
while t > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = [0]
	temp = -1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			ans.append(ans[i - 1])
			temp = i
		else:
			ans.append((ans[i - 1] + 1) % 2)
	if a[-1] != a[0] and ans[-1] == ans[0]:
		if temp == -1:
			ans[-1] = 2
		else:
			for i in range(temp, n):
				if i == temp:
					ans[i] = (ans[i - 1] + 1) % 2
				elif a[i] == a[i - 1]:
					ans[i] = ans[i - 1]
				else:
					ans[i] = (ans[i - 1] + 1) % 2
	s = set(ans)
	s1 = list(s)
	l = len(s1)
	print(l)
	for i in range(n):
		print(ans[i] + 1, end=' ')
	print()
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	animals = [int(d) for d in input().split()]
	same = True
	if n % 2 == 0:
		for i in range(1, n):
			if animals[i] != animals[i - 1]:
				same = False
				break
		if not same:
			print(2)
			print(*[1, 2] * (n // 2))
		else:
			print(1)
			print(*[1] * n)
	else:
		clr_num = 1
		clr = {1: 2, 2: 1}
		colors = [1] * n
		same = True
		need_stay = False
		if animals[-1] != animals[0]:
			need_stay = True
		for i in range(1, n):
			if animals[i] == animals[i - 1]:
				if need_stay:
					need_stay = False
					colors[i] = colors[i - 1]
				else:
					colors[i] = clr[colors[i - 1]]
			else:
				same = False
				clr_num = 2
				colors[i] = clr[colors[i - 1]]
		if animals[-1] != animals[0] and colors[-1] == colors[0]:
			colors[-1] = 3
			clr_num = 3
		if not same:
			print(clr_num)
			print(*colors)
		else:
			print(1)
			print(*[1] * n)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	kk = 0
	xx = 0
	if len(list(set(a))) == 1:
		p = [1] * n
		kkk = 1
	elif not n % 2:
		p = [0 for _ in range(n)]
		for ii in range(n):
			if ii % 2:
				p[ii] = 2
			else:
				p[ii] = 1
		kkk = 2
	else:
		for ii in range(1, n):
			if a[ii] == a[ii - 1]:
				kk = 1
				xx = ii
				break
		p = [0 for _ in range(n)]
		p[0] = 1
		if kk == 1:
			for ii in range(1, n):
				if ii == xx:
					p[ii] = p[ii - 1]
				elif p[ii - 1] == 1:
					p[ii] = 2
				else:
					p[ii] = 1
			kkk = 2
		else:
			for ii in range(n - 1):
				if ii % 2:
					p[ii] = 2
				else:
					p[ii] = 1
			if a[n - 1] == a[0]:
				p[n - 1] = 1
				kkk = 2
			else:
				p[n - 1] = 3
				kkk = 3
	print(kkk)
	print(*p)


import collections
t = int(input())

def solve(n, arr):

	def start_x(x):
		ans = [0] * n
		for i in range(n):
			if i == 0:
				ans[i] = x
			elif i < n - 1:
				if arr[i] == arr[i - 1]:
					if arr[i] == arr[i + 1]:
						ans[i] = 1
					else:
						ans[i] = 2
				elif ans[i - 1] == 1:
					ans[i] = 2
				else:
					ans[i] = 1
			elif i == n - 1:
				if arr[i] == arr[i - 1]:
					if arr[i] == arr[0]:
						ans[i] = 1
					elif ans[0] == 1:
						ans[i] = 2
					else:
						ans[i] = 1
				elif arr[i] == arr[0]:
					if ans[i - 1] == 1:
						ans[i] = 2
					else:
						ans[i] = 1
				elif ans[i - 1] == 1:
					if ans[0] == 1:
						ans[i] = 2
					else:
						ans[i] = 3
				elif ans[0] == 2:
					ans[i] = 1
				else:
					ans[i] = 3
		return ans
	l1 = start_x(1)
	l2 = start_x(2)
	if max(l1) < max(l2):
		print(max(l1))
		print(' '.join(map(str, l1)))
	else:
		print(max(l2))
		print(' '.join(map(str, l2)))
	return
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(n, arr)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	if len(set(s)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		ans = []
		k = f = 1
		for i in range(n):
			i1 = (i - 1) % n
			if f and s[i] == s[(i - 1) % n]:
				ans.append(3 - k)
				f = 0
			else:
				ans.append(k)
				k = 3 - k
		if f:
			print(3)
			print('1 2 ' * (n // 2) + '3')
			continue
		else:
			print(2)
			print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	if len(set(arr)) == 1:
		print(1)
		print('1 ' * n)
	else:
		ans = [1]
		l = 1
		for i in range(1, n):
			if arr[i] != arr[i - 1]:
				l = 3 - l
			ans.append(l)
		count = 2
		if arr[0] != arr[n - 1]:
			if ans[0] == ans[n - 1]:
				indo = 0
				b = False
				for i in range(1, n):
					if arr[i] == arr[i - 1]:
						b = True
						ans[i] = 3 - ans[i]
						for j in range(i + 1, n):
							if arr[j] == arr[j - 1]:
								ans[j] = ans[j - 1]
							else:
								ans[j] = 3 - ans[j - 1]
						break
				if not b:
					count = 3
					ans[n - 1] = 3
		print(count)
		ans = [str(i) for i in ans]
		print(' '.join(ans))


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	array = array + [array[0]]
	if len(set(array)) == 1:
		print(1)
		print(*[1] * n)
	elif n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
	else:
		flag = -1
		for i in range(1, n + 1):
			if array[i] == array[i - 1]:
				flag = i
				break
		if flag == -1:
			print(3)
			print(*[1, 2] * (n // 2), 3)
		else:
			x = 0
			res = [0]
			for i in range(1, n):
				if i != flag:
					x = (x + 1) % 2
				res.append(x)
			res = [r + 1 for r in res]
			print(2)
			print(*res)


for p in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	out = list()
	out.append(1)
	color = 1
	k = -1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			out.append(color)
			k = i
		else:
			color = color % 2 + 1
			out.append(color)
	if out[n - 1] == out[0] and k > -1 and (a[n - 1] != a[0]):
		for i in range(k, n):
			out[i] = out[i] % 2 + 1
	elif out[n - 1] == out[0] and a[n - 1] != a[0]:
		out[n - 1] = 3
	print(max(out))
	print(*out)


t = int(input())
import math
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	col_num = 2
	if len(set(a)) == 1:
		print(1)
		print('1 ' * n)
		continue
	if n % 2 == 0:
		for i in range(1, n):
			b[i] = i % 2
	else:
		last_pos = -1
		for i in range(1, n):
			b[i] = i % 2
			if a[i - 1] == a[i]:
				last_pos = i
		if last_pos == -1 and a[0] != a[-1]:
			b[-1] = 2
			col_num = 3
		elif a[0] != a[-1]:
			for i in range(last_pos, n):
				b[i] = (b[i] + 1) % 2
	print(col_num)
	for i in range(n):
		print(b[i] + 1, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	ans = [0] * n
	x = t[0]
	flag = 1
	for i in range(n):
		if t[i] != t[0]:
			flag = 0
	if flag:
		ans = [1] * n
		print(1)
		print(*ans, sep=' ')
		continue
	flag = 1
	for i in range(0, n, 2):
		ans[i] = 1
	for i in range(1, n, 2):
		ans[i] = 2
	if t[n - 1] != t[0] and ans[n - 1] == ans[0]:
		for i in range(n - 1):
			if t[i] == t[i + 1]:
				flag = 0
				ans[i + 1] = ans[i]
				break
		if flag == 0:
			for k in range(i + 2, n):
				if ans[k] == 1:
					ans[k] = 2
				elif ans[k] == 2:
					ans[k] = 1
		else:
			ans[n - 1] = 3
	if 3 in ans:
		print(3)
	else:
		print(2)
	print(*ans, sep=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if n % 2 == 0:
		a = max(arr)
		b = min(arr)
		if a == b:
			print(1)
			ans = [1] * n
			print(' '.join((str(x) for x in ans)))
		else:
			ans = []
			for i in range(n):
				if i % 2 == 0:
					ans.append(1)
				else:
					ans.append(2)
			print(2)
			print(' '.join((str(x) for x in ans)))
	else:
		a = max(arr)
		b = min(arr)
		if a == b:
			print(1)
			ans = [1] * n
			print(' '.join((str(x) for x in ans)))
		else:
			ans = [0] * n
			if arr[0] == arr[-1]:
				ans[0] = 1
				ans[-1] = 1
				for i in range(1, n - 1):
					if i % 2 == 1:
						ans[i] = 2
					else:
						ans[i] = 1
				print(2)
				print(' '.join((str(x) for x in ans)))
			else:
				temp = -1
				for i in range(n - 1):
					if arr[i] == arr[i + 1]:
						temp = i
						break
				if temp == -1:
					ans[-1] = 3
					for i in range(n - 1):
						if i % 2 == 0:
							ans[i] = 1
						else:
							ans[i] = 2
					print(3)
					print(' '.join((str(x) for x in ans)))
				else:
					ans[temp] = 1
					ans[temp + 1] = 1
					j = temp + 2
					for i in range(2, n):
						if i % 2 == 0:
							ans[j % n] = 2
						else:
							ans[j % n] = 1
						j += 1
					print(2)
					print(' '.join((str(x) for x in ans)))


def solve():
	N = int(input())
	L = list(map(int, input().split()))
	if len(set(L)) == 1:
		print(1)
		print(' '.join(['1' for _ in range(N)]))
	elif N % 2 == 0:
		A = [i % 2 + 1 for i in range(N)]
		print(2)
		print(' '.join(map(str, A)))
	else:
		for i in range(N):
			if L[i] == L[(i + 1) % N]:
				A = []
				for j in range(i + 1):
					A.append(j % 2 + 1)
				for j in range(i + 1, N):
					A.append((j + 1) % 2 + 1)
				print(2)
				print(' '.join(map(str, A)))
				break
		else:
			A = [i % 2 + 1 for i in range(N - 1)] + [3]
			print(3)
			print(' '.join(map(str, A)))
T = int(input())
for _ in range(T):
	solve()


def tryToChange(c):
	for i in range(1, len(c)):
		if c[i] == c[i - 1]:
			toPast = 1 if c[i - 1] == 2 else 2
			j = i
			while j < len(c):
				c[j] = 1 if c[j] == 2 else 2
				j += 1
			return c
	return False

def getDrawings(a):
	n = len(a)
	if len(set(a)) == 1:
		k = 1
		return (1, [1] * n)
	c = [1] * n
	k = 2
	for i in range(1, n):
		if a[i] == a[i - 1]:
			c[i] = c[i - 1]
		elif c[i - 1] == 2:
			c[i] = 1
		else:
			c[i] = 2
	if a[0] != a[-1] and c[0] == c[-1]:
		result = tryToChange(c)
		if result == False:
			c[-1] = 3
			k = 3
		else:
			c = result
	return (k, c)
kt = int(input())
for t in range(kt):
	n = int(input())
	a = list(map(int, input().split()))
	(k, answer) = getDrawings(a)
	print(k)
	for x in answer:
		print(x, end=' ')
	print()


t = int(input())
for foo in range(t):
	n = int(input())
	t = list(map(int, input().split()))
	same = 1
	pair = 0
	for i in range(n):
		if t[i] == t[i - 1]:
			pair = 1
		else:
			same = 0
	if same == 1:
		print(1)
		print(*[1] * n)
	elif n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
	else:
		if pair == 1:
			print(2)
			s = [1] * n
			p = 0
			for i in range(n - 1):
				if p == 1 or t[i] != t[i - 1]:
					s[i] = 3 - s[i - 1]
				else:
					p = 1
					s[i] = s[i - 1]
			print(*s)
		if pair == 0:
			print(3)
			print(*[1, 2] * (n // 2), 3)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		print(1)
		print(*[1] * n)
		continue
	if n % 2 == 0:
		print(2)
		for i in range(0, n):
			print(i % 2 + 1, end=' ')
		print()
		continue
	flag = False
	for i in range(n):
		if arr[i] == arr[(i + 1) % n]:
			temp = 0
			for j in range(i + 1, n):
				arr[j] = temp + 1
				temp ^= 1
			temp = 0
			for j in range(i, -1, -1):
				arr[j] = temp + 1
				temp ^= 1
			print(2)
			print(*arr)
			flag = True
	if flag:
		continue
	print(3)
	for i in range(0, n - 1):
		print(i % 2 + 1, end=' ')
	print(3)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	n = len(a)
	groups = 0
	s2 = False
	ind = 0
	for i in range(1, n):
		if a[i - 1] != a[i]:
			groups += 1
		elif not s2:
			s2 = True
			ind = i - 1
	if a[-1] != a[0]:
		groups += 1
	elif not s2:
		ind = 0
		s2 = True
	if groups == 0:
		groups = 1
	if groups == 1:
		print(1)
		print('1 ' * n)
	else:
		if groups % 2 == 1:
			if s2:
				a[ind] = -1
				groups += 1
		if groups % 2 == 0:
			t = 0
			print(2)
			print('1', end=' ')
			for i in range(1, n):
				if a[i] == a[i - 1]:
					print(t + 1, end=' ')
				else:
					t = (t + 1) % 2
					print(t + 1, end=' ')
			print()
		else:
			ans = []
			print(3)
			t = 0
			ans.append('1 ')
			for i in range(1, n):
				if a[i] == a[i - 1]:
					ans.append(str(t + 1) + ' ')
				else:
					t = (t + 1) % 2
					ans.append(str(t + 1) + ' ')
			for i in range(n):
				if a[i] != a[(i + 1) % n] and ans[i] == ans[(i + 1) % n]:
					ans[i] = '3 '
			print(''.join(ans))


for nt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = list(set(l))
	s.sort()
	if len(s) == 1:
		print(1)
		print(*[1] * n)
	elif len(s) == 2:
		print(2)
		a = s[0]
		b = s[1]
		ans = []
		for i in l:
			if i == a:
				ans.append(1)
			else:
				ans.append(2)
		print(*ans)
	else:
		ans = [1]
		for i in range(1, n):
			if i == n - 1:
				if l[i] == l[i - 1] and l[0] == l[i]:
					ans.append(ans[-1])
				elif l[i] == l[i - 1] and l[i] != l[0]:
					ans.append(ans[0] % 2 + 1)
				else:
					temp = ans[-1] % 2 + 1
					if l[i] == l[0]:
						ans.append(temp)
					elif temp == ans[0]:
						ans.append(3)
					else:
						ans.append(temp)
				continue
			if l[i] == l[i - 1]:
				ans.append(ans[-1])
			else:
				ans.append(ans[-1] % 2 + 1)
		x = len(set(ans))
		if x == 2:
			print(2)
			print(*ans)
			continue
		find = 0
		for i in range(n - 1, 0, -1):
			if l[i] == l[i - 1]:
				index = i
				prev = ans[i - 1]
				find = 1
				break
		if not find:
			print(3)
			print(*ans)
		else:
			for i in range(index, n):
				ans[i] = ans[i - 1] % 2 + 1
			print(2)
			print(*ans)


n = int(input())
for i in range(n):
	input()
	lst = list(map(int, input().split()))
	sol = []
	sol.append(1)
	col = 1
	modify = False
	if lst[-1] == lst[1]:
		modify = True
		lst = [lst[-1]] + lst[:-1]
	pos = -1
	for i in range(1, len(lst)):
		if lst[i] != lst[i - 1]:
			if col == 1:
				col = 2
			else:
				col = 1
		else:
			pos = i
		sol.append(col)
	if lst[0] != lst[-1] and sol[0] == sol[-1]:
		if pos == -1:
			sol[-1] = 3
		else:
			for i in range(pos, len(lst)):
				if sol[i] == 1:
					sol[i] = 2
				else:
					sol[i] = 1
	if modify:
		sol = sol[1:] + [sol[0]]
	print(max(sol))
	print(*sol)


for _ in range(int(input())):
	n = int(input())
	(*_figs,) = map(int, input().split())
	_setfig = set(_figs)
	if len(_setfig) == 1:
		print(1)
		print('1 ' * n)
	elif not n & 1:
		print(2)
		print('2 1 ' * (n // 2))
	else:
		for i in range(n):
			if _figs[i] == _figs[(i + 1) % n]:
				j = 0
				pos = i + 1
				ans = [0 for i in range(n)]
				while pos < n:
					ans[pos] = j + 1
					pos += 1
					j ^= 1
				j = 0
				pos = i
				while pos >= 0:
					ans[pos] = j + 1
					pos -= 1
					j ^= 1
				print(2)
				print(*ans)
				break
		else:
			print(3)
			print('1', '2 3 ' * ((n - 1) // 2))


from sys import stdin, stdout

def read():
	x = stdin.readline().rstrip()
	return x

def __main__():
	q = int(read())
	for q0 in range(q):
		n = int(read())
		t = read()
		z = [int(i) for i in t.split()]
		x1 = -1
		x2 = -1
		z0 = set(z)
		if len(z0) == 1:
			c = '1'
			c0 = ['1' for g in range(n)]
		elif n % 2 == 0:
			c = '2'
			c0 = ['1 2' for g in range(n // 2)]
		else:
			ind = 0
			v0 = z[ind]
			fl = True
			for v in z[1:]:
				ind += 1
				if v == v0:
					if fl:
						x1 = ind - 1
						x2 = ind
						fl = False
				v0 = v
			if z[0] == z[-1]:
				if fl:
					x1 = 0
					x2 = n - 1
					fl = False
			if fl:
				c = '3'
				c0 = ['1 2 3' for g in range(n // 3)]
				for h in range(n - n // 3 * 3):
					if h % 2 == 0:
						c0.append('2')
					else:
						c0.append('3')
			else:
				c = '2'
				c0 = []
				for g in range(n - 1):
					if g % 2 == 0:
						c0.append('1')
					else:
						c0.append('2')
				k1 = c0[x1]
				c0.insert(x2, k1)
		out1 = c + '\n'
		out2 = ' '.join(c0) + '\n'
		stdout.write(out1)
		stdout.write(out2)
__main__()


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		print(1)
		for i in range(n):
			print('1', end=' ')
		print()
	elif n % 2 == 0:
		print(2)
		for i in range(n // 2):
			print('1 2', end=' ')
		print()
	else:
		flag = False
		last_flag = False
		for i in range(n - 1):
			if arr[i] == arr[i + 1]:
				flag = True
				indx = i + 1
				break
		if arr[0] == arr[-1]:
			flag = True
			last_flag = True
			indx = n - 1
		if flag:
			print(2)
			print(1, end=' ')
			prev = 1
			for i in range(1, n):
				if i == indx:
					if last_flag:
						print(1, end=' ')
					else:
						print(prev, end=' ')
				else:
					if prev == 1:
						prev = 2
					else:
						prev = 1
					print(prev, end=' ')
			print()
		else:
			print(3)
			for i in range(n // 2):
				print('1 2', end=' ')
			print(3)


q = int(input())
for i in range(q):
	n = int(input())
	t = [int(i) for i in input().split(' ')]
	if t.count(t[0]) == n:
		print(1)
		for i in range(n):
			print(1, end=' ')
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			print(i % 2 + 1, end=' ')
	else:
		s = -1
		for i in range(0, len(t)):
			if t[i] == t[i - 1]:
				s = i
		if s != -1:
			print(2)
			for i in range(s):
				print(i % 2 + 1, end=' ')
			for i in range(s, n):
				print((i + 1) % 2 + 1, end=' ')
		else:
			print(3)
			for i in range(n - 1):
				print(i % 2 + 1, end=' ')
			print(3, end=' ')
	print()


from itertools import cycle, islice
q = int(input())
for _ in range(q):
	n = int(input())
	t = [*map(int, input().split())]
	if len(set(t)) == 1:
		print(1)
		print(' '.join(['1'] * len(t)))
	elif len(t) % 2 == 0:
		print(2)
		print(' '.join(islice(cycle(['1', '2']), len(t))))
	elif t[0] == t[-1]:
		print(2)
		print(' '.join(islice(cycle(['1', '2']), len(t))))
	else:
		k = -1
		for i in range(1, len(t)):
			if t[i] == t[i - 1]:
				k = i - 1
				break
		if k >= 0:
			r = list(islice(cycle(['1', '2']), k + 1))
			r.append(r[-1])
			if r[-1] == '1':
				r += list(islice(cycle(['2', '1']), len(t) - k - 2))
			else:
				r += list(islice(cycle(['1', '2']), len(t) - k - 2))
			print(2)
			print(' '.join(r))
		else:
			r = list(islice(cycle(['1', '2']), len(t) - 1))
			r.append('3')
			print(3)
			print(' '.join(r))


q = int(input().strip())
for _ in range(q):
	n = int(input().strip())
	a = list(map(int, input().strip().split()))
	c = [1]
	for i in range(1, n):
		if a[i] != a[i - 1]:
			c.append(3 - c[i - 1])
		else:
			c.append(c[i - 1])
	for i in range(n):
		if a[i] != a[i - 1] and c[i] == c[i - 1]:
			c[i] = 3 - c[i - 1]
	if a[0] != a[-1] and c[0] == c[-1]:
		c[-1] = max(c) + 1
	print(max(c))
	print(' '.join(map(str, c)))


from sys import stdin, stdout
input = stdin.readline

def a():
	t = int(input())
	for _ in range(t):
		(a, b) = map(int, input().split())
		if a % b == 0:
			print(0)
		else:
			print(str(b - a % b))

def b():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		bpos1 = 0
		bpos2 = 0
		for i in range(2, n + 1):
			asdf = i * (i - 1) // 2
			if asdf >= k:
				bpos1 = i
				bpos2 = bpos1 - (asdf - k) - 1
				break
		string = ['a'] * n
		string[n - bpos1] = 'b'
		string[n - bpos2] = 'b'
		print(''.join(string))

def c():
	t = int(input())
	for _ in range(t):
		n = int(input())
		x = [int(i) for i in input().rstrip()]
		a = [0] * n
		b = [0] * n
		ind = 0
		for i in x:
			if i == 0:
				a[ind] = 0
				b[ind] = 0
			elif i == 1:
				a[ind] = 1
				b[ind] = 0
				break
			else:
				a[ind] = 1
				b[ind] = 1
			ind += 1
		for i in range(ind + 1, n):
			b[i] = x[i]
		for i in a:
			stdout.write(str(i))
		stdout.write('\n')
		for i in b:
			stdout.write(str(i))
		stdout.write('\n')

def d():
	q = int(input())
	for _ in range(q):
		n = int(input())
		t = list(map(int, input().split()))
		colors = [1] * n
		same = True
		for i in range(1, n):
			if t[i] != t[i - 1]:
				same = False
				break
		if same:
			print(1)
			print(*colors)
		else:
			for i in range(1, n):
				colors[i] = colors[i - 1] % 2 + 1
			if n % 2 == 0:
				print(2)
				print(*colors)
			else:
				ind = -1
				if t[0] == t[n - 1]:
					ind = n
				for i in range(1, n):
					if t[i] == t[i - 1]:
						ind = i
						break
				if ind >= 0:
					for i in range(ind, n):
						colors[i] = colors[i] % 2 + 1
					print(2)
					print(*colors)
				else:
					colors[n - 1] = 3
					print(3)
					print(*colors)
d()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	st = [int(i) for i in input().split(' ')]
	allSame = True
	neighborsSame = False
	for i in range(n):
		if not st[i] == st[(i + 1) % n]:
			allSame = False
		if st[i] == st[(i + 1) % n]:
			neighborsSame = True
	if allSame:
		print(1)
		for _ in range(n):
			print(1, end=' ')
		print('')
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			pp = i % 2 + 1
			print(pp, end=' ')
		print('')
	elif neighborsSame:
		print(2)
		wasthere = False
		sols = [1] * n
		last = 2
		if st[0] == st[n - 1]:
			for i in range(n - 1):
				last = 3 - last
				sols[i] = last
		else:
			for i in range(n):
				sols[i] = last
				if not wasthere and st[i] == st[i + 1]:
					wasthere = True
				else:
					last = 3 - last
		for i in range(n):
			print(sols[i], end=' ')
		print('')
	else:
		print(3)
		for i in range(n - 1):
			pp = i % 2 + 1
			print(pp, end=' ')
		print(3)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [1] * n
	f = 1
	ind = 0
	if a[0] == a[1]:
		ind = 1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			ans[i] = ans[i - 1]
		else:
			ans[i] = 3 - ans[i - 1]
			f = 2
		if a[i] == a[(i + 1) % n]:
			ind = (i + 1) % n
	if a[0] != a[-1] and ans[-1] == ans[0]:
		ans[-1] = 3
		f = 3
	if f == 3 and ind:
		for i in range(ind, n):
			ans[i] = 3 - ans[i]
		ans[-1] = 3 - ans[0]
	print(len(set(ans)))
	print(*ans)


import sys
import os
from io import IOBase, BytesIO
import math
mod = 10 ** 9 + 7
pie = 3.1415926536

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

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

def read2DIntArray(row, col):
	arr = []
	for i in range(0, row):
		temp = list(map(int, sin().split()))
		arr.append(temp)
	return arr

def read2DCharArray(row, col):
	arr = []
	for i in range(0, row):
		temp = str(sin())
		arr.append(temp)
	return arr

def smallestNumber(n):
	lst = list(str(n))
	lst.sort()
	tmp = ''
	for (i, n) in enumerate(lst):
		if n != '0':
			tmp = lst.pop(i)
			break
	return str(tmp) + ''.join(lst)

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 * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	lst = []
	for p in range(n + 1):
		if prime[p]:
			lst.append(p)
	return lst

def nCr(n, r):
	a = 1
	b = 1
	c = 1
	for i in range(1, n + 1):
		c *= i
	for i in range(1, r + 1):
		b *= i
	for i in range(1, n - r + 1):
		a *= i
	return c // (a * b)

def sieveOfEratosthenes1(N, s):
	prime = [False] * (N + 1)
	for i in range(2, N + 1, 2):
		s[i] = 2
	for i in range(3, N + 1, 2):
		if prime[i] == False:
			s[i] = i
			for j in range(i, int(N / i) + 1, 2):
				if prime[i * j] == False:
					prime[i * j] = True
					s[i * j] = i

def generatePrimeFactors(N):
	s = [0] * (N + 1)
	sieveOfEratosthenes1(N, s)
	curr = s[N]
	cnt = 1
	factors = []
	power = []
	while N > 1:
		N //= s[N]
		if curr == s[N]:
			cnt += 1
			continue
		factors.append(curr)
		power.append(cnt)
		curr = s[N]
		cnt = 1
	return (factors, power)

def main():
	for _ in range(int(sin())):
		n = int(sin())
		t = ain()
		flag = 0
		for i in range(n):
			if i > 0 and t[i] == t[i - 1]:
				flag = 1
				break
		tmp = set(t)
		res = []
		if len(tmp) == 1:
			res = [1] * n
		elif n % 2 == 0:
			for i in range(n):
				res.append(i % 2 + 1)
		elif flag == 0:
			for i in range(n - 1):
				res.append(i % 2 + 1)
			if t[0] != t[-1]:
				res.append(3)
			else:
				res.append((n - 1) % 2 + 1)
		elif flag == 1:
			f = 0
			for i in range(n):
				if i > 0 and t[i] == t[i - 1] and (f == 0):
					res.append((i - 1) % 2 + 1)
					f = 1
				elif i > 0:
					if res[i - 1] == 1:
						res.append(2)
					else:
						res.append(1)
				else:
					res.append(i % 2 + 1)
		print(max(res))
		print(*res)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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()


from math import *
t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0 for i in range(n)]
	if len(set(a)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		f = 0
		v = 0
		for i in range(n):
			ans[i] = v + 1
			v = v ^ 1
			if i != n - 1:
				if f == 0 and a[i] == a[i + 1]:
					f = 1
					v ^= 1
			elif f == 0 and a[0] == a[-1]:
				f = 1
		if f == 0:
			ans[n - 1] = 3
			print(3)
		else:
			print(2)
		for i in ans:
			print(i, end=' ')
		print()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [1]
	b = False
	for s in range(1, n):
		if l[s] != l[s - 1]:
			ans.append(2 - (ans[-1] + 1) % 2)
		else:
			ans.append(ans[-1])
			b = True
	if l[-1] != l[0] and ans[-1] == ans[0]:
		if not b:
			ans[-1] = 3
		else:
			q = False
			for s in range(1, n):
				if q:
					ans[s] = 2 - (ans[s] + 1) % 2
				if l[s] == l[s - 1]:
					if not q:
						ans[s] = 2 - (ans[s] + 1) % 2
					q = True
	print(max(ans))
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	m = len(set(a))
	if m == 1:
		print(1)
		print(' '.join(['1'] * n))
	elif n % 2 == 0:
		print(2)
		print(' '.join(['1', '2'] * (n // 2)))
	else:
		s = -1
		for i in range(n):
			if i != n - 1:
				if a[i] == a[i + 1]:
					s = i
					break
			elif a[n - 1] == a[0]:
				s = n - 1
				break
		if s == -1:
			print(3)
			print(' '.join(['1', '2'] * (n // 2) + ['3']))
		else:
			if s % 2 == 0:
				b = ['1', '2'] * (s // 2) + ['1'] + ['1', '2'] * ((n - s - 1) // 2)
			else:
				b = ['1', '2'] * ((s + 1) // 2) + ['2'] + ['1', '2'] * ((n - s - 2) // 2)
			print(2)
			print(' '.join(b))


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	k = len(set(t))
	if k == 1:
		print(1)
		print('1 ' * n)
		continue
	if n & 1:
		if t[0] == t[-1]:
			print(2)
			print('1 2 ' * (n // 2) + '1')
		elif t[-1] == t[-2]:
			print(2)
			print('1 2 ' * (n // 2) + '2')
		else:
			p = '1 2 ' * (n // 2)
			res = True
			for i in range(1, n):
				if t[i] == t[i - 1]:
					if i & 1:
						p = p[:2 * i] + '1 ' + p[2 * i:]
					else:
						p = p[:2 * i] + '2 ' + p[2 * i:]
					res = False
					break
			if not res:
				print(2)
				print(p)
			else:
				print(3)
				print(p + '3')
	else:
		print(2)
		print('1 2 ' * (n // 2))


import sys
input = sys.stdin.readline

def solve(n, T):
	c = [1] * n
	ans = 1
	doubled = False
	doubled_idx = 0
	for i in range(n):
		if i == 0:
			c[0] = 1
		elif T[i] != T[i - 1]:
			c[i] = 3 - c[i - 1]
			ans = 2
		elif T[i] == T[i - 1]:
			c[i] = c[i - 1]
			doubled_idx = i
			doubled = True
		if i == n - 1 and c[i] == c[0] and (T[i] != T[0]) and (not doubled):
			c[i] = 3
			ans = 3
		elif i == n - 1 and c[i] == c[0] and (T[i] != T[0]) and doubled:
			for j in range(doubled_idx, n):
				c[j] = 3 - c[j]
	return (ans, c)
q = int(input())
for _ in range(q):
	n = int(input())
	T = list(map(int, input().split()))
	(clr, c) = solve(n, T)
	print(clr)
	print(*c)


for q in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = [0] * n
	y = list(set(x))
	if len(y) == 1:
		for i in range(n):
			ans[i] = 1
	elif len(x) % 2 == 0:
		for i in range(n):
			if i % 2 == 0:
				ans[i] = 1
				last = 1
			else:
				ans[i] = 2
				last = 2
	else:
		ans[0] = 1
		last = 1
		flag = True
		for i in range(1, n - 1):
			if x[i] == x[i - 1] and flag:
				ans[i] = last
				flag = False
			else:
				if last == 1:
					last = 2
				else:
					last = 1
				ans[i] = last
		if len(x) > 1:
			if last == 1:
				ans[-1] = 2
			elif last == 2 and x[-1] == x[-2]:
				ans[-1] = 2
			elif last == 2 and x[-1] == x[0]:
				ans[-1] = 1
			else:
				ans[-1] = 3
	ans1 = list(set(ans))
	print(len(ans1))
	print(*ans)


q = int(input())
while q:
	ans = 0
	q += -1
	ind = 0
	n = int(input())
	l = list(map(int, input().split()))
	s = list(set(l))
	if len(s) == 1:
		print(1)
		for i in range(n):
			print('1', end=' ')
		print()
		continue
	elif len(s) == 2:
		print(2)
		for i in range(n):
			if l[i] == s[0]:
				print('1', end=' ')
			else:
				print('2', end=' ')
		print()
		continue
	elif n % 2 == 0:
		ans = 2
		print(2)
		for i in range(n):
			if i % 2:
				print('2', end=' ')
			else:
				print('1', end=' ')
		print()
		continue
	elif l[0] == l[n - 1]:
		ans = 2
		print(2)
		for i in range(n):
			if i % 2:
				print('2', end=' ')
			else:
				print('1', end=' ')
		print()
		continue
	else:
		ch = 0
		for i in range(n - 1):
			if l[i] == l[i + 1]:
				ch = 1
				ind = i
				break
		if ch:
			ans = 2
		else:
			ans = 3
	if ans == 2:
		print(2)
		for i in range(ind + 1):
			if i % 2:
				print('2', end=' ')
			else:
				print('1', end=' ')
		for i in range(ind + 1, n):
			if ind % 2:
				if i % 2:
					print('1', end=' ')
				else:
					print('2', end=' ')
			elif i % 2:
				print('1', end=' ')
			else:
				print('2', end=' ')
	else:
		print(3)
		for i in range(n - 1):
			if i % 2:
				print('2', end=' ')
			else:
				print('1', end=' ')
		print('3', end=' ')
	print()


from sys import stdin
inf = stdin
for _ in range(int(inf.readline())):
	n = int(inf.readline())
	arr = list(map(int, inf.readline().split(' ')))
	temp = set(arr)
	if len(temp) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		flag = True
		ind = 0
		for i in range(1, n):
			if arr[i] == arr[i - 1]:
				flag = False
				ind = i
				break
		if not flag:
			print(2)
			prev = '2'
			for i in range(n):
				if i == ind:
					print(prev, end=' ')
				else:
					prev = '1' if prev == '2' else '2'
					print(prev, end=' ')
			print()
			continue
		if flag and arr[0] == arr[n - 1]:
			print(2)
			prev = '2'
			for i in range(n - 1):
				prev = '1' if prev == '2' else '2'
				print(prev, end=' ')
			print('1')
			continue
		print(3)
		print('1 2 ' * (n // 2), end='')
		print('3')


import collections

def get_color(n, crs):
	if len(set(crs)) == 1:
		return (1, [1] * n)
	if n % 2 == 0:
		return (2, [i % 2 + 1 for i in range(n)])
	overlap = sum([1 for (prev, cur) in zip([crs[-1]] + crs, crs + [crs[0]]) if prev == cur]) > 0
	if not overlap:
		res = [i % 2 + 1 for i in range(n)]
		res[-1] = 3
		return (3, res)
	rep = False
	res = []
	for (i, (prev, cur)) in enumerate(zip([crs[-1]] + crs, crs + [crs[0]])):
		if prev == cur:
			rep = True
		res.append((i + rep) % 2 + 1)
	return (2, res[:-1])
t = int(input())
for i in range(1, t + 1):
	n = int(input())
	carousel = [int(s) for s in input().split(' ')]
	(num_colors, ans) = get_color(n, carousel)
	ans = ' '.join(map(str, ans))
	print(f'{num_colors}\n{ans}')


lenN = int(input())
for j in range(lenN):
	n = int(input())
	arr = input().split()
	res = []
	wasPair = False
	lastPos = -1
	colorAmount = 1
	res.append(1)
	for i in range(1, len(arr)):
		if arr[i] != arr[i - 1]:
			if res[i - 1] == 1:
				res.append(2)
				colorAmount = 2
			else:
				res.append(1)
		else:
			wasPair = True
			lastPos = i
			res.append(res[i - 1])
	if arr[len(arr) - 1] != arr[0] and res[len(arr) - 1] == res[0]:
		if not wasPair:
			res[len(arr) - 1] = 3
			colorAmount = 3
		else:
			if res[lastPos - 1] == 1:
				res[lastPos] = 2
			else:
				res[lastPos] = 1
			for i in range(lastPos + 1, len(arr)):
				if arr[i] != arr[i - 1]:
					if res[i - 1] == 1:
						res[i] = 2
					else:
						res[i] = 1
				else:
					res[i] = res[i - 1]
	print(colorAmount)
	print(*res)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(1)
		print(*[1] * n)
	elif n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
	else:
		flag = 1
		v = 0
		ans = [1] * n
		for i in range(1, n):
			if flag and a[i - 1] == a[i]:
				flag = 0
			else:
				v ^= 1
			ans[i] = v + 1
		if flag and a[0] != a[-1]:
			ans[-1] = 3
			print(3)
			print(*ans)
		else:
			print(2)
			print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(1)
		print(*[1] * n)
	elif n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
	elif n % 2 == 1 and all((a[q] != a[q + 1] for q in range(n - 1))) and (a[0] != a[n - 1]):
		print(3)
		print(*[1, 2] * (n // 2), 3)
	else:
		print(2)
		(q1, ans) = (0, [])
		while q1 < n - 1 and a[q1] != a[q1 + 1]:
			ans.append(q1 % 2 + 1)
			q1 += 1
		ans.extend([q1 % 2 + 1] * min(2, n - q1))
		for q in range(q1 + 2, n):
			ans.append(2 - q % 2)
		print(*ans)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
M = 10 ** 9 + 7

def solve():
	N = getInt()
	A = getInts()
	if len(set(A)) == 1:
		ans = [1] * N
		print(1)
	elif N % 2 == 0:
		ans = [1, 2] * (N // 2)
		print(2)
	else:
		flag = False
		for j in range(N):
			if A[j] == A[(j + 1) % N]:
				idx = j
				flag = True
				break
		if flag:
			ans = []
			for i in range(idx):
				ans.append(1 if i % 2 == 0 else 2)
			if idx == 0:
				ans.append(1)
				ans.append(1)
			elif idx < N - 1:
				ans.append(3 - ans[-1])
				ans.append(ans[-1])
			while len(ans) < N:
				ans.append(3 - ans[-1])
			print(2)
		else:
			ans = [1, 2] * (N // 2) + [3]
			print(3)
	print(*ans)
	return
T = getInt()
for t in range(T):
	solve()


def I():
	return list(map(int, input().split()))
for __ in range(int(input())):
	n = int(input())
	x = I()
	f = 0
	t = len(set(x))
	mark = 0
	for i in range(n - 1):
		if x[i] == x[i + 1]:
			mark = i
			f = 1
			break
	if x[0] == x[-1]:
		mark = n - 1
		f = 1
	if t == 1:
		print(1)
		print(*[1] * n)
	else:
		s = []
		if n % 2:
			if f:
				print(2)
				col = 1
				for i in range(n):
					s.append(col)
					if i != mark:
						col = 2 if col == 1 else 1
			else:
				print(3)
				s = [1, 2] * (n // 2) + [3]
		else:
			print(2)
			s = [1, 2] * (n // 2)
		print(*s)


def linput():
	return [int(i) for i in input().split()]
q = int(input())
for ______ in range(q):
	n = int(input())
	k = linput()
	k1 = []
	if len(set(k)) == 1:
		print(1)
		print('1 ' * (n - 1) + '1')
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		i = 1
		while i < n and k[i - 1] != k[i]:
			k1.append(i % 2 + 1)
			i += 1
		if i == n:
			if k[0] == k[-1]:
				k1.append(k1[0])
				print(2)
				print(*k1)
			else:
				k1.append(3)
				print(3)
				print(*k1)
		else:
			k1.append(i % 2 + 1)
			k1.append(k1[-1])
			for l in range(i + 1, n):
				k1.append(k1[-1] % 2 + 1)
			print(2)
			print(*k1)


import sys
input = lambda : sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(a) for a in input().split()]
	if max(A) == min(A):
		print(1)
		print(*[1] * N)
	elif N % 2 == 0:
		print(2)
		print(*[1, 2] * (N // 2))
	else:
		for i in range(N):
			if A[i - 1] == A[i]:
				print(2)
				print(*([1, 2] * N)[:i][::-1] + ([1, 2] * N)[:N - i])
				break
		else:
			print(3)
			print(*[3] + [1, 2] * (N // 2))


q = int(input())
for _ in range(q):
	n = int(input())
	a = input().split()
	color = [1]
	count = 1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			color.append(color[-1])
		elif color[-1] > 1:
			color.append(color[-1] - 1)
		else:
			color.append(2)
			count = 2
	if a[-1] != a[0] and color[-1] == 1:
		count = 3
		color[-1] = 3
	if count == 3:
		color2 = [1]
		count2 = 1
		f = False
		for i in range(1, n):
			if a[i] == a[i - 1] and f:
				color2.append(color2[-1])
			elif color2[-1] > 1:
				color2.append(color2[-1] - 1)
			else:
				color2.append(2)
				count2 = 2
			if a[i] == a[i - 1]:
				f = True
		if a[-1] != a[0] and color2[-1] == 1:
			count2 = 3
			color2[-1] = 3
		if count2 < count:
			print(count2)
			print(*color2)
		else:
			print(count)
			print(*color)
	else:
		print(count)
		print(*color)


from collections import *
for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	ch = 9
	st = set(t)
	if len(st) == 1:
		ch = 1
	if len(t) % 2 == 0:
		ch = min(ch, 2)
	ind = -1
	t.append(t[0])
	for i in range(n):
		if t[i] == t[i + 1] and ch != 2:
			ind = i
			ch = min(ch, 2)
			break
	else:
		ch = min(ch, 3)
	print(ch)
	if ch == 1:
		for i in range(n):
			print(1, end=' ')
		print()
	elif ch == 2 and ind == -1:
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print()
	elif ch == 2 and ind != -1:
		for i in range(ind + 1):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		for i in range(ind + 1, n):
			if i % 2 == 0:
				print(2, end=' ')
			else:
				print(1, end=' ')
		print()
	else:
		for i in range(n - 1):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print(3, end=' ')
		print()


import os
import sys
from io import BytesIO, IOBase

def main():
	t = int(input())
	for xx in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		clrs = []
		col = 2
		if n % 2 == 0:
			clrs = [i % 2 + 1 for i in range(n)]
		else:
			fl = ct = 0
			for i in range(n):
				if a[i] == a[(i + 1) % n]:
					ct = i + 1
					fl = 1
					break
			if fl == 1:
				ed = 0
				for i in range(n):
					if i == ct:
						ed = 1
					k = (i + ed) % 2 + 1
					clrs.append(k)
			else:
				col = 3
				for i in range(n - 1):
					clrs.append(i % 2 + 1)
				clrs.append(3)
		fg = 0
		for i in range(n):
			if a[i] != a[(i + 1) % n]:
				fg += 1
				break
		if fg >= 1:
			ans = ' '.join([str(v) for v in clrs])
			print(col)
		else:
			print(1)
			ans = ' '.join(['1' for i in range(n)])
		print(ans)
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()


def altt(a):
	val = 0
	for i in range(1, len(a)):
		if a[i] != a[i - 1]:
			val += 1
	if a[0] != a[-1]:
		val += 1
	if val == len(a):
		return True
	return False
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if n % 2 == 0:
		if len(list(set(a))) == 1:
			print(1)
			print(*[1] * n)
		else:
			print(2)
			print(*[1, 2] * (n // 2))
	elif len(list(set(a))) == 1:
		print(1)
		print(*[1] * n)
	elif altt(a):
		print(3)
		print(*[1, 2] * (n // 2) + [3])
	else:
		if a[0] == a[-1]:
			print(2)
			print(*[1, 2] * (n // 2) + [1])
			continue
		idx = -1
		for i in range(1, n):
			if a[i] == a[i - 1]:
				idx = i - 1
				break
		fl = 1
		arrr = []
		for i in range(n):
			if i == idx + 1:
				arrr.append(3 - fl)
			else:
				arrr.append(fl)
				fl = 3 - fl
		print(2)
		print(*arrr)


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		c = [1] * n
	elif n % 2 == 0:
		c = [1, 2] * (n // 2)
	else:
		try:
			s = next((i for i in range(n) if t[i] == t[(i + 1) % n])) + 1
			c = [1, 2] * (s // 2) + [2 if s % 2 == 0 else 1] + [1, 2] * ((n - s) // 2)
		except StopIteration:
			c = [1, 2] * (n // 2) + [3]
	print(max(c))
	print(' '.join(('{}'.format(x) for x in c)))


from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

def li():
	return list(mi())

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		if len(set(a)) == 1:
			print('1')
			x = '1' * n
			x = list(x)
			print(*x)
		else:
			ans = []
			ans.append(1)
			f = 1
			f1 = 0
			for i in range(1, n - 1):
				if a[i] != a[i - 1]:
					if f == 1:
						f = 2
					else:
						f = 1
				else:
					f1 = 1
				ans.append(f)
			if f1 and f == 2:
				ans = []
				ans.append(1)
				f = 1
				for i in range(1, n - 1):
					if f1 or a[i] != a[i - 1]:
						if f == 1:
							f = 2
						else:
							f = 1
						if a[i] == a[i - 1]:
							f1 = 0
					ans.append(f)
			if a[n - 2] != a[n - 1]:
				if f == 1:
					ans.append(2)
				elif a[0] != a[n - 1]:
					ans.append(3)
				else:
					ans.append(1)
			else:
				ans.append(2)
			print(len(set(ans)))
			print(*ans)
main()


q = int(input())
for test_case in range(q):
	n = int(input())
	t = input().split()
	if n == 1:
		print(1)
		print(1)
		continue
	t_0 = t[0]
	all_same = True
	any_adj_same = False
	adj_same_index = -1
	for i in range(0, len(t)):
		animal = t[i]
		if animal != t_0:
			all_same = False
		if animal == t[(i + 1) % n]:
			any_adj_same = True
			adj_same_index = i
	if all_same:
		print(1)
		output = ''
		for i in range(n):
			output += ' 1'
		output = output[1:]
		print(output)
		continue
	if n % 2 == 0:
		print(2)
		output = ''
		for i in range(n):
			output += ' 1' if i % 2 == 0 else ' 2'
		output = output[1:]
		print(output)
		continue
	if any_adj_same:
		print(2)
		output = ''
		for i in range(n):
			if i > adj_same_index:
				output += ' 2' if i % 2 == 0 else ' 1'
			else:
				output += ' 1' if i % 2 == 0 else ' 2'
		output = output[1:]
		print(output)
		continue
	else:
		print(3)
		output = ''
		for i in range(n - 1):
			output += '1 ' if i % 2 == 0 else '2 '
		output += '3'
		print(output)
		continue


q = int(input())
for i in range(q):
	n = int(input())
	ti = list(map(int, input().split()))
	ci = [0] * n
	ci[0] = 1
	num = -1
	for i in range(1, n - 1):
		if ti[i] == ti[i - 1]:
			ci[i] = ci[i - 1]
			num = i
		else:
			ci[i] = 3 - ci[i - 1]
	if n > 2 and ti[-1] != ti[0] and (ti[-2] != ti[-1]):
		if ci[-2] != ci[0]:
			if num == -1:
				ci[-1] = 3
			else:
				for i in range(num, n):
					ci[i] = 3 - ci[i - 1]
		else:
			ci[-1] = 3 - ci[0]
	elif ti[-1] != ti[0]:
		ci[-1] = 3 - ci[0]
	elif ti[-2] != ti[-1]:
		ci[-1] = 3 - ci[-2]
	else:
		ci[-1] = ci[0]
	print(max(ci))
	print(' '.join(list(map(str, ci))))


q = int(input())
for i in range(q):
	n = int(input())
	ch = input()
	L = [int(i) for i in ch.split()]
	if L == [L[0]] * n:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		test = 0
		x = '1 '
		y = '2 '
		s = '1 '
		c = x
		for j in range(1, n):
			if test == 0 and L[j] == L[j - 1]:
				test = 1
			elif c == x:
				c = y
			else:
				c = x
			s += c
		if test or L[0] == L[-1]:
			print(2)
			print(s)
		else:
			print(3)
			print(s[0:2 * n - 2] + '3 ')


t = int(input())
for x in range(t):
	n = int(input())
	if n == 0:
		continue
	numbers = list(map(int, input().split()))
	all_same = 1
	a_pair = -1
	thing = numbers[0]
	for i in range(n):
		if numbers[i] != thing:
			all_same = 0
		if numbers[i] == numbers[(i + 1) % n]:
			a_pair = i
	if all_same:
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()
	elif n % 2 == 0:
		print(2)
		a = 0
		for i in range(n):
			print(a + 1, end=' ')
			a = 1 - a
		print()
	elif a_pair != -1:
		print(2)
		a = 0
		for i in range(n):
			print(a + 1, end=' ')
			if i != a_pair:
				a = 1 - a
		print()
	else:
		print(3)
		a = 0
		for i in range(n - 1):
			print(a + 1, end=' ')
			a = 1 - a
		print(3, end='')
		print()


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	t = inputlist()
	k = [1] * n
	a = sorted(t)
	if a[0] == a[n - 1]:
		print(1)
		print(*k)
		continue
	for i in range(n):
		if i % 2 == 1:
			k[i] = 2
	if n % 2 == 0:
		print(2)
		print(*k)
	elif t[n - 1] != t[n - 2] and t[n - 1] != t[0]:
		good = False
		for j in range(1, n):
			if not good and t[j] == t[j - 1]:
				good = True
			if good:
				if k[j] == 1:
					k[j] = 2
				else:
					k[j] = 1
		if good:
			print(2)
			print(*k)
		else:
			k[n - 1] = 3
			print(3)
			print(*k)
	elif t[n - 1] != t[0]:
		k[n - 1] = 2
		print(2)
		print(*k)
	else:
		print(2)
		print(*k)


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	a = []
	if min(b) == max(b):
		a = [1] * n
		print(1)
		print(*a)
	elif n % 2 == 0:
		for j in range(n):
			if j % 2 == 0:
				a.append(1)
			else:
				a.append(2)
		print(2)
		print(*a)
	else:
		a = []
		t = 0
		for j in range(n):
			if b[j - 1] == b[j]:
				t = 1
				break
		if t == 0:
			for j in range(n - 1):
				if j % 2 == 0:
					a.append(1)
				else:
					a.append(2)
			a.append(3)
			print(3)
			print(*a)
		elif b[-1] == b[0]:
			for j in range(n):
				if j % 2 == 0:
					a.append(1)
				else:
					a.append(2)
			print(2)
			print(*a)
		else:
			j = 0
			h = 0
			while j < n:
				if j < n - 1 and b[j + 1] == b[j] and (h == 0):
					if j % 2 == 0:
						a.append(1)
						a.append(1)
					else:
						a.append(2)
						a.append(2)
					h = 1
					j += 2
				elif h == 0:
					if j % 2 == 0:
						a.append(1)
					else:
						a.append(2)
					j += 1
				else:
					if j % 2 == 0:
						a.append(2)
					else:
						a.append(1)
					j += 1
			print(2)
			print(*a)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	if max(a) == min(a):
		print(1)
		ans = [1 for x in range(n)]
		print(*ans)
	elif n % 2 == 0:
		print(2)
		ans = [x % 2 + 1 for x in range(n)]
		print(*ans)
	else:
		ans = []
		k = 3
		cur = 1
		yes = 0
		for i in range(n):
			if a[i] == a[i - 1] and yes == 0:
				print(2)
				ans.append(cur)
				yes = 1
			else:
				cur = cur % 2 + 1
				ans.append(cur)
		if yes == 0:
			print(3)
			ans[-1] = 3
			print(*ans)
		else:
			print(*ans)


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		mx = 1
		if n == 1:
			stdout.write('1\n1\n')
			continue
		decide = [0] * n
		for (i, x) in enumerate(arr):
			if decide[i] != 0:
				continue
			j = (i + 1) % n
			decide[i] = 1
			while arr[j] != arr[j - 1] and decide[j] == 0:
				mx = 2
				decide[j] = (decide[j - 1] + 1) % 3
				if decide[j] == 0:
					decide[j] = 1
				j += 1
				j %= n
			if j - 1 < 0:
				j = n
			if i == 0 and j == n and (arr[n - 1] != arr[0]) and (n % 2 == 1):
				mx = 3
				decide[n - 1] = 3
				break
			j = i - 1
			if j < 0:
				j = n - 1
			while arr[j] != arr[(j + 1) % n] and decide[j] == 0:
				mx = 2
				decide[j] = (decide[(j + 1) % n] + 1) % 3
				if decide[j] == 0:
					decide[j] = 1
				j -= 1
				if j < 0:
					j = n - 1
		stdout.write(str(mx) + '\n')
		stdout.write(' '.join((str(x) for x in decide)) + '\n')
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = len(set(l))
	if c == 1:
		print(1)
		print('1 ' * n)
		continue
	if n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
		continue
	if n % 2 == 1 and l[-1] == l[0]:
		print(2)
		print('1 2 ' * (n // 2), end='')
		print('1')
		continue
	prev = l[0]
	flag = False
	for i in range(1, n):
		if prev == l[i]:
			flag = True
			ind = i
			break
		prev = l[i]
	if flag == True:
		print(2)
		arr = [0] * n
		var = 1
		for term in range(n):
			if term == ind:
				arr[term] = arr[term - 1]
			elif var == 1:
				arr[term] = 1
				var = 2
			else:
				arr[term] = 2
				var = 1
		print(*arr, sep=' ')
	else:
		var = 1
		print(3)
		print('1 2 ' * (n // 2), end='')
		print('3')
		print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(arr[0]) == n:
		print(1)
		print(*[1] * n)
	elif n & 1:
		found = False
		prev = arr[0]
		i = 1
		ans = [1]
		while i < n:
			if prev == arr[i]:
				found = True
				ans.append(ans[-1])
				break
			else:
				ans.append(1 if ans[-1] == 2 else 2)
			prev = arr[i]
			i += 1
		while len(ans) < n:
			ans.append(1 if ans[-1] == 2 else 2)
		if not found:
			ans[-1] = 3
			if arr[-1] == arr[0]:
				found = True
				ans[-1] = ans[0]
		print(2 if found else 3)
		print(*ans)
	else:
		print(2)
		print(*[1, 2] * (n // 2))


from sys import stdin
import math
a = int(stdin.readline())
for k in range(0, a):
	b = int(stdin.readline())
	A = stdin.readline().split()
	temp = 1
	ans2 = '1 '
	if b == 1:
		print(1)
		print(1)
		continue
	B = A[:min(100, len(A))]
	if len(set(B)) == 1:
		if len(set(A)) == 1:
			print(1)
			for u in range(0, b):
				if u == b - 1:
					print(1)
				else:
					print(1, end=' ')
		continue
	if b % 2 == 0 or (b % 2 == 1 and A[0] == A[b - 1]):
		print(2)
		print(1, end=' ')
		for k in range(0, int(math.floor((b - 1) / 2))):
			print(2, end=' ')
			print(1, end=' ')
		if b % 2 == 0:
			print(2)
	else:
		K = 0
		for j in range(1, b):
			if A[j] == A[j - 1]:
				K = 1
				break
		if K == 0:
			print(3)
		else:
			print(2)
		KK = 0
		print(1, end=' ')
		for k in range(1, b - 1):
			if A[k] == A[k - 1] and KK == 0:
				KK = 1
				print(str(temp), end=' ')
			else:
				if temp == 1:
					temp = 2
				else:
					temp = 1
				print(str(temp), end=' ')
		if KK == 0:
			if A[b - 1] == A[b - 2]:
				print(str(temp))
			else:
				print(3)
		else:
			if temp == 1:
				temp = 2
			else:
				temp = 1
			print(str(temp))


t = int(input())
for _ in range(t):
	n = int(input())
	items = list(map(int, input().split()))
	if len(set(items)) == 1:
		res = '1 ' * n
		print(1)
		print(res)
	elif n % 2 == 0:
		res = '1 2 ' * (n // 2)
		print(2)
		print(res)
	else:
		res = []
		flag = 0
		items.append(items[0])
		index = 0
		for i in range(n):
			if items[i] == items[i + 1]:
				flag = 1
				index = i
		if flag == 0:
			print(3)
			res = '1 2 ' * (n // 2) + '3'
			print(res)
		else:
			print(2)
			if index == n - 1:
				res = '1 2 ' * (index // 2) + '1'
				print(res)
			else:
				if index % 2 == 0:
					res = '1 2 ' * ((index + 1) // 2) + '1 1 '
					res = res + '2 1 ' * ((n - index - 2) // 2) + '2'
				else:
					res = '1 2 ' * ((index + 1) // 2) + '2 '
					res = res + '1 2 ' * ((n - index - 2) // 2)
				print(res)


T = int(input())
for _ in range(0, T):
	n = int(input())
	s = [int(x) for x in input().split()]
	ans = [1] * n
	if len(set(s)) == 1:
		print(1)
		print(*ans)
	elif len(s) % 2 == 0:
		for i in range(0, len(s)):
			if i % 2 != 0:
				ans[i] = 2
		print(2)
		print(*ans)
	elif s[-1] == s[0]:
		for i in range(0, len(s)):
			if i % 2 != 0:
				ans[i] = 2
		print(2)
		print(*ans)
	else:
		temp = -1
		for i in range(1, len(s)):
			if s[i] == s[i - 1]:
				temp = i
				break
		if temp == -1:
			ans[0] = 0
			c = 1
			for i in range(1, len(s)):
				if s[i] == s[i - 1]:
					ans[i] = ans[i - 1]
				else:
					ans[i] = c
					c = (c + 1) % 2
			for i in range(0, len(ans)):
				ans[i] += 1
			if ans[-1] == ans[0]:
				ans[-1] = 3
				print(3)
				print(*ans)
			else:
				print(2)
				print(*ans)
		else:
			ans[0] = 0
			c = 1
			for i in range(1, len(s)):
				if s[i] == s[i - 1]:
					ans[i] = ans[i - 1]
				else:
					ans[i] = c
					c = (c + 1) % 2
			for i in range(0, len(ans)):
				ans[i] += 1
			if ans[-1] == ans[0]:
				ans[0] = 0
				c = 1
				for i in range(1, len(s)):
					if s[i] == s[i - 1]:
						if i == temp:
							ans[i] = c
							c = (c + 1) % 2
						else:
							ans[i] = ans[i - 1]
					else:
						ans[i] = c
						c = (c + 1) % 2
				for i in range(0, len(ans)):
					ans[i] += 1
				if ans[-1] == ans[0]:
					ans[-1] = 3
					print(3)
					print(*ans)
				else:
					print(2)
					print(*ans)
			else:
				print(2)
				print(*ans)


import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
	f = iter(open('D.txt').readlines())

	def input():
		return next(f).strip()
else:
	input = lambda : sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
t = int(input())
for _ in range(t):
	n = int(input())
	T = list(map(int, input().split()))
	s = set(T)
	if len(s) == 1:
		res = [1 for _ in range(n)]
	elif all([u != v for (u, v) in zip(T, T[1:])]) and T[0] != T[-1] and (n % 2 != 0):
		res = [i % 2 + 1 for i in range(n)]
		res[-1] = 3
	else:
		res = [1]
		free = -1
		for (num, (u, v)) in enumerate(zip(T[:], T[1:])):
			if u != v:
				res.append(res[-1] % 2 + 1)
			else:
				free = num
				res.append(res[-1])
		if T[0] != T[-1] and res[0] == res[-1]:
			for j in range(free + 1, n):
				res[j] = res[j] % 2 + 1
	print(len(set(res)))
	print(' '.join(map(str, res)))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = -1
	arr = []
	s = set()
	for j in l:
		s.add(j)
	if len(s) == 1:
		ans = 1
		for j in range(n):
			arr.append(1)
	elif n % 2 == 0:
		ans = 2
		for j in range(n // 2):
			arr.append(1)
			arr.append(2)
	else:
		ind = -1
		ans = 3
		for j in range(n - 1):
			if l[j] == l[j + 1]:
				ind = j + 1
				ans = 2
				break
		arr = [1]
		if ind == -1:
			j = 0
			for j in range(n - 2):
				arr.append((j + 1) % 2 + 1)
			if l[0] == l[n - 1]:
				ans = 2
				arr.append(1)
			else:
				arr.append(3)
		else:
			ans = 2
			for j in range(1, n):
				if j == ind:
					arr.append(arr[-1])
				elif arr[-1] == 1:
					arr.append(2)
				else:
					arr.append(1)
	print(ans)
	for j in range(n):
		print(arr[j], end=' ')
	print()


from sys import stdin, stdout
q = int(stdin.readline().strip())
for _ in range(q):
	n = int(stdin.readline().strip())
	t = list(map(int, stdin.readline().split()))
	cons = -1
	types = set()
	for i in range(n):
		types.add(t[i])
		if t[i] == t[i - 1]:
			cons = i
	if len(types) == 1:
		stdout.write('1\n{}\n'.format(' '.join(['1' for _ in range(n)])))
	elif n % 2 == 0:
		stdout.write('2\n{}\n'.format(' '.join([['1', '2'][i % 2] for i in range(n)])))
	elif cons != -1:
		a = []
		b = False
		c = ['1', '2']
		for i in range(n):
			if i != cons:
				b = not b
			a.append(c[b])
		stdout.write('2\n{}\n'.format(' '.join(a)))
	else:
		a = [['1', '2'][i % 2] for i in range(n)]
		a[-1] = '3'
		stdout.write('3\n{}\n'.format(' '.join(a)))


testCase = int(input())
for i1 in range(testCase):
	length = int(input())
	sequence = list(map(int, input().split()))
	i2 = 0
	section = []
	temp = sequence[0]
	while i2 < length:
		start = i2
		while i2 < length and sequence[i2] == temp:
			i2 += 1
		end = i2
		if i2 != length:
			temp = sequence[i2]
		section.append(end - start)
	twoFound = False
	indexTwo = 0
	for i2 in range(len(section)):
		if section[i2] > 1:
			twoFound = True
			indexTwo = i2
			break
	if len(section) == 1:
		print(1)
		print(length * '1 ')
	elif sequence[0] == sequence[-1]:
		if length % 2 == 0:
			print(2)
			print(length // 2 * '1 2 ')
		else:
			print(2)
			print(length // 2 * '1 2 ' + '1 ')
	elif length % 2 == 0:
		print(2)
		print(length // 2 * '1 2 ')
	elif twoFound:
		print(2)
		colourIndex = '1 '
		for i3 in range(length - 1):
			if i3 == indexTwo:
				print(colourIndex * 2, end='')
			else:
				print(colourIndex, end='')
			if colourIndex == '1 ':
				colourIndex = '2 '
			else:
				colourIndex = '1 '
		print('')
	else:
		print(3)
		print(length // 2 * '1 2 ' + '3')


testCases = int(input())
for i in range(testCases):
	n = int(input())
	carouselList = [int(x) for x in input().split()]
	if len(set(carouselList)) == 1:
		print('1')
		print('1 ' * n)
	elif n % 2 == 0:
		print('2')
		for i in range(n):
			print(i % 2 + 1, end=' ')
		print()
	else:
		string = ''
		flag = False
		for i in range(n):
			if carouselList[i] == carouselList[(i + 1) % n]:
				flag = True
				print('2')
				j = 0
				for pos in range(i + 1, n):
					string = string + str(j + 1) + ' '
					j = (j + 1) % 2
				j = 0
				for pos in range(i, -1, -1):
					string = str(j + 1) + ' ' + string
					j = (j + 1) % 2
				print(string)
				break
		if not flag:
			print(3)
			for i in range(0, n - 1):
				print(i % 2 + 1, end=' ')
			print(3, end='\n')


import sys
input = lambda : sys.stdin.readline().strip()
ipnut = input

def main(t=1):
	for i in range(t):
		n = int(input())
		s = list(map(int, ipnut().split()))
		f = False
		for i in range(n):
			if s[i] == s[i - 1]:
				f = True
				break
		if len(set(s)) == 1:
			print(1)
			print('1 ' * n)
		elif s[0] != s[n - 1] and s[n - 2] != s[n - 1] and n % 2:
			if f:
				print(2)
				f = True
				d = []
				ans = [1]
				for i in range(n):
					if s[i] == s[i - 1] and f:
						f = False
						if i:
							ans.append(ans[-1])
						else:
							d.append(1)
					elif i:
						ans.append(ans[-1] % 2 + 1)
				if d:
					print(' '.join(map(str, ans[:-1] + d)))
				else:
					print(' '.join(map(str, ans)))
			else:
				print(3)
				ans = [1]
				for i in range(n - 2):
					ans.append(ans[-1] % 2 + 1)
				ans.append(3)
				print(' '.join(map(str, ans)))
		else:
			print(2)
			if n % 2:
				ans = [1]
				for i in range(1, n - 1):
					ans.append(ans[-1] % 2 + 1)
				if s[n - 1] != s[0]:
					ans.append(2)
				else:
					ans.append(ans[-1] % 2 + 1)
				print(' '.join(map(str, ans)))
			else:
				for i in range(n):
					print(i % 2 + 1, end=' ')
				print()
main(int(input()))


def fun(a):
	global s, d
	a = int(a)
	if len(l) > 0 and a == l[len(l) - 1]:
		l.append(a)
		s = len(l)
	else:
		l.append(a)
		if len(l) > 1:
			d = 1

def fun2(b):
	print(' '.join([str(i % 2 + 1) for i in range(1, b + 1)]), end=' ')
for i in range(int(input())):
	n = int(input())
	s = -1
	d = 0
	l = []
	t = list(map(fun, input().split()))
	if l[0] == l[len(l) - 1]:
		if d == 0:
			print(1)
			print(' '.join(['1' for i in range(1, n + 1)]))
		else:
			print(2)
			fun2(n)
			print('')
	elif n % 2 == 0:
		print(2)
		fun2(n)
		print('')
	elif s != -1:
		print(2)
		fun2(s - 1)
		print(' '.join([str(3 - (i % 2 + 1)) for i in range(s, n + 1)]))
	else:
		print(3)
		fun2(n - 2)
		print('3 1')


import sys
import math
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = 1
	pos = 0
	m = 1
	p = [1]
	for i in range(1, n - 1):
		if a[i] != a[i - 1]:
			if p[i - 1] != 1:
				k = 1
			else:
				k = 2
				m = 2
		else:
			pos = i
		p.append(k)
	if p[-1] == 2 and pos:
		for i in range(pos, n - 1):
			if p[i] == 1:
				p[i] = 2
			else:
				p[i] = 1
	if p[-1] == 2:
		if a[-2] == a[-3]:
			p[-1] = 1
	if p[-1] == p[0]:
		if a[-2] == a[-1] and a[-1] == a[0]:
			p.append(1)
		else:
			p.append(2)
			m = 2
	elif a[-1] == a[-2] and a[-1] == a[0]:
		p.append(1)
	elif a[-1] != a[-2] and a[-1] != a[0]:
		p.append(3)
		m = 3
	elif a[-1] == a[-2]:
		p.append(2)
		m = 2
	else:
		p.append(1)
	print(m)
	print(*p)


t = int(input())
for T in range(t):
	n = int(input())
	types = list(map(int, input().split()))
	cols = n * [1]
	used = 1
	idx_eq = -1
	for i in range(1, n):
		if types[i] == types[i - 1]:
			cols[i] = cols[i - 1]
			idx_eq = i
		else:
			used = 2
			cols[i] = 3 - cols[i - 1]
	if types[n - 1] != types[0] and cols[n - 1] == cols[0]:
		if idx_eq == -1:
			used = 3
			cols[n - 1] = 3
		else:
			for j in range(idx_eq, n):
				cols[j] = 3 - cols[j]
	print(used)
	print(' '.join(map(str, cols)))


q = int(input())
for _ in range(0, q):
	n = int(input())
	animals = list(map(int, input().split()))
	no_dupes = True
	all_same = True
	idx = -1
	for i in range(1, len(animals)):
		if animals[i] == animals[i - 1]:
			no_dupes = False
			idx = i
		else:
			all_same = False
		if animals[i] == animals[(i + 1) % len(animals)]:
			no_dupes = False
			idx = (i + 1) % len(animals)
	if len(animals) % 2 == 1 and no_dupes:
		print(3)
		res = [1 for _ in range(n)]
		for i in range(1, len(animals), 2):
			res[i] = 2
		res[len(animals) - 1] = 3
		print(' '.join(map(str, res)))
	else:
		res = [1 for _ in range(n)]
		if all_same:
			print(1)
			print(' '.join(map(str, res)))
		else:
			for i in range(n):
				res[(i + idx) % n] = 1 if i % 2 else 2
			print(2)
			print(' '.join(map(str, res)))


import sys
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	color = [1 for i in range(n)]
	if len(list(set(arr))) == 1:
		print(1)
		print(*color)
	elif n % 2 == 0:
		for i in range(n):
			if i % 2 == 0:
				color[i] = 1
			else:
				color[i] = 2
		print(2)
		print(*color)
	else:
		f = 0
		for i in range(1, n):
			if f == 0:
				if arr[i] == arr[i - 1]:
					color[i] = color[i - 1]
					f = 1
				else:
					color[i] = 3 - color[i - 1]
			else:
				color[i] = 3 - color[i - 1]
		if f == 0 and arr[i] != arr[0]:
			color[-1] = 3
		print(len(list(set(color))))
		print(*color)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def case():
	n = I()
	a = li()
	ans = []
	if len(set(a)) == 1:
		for i in range(n):
			ans.append(1)
		print(1)
		print(*ans)
	elif n % 2 == 0:
		for i in range(n):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(2)
		print(2)
		print(*ans)
	else:
		for i in range(n):
			j = 1
			if a[i] == a[(i + 1) % n]:
				ans = [0] * n
				for pos in range(i + 1, n):
					ans[pos] = j + 1
					j ^= 1
				j = 1
				for pos in range(i, -1, -1):
					ans[pos] = j + 1
					j ^= 1
				print(len(set(ans)))
				print(*ans)
				return
		print(3)
		for i in range(n - 1):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print(3)
for _ in range(int(input())):
	case()


def solve(t):
	l = len(t)
	if t.count(t[0]) == l:
		print(1)
		print('1 ' * l)
		return
	if l % 2 == 0:
		print(2)
		for i in range(l):
			print(i % 2 + 1, end=' ')
		print()
		return
	res = []
	pr = 1
	flag = True
	for i in range(l - 1):
		if t[i] == t[i + 1] and flag:
			res.append(pr)
			flag = False
		else:
			res.append(pr)
			pr = 2 if pr == 1 else 1
	if t[0] != t[-1] and res[0] == pr:
		res.append(3)
	else:
		res.append(pr)
	if 3 in res:
		print(3)
	elif 2 in res:
		print(2)
	else:
		print(1)
	print(*res)
for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	solve(t)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

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

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	a = array()
	ok = False
	for i in range(n):
		if a[i] == a[i - 1]:
			ok = True
			key = i
	unique = len(set(a))
	need = False
	if a[-1] != a[0] and a[-2] == a[0]:
		need = True
	ans = []
	if n % 2 == 0:
		if unique == 1:
			ans = [1] * n
		else:
			ans = [1, 2] * (n // 2 + 2)
	elif ok:
		if unique == 1:
			ans = [1] * n
		else:
			ans = [1, 2] * (n // 2 + 2)
			ans.insert(key, ans[key - 1])
	else:
		ans = [1, 2] * (n // 2 + 2)
		ans = ans[:n - 1] + [3]
	print(len(set(ans)))
	print(*ans[:n])


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	B = [1]
	k = 1
	flag = 0
	ec = 0
	for i in range(1, n):
		if A[i] == A[i - 1]:
			ec = i
			B.append(B[i - 1])
		else:
			flag = 1
			k = (k + 1) % 3
			k = max(1, k)
			B.append(k)
	if flag == 0:
		print(1)
		print(*B)
	elif A[0] == A[n - 1]:
		print(2)
		print(*B)
	elif B[n - 1] == B[0]:
		if ec == 0:
			print(3)
			B[n - 1] = 3
			print(*B)
		else:
			print(2)
			for i in range(ec, n):
				k = (B[i] + 1) % 3
				k = max(1, k)
				B[i] = k
			print(*B)
	else:
		print(2)
		print(*B)


for i in range(int(input())):
	n = int(input())
	data = list(map(int, input().split()))
	result = ['1']
	if max(data) == min(data):
		print(1)
		print(' '.join(['1' for j in range(n)]))
		continue
	if n % 2 == 0:
		for j in range(1, n):
			result.append('1' if result[j - 1] == '2' else '2')
		print(2)
		print(' '.join(result))
		continue
	if n % 2 == 1:
		flag = True
		for j in range(1, n):
			if flag and data[j] == data[j - 1]:
				result.append(result[j - 1])
				flag = False
			else:
				result.append('1' if result[j - 1] == '2' else '2')
		if flag and data[-2] == data[-1]:
			result[-1] = '1' if result[-1] == '1' else '2'
			print(2)
			print(' '.join(result))
		elif not flag:
			print(2)
			print(' '.join(result))
		elif data[-1] != data[0]:
			result[-1] = '3'
			print(3)
			print(' '.join(result))
		else:
			result[-1] = '1' if result[j - 1] == '2' else '2'
			print(2)
			print(' '.join(result))


q = int(input())
for i in range(q):
	n = int(input())
	arr = list(map(int, input().split()))
	arr_ans = [-1 for j in range(n)]
	flag = False
	if arr[0] != arr[n - 1]:
		for j in range(1, n):
			if arr[j] == arr[j - 1]:
				flag = True
				ind = j
				break
	else:
		flag = True
		ind = 0
	if flag == True:
		flag1 = False
		arr_ans[ind] = '1'
		for j in range(ind + 1, ind + n):
			j = j % n
			if arr[j] != arr[(j - 1) % n]:
				if arr_ans[(j - 1) % n] == '1':
					arr_ans[j] = '2'
					flag1 = True
				else:
					arr_ans[j] = '1'
			else:
				arr_ans[j] = arr_ans[(j - 1) % n]
		ans = ' '.join(arr_ans)
		if flag1 == True:
			print(2)
		else:
			print(1)
		print(ans)
	else:
		flag1 = False
		flag2 = False
		arr_ans[0] = '1'
		for j in range(1, n - 1):
			if arr[j] != arr[(j - 1) % n]:
				if arr_ans[(j - 1) % n] == '1':
					arr_ans[j] = '2'
					flag1 = True
				else:
					arr_ans[j] = '1'
			else:
				arr_ans[j] = arr_ans[(j - 1) % n]
		if n % 2 == 0:
			arr_ans[n - 1] = '2'
			print(2)
		else:
			arr_ans[n - 1] = '3'
			print(3)
		ans = ' '.join(arr_ans)
		print(ans)


t = int(input())
for _ in range(t):
	N = int(input())
	A = [int(a) for a in input().split()]
	if max(A) == min(A):
		print(1)
		print(*[1] * N)
	elif N % 2 == 0:
		print(2)
		print(*[1, 2] * (N // 2))
	else:
		for i in range(N):
			if A[i - 1] == A[i]:
				print(2)
				print(*([1, 2] * N)[:i][::-1] + ([1, 2] * N)[:N - i])
				break
		else:
			print(3)
			print(*[3] + [1, 2] * (N // 2))


import sys
input = sys.stdin.readline
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ok = 0
	sinish = 1
	for j in range(1, n):
		if a[j] == a[j - 1]:
			ok = 1
		else:
			sinish += 1
	if sinish == 1:
		print(1)
		for j in range(n):
			print(1, end=' ')
		print()
		continue
	if a[0] == a[len(a) - 1] or sinish % 2 == 0:
		print(2)
		last = -1
		tosc = 1
		for j in a:
			if j != last:
				last = j
				tosc ^= 1
			print(tosc + 1, end=' ')
		print()
		continue
	if ok:
		done = 0
		print(2)
		last = -1
		tosc = 1
		for j in a:
			if j != last:
				tosc ^= 1
				last = j
			elif not done:
				done = 1
				tosc ^= 1
			print(tosc + 1, end=' ')
		print()
	else:
		print(3)
		last = -1
		tosc = 1
		for j in range(n - 1):
			if a[j] != last:
				tosc ^= 1
				last = a[j]
			print(tosc + 1, end=' ')
		print(3)


def main():
	result = str()
	for _ in range(int(input())):
		n = int(input())
		c = list(map(int, input().split()))
		if len(set(c)) == 1:
			result += '1\n'
			result += f"{' '.join(['1'] * n)}\n"
		elif n % 2 == 0:
			result += '2\n'
			result += f"{' '.join(['2', '1'] * (n // 2))}\n"
		else:
			is_use_duble = bool()
			for i in range(n):
				if c[i] == c[(i + 1) % n]:
					ans = ['1']
					for i in range(1, n):
						if c[i] == c[i - 1] and (not is_use_duble):
							ans.append(ans[i - 1])
							is_use_duble = True
						elif ans[i - 1] == '1':
							ans.append('2')
						else:
							ans.append('1')
					result += '2\n'
					result += f"{' '.join(ans)}\n"
					break
			else:
				result += f'3\n'
				new_list = (['1', '2'] * n)[:n - 3]
				new_list += ['1', '2', '3']
				result += f"{' '.join(new_list)}\n"
	print(result.strip())
main()


q = int(input())
for _ in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	t_set = set(t)
	if len(t_set) == 1:
		print(1)
		print(*[1] * n)
		continue
	if n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
		continue
	found = -1
	for (i, (t1, t2)) in enumerate(zip(t, t[1:] + [t[0]])):
		if t1 == t2:
			found = (i + 1) % n
	if found >= 0:
		print(2)
		r = []
		one = True
		for i in range(n):
			if i == found:
				one = not one
			if one:
				r += [1]
			else:
				r += [2]
			one = not one
		print(*r)
		continue
	print(3)
	r = [1, 2] * (n // 2) + [3]
	print(*r)


num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()
from collections import deque
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	if len(set(s)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		ans = []
		k = f = 1
		for i in range(n):
			i1 = (i - 1) % n
			if f and s[i] == s[(i - 1) % n]:
				ans.append(3 - k)
				f = 0
			else:
				ans.append(k)
				k = 3 - k
		if f:
			print(3)
			print('1 2 ' * (n // 2) + '3')
			continue
		else:
			print(2)
			print(*ans)


for h in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	t = 2
	ans = ['1' if i % 2 == 0 else '2' for i in range(n)]
	if len(set(arr)) == 1:
		print(1)
		print(*['1' for i in range(n)])
	elif ans[-1] != ans[0] or arr[0] == arr[-1]:
		print(t)
		print(*ans)
	else:
		temp = []
		flag = False
		for i in range(n - 1):
			if i % 2 == 0:
				temp.append('1')
			else:
				temp.append('2')
			if arr[i] == arr[i + 1]:
				flag = True
				break
		else:
			t += 1
			ans[-1] = '3'
			print(t)
			print(*ans)
			continue
		for i in range(len(temp), n):
			if i % 2 == 0:
				temp.append('2')
			else:
				temp.append('1')
		print(t)
		print(*temp)


from collections import defaultdict

def arrinp():
	return [*map(int, input().split(' '))]

def mulinp():
	return map(int, input().split(' '))

def intinp():
	return int(input())

def solution():
	n = intinp()
	a = arrinp()
	if len(set(a)) == 1:
		a = [1] * n
		print(1)
		print(*a)
		return
	arr = [1 if x % 2 == 0 else 2 for x in range(n)]
	if n % 2 != 0 and a[0] != a[-1]:
		for j in range(1, n):
			if a[j] == a[j - 1]:
				arr[j] = arr[j - 1]
				for k in range(j + 1, n):
					arr[k] = 3 - arr[k - 1]
				break
		else:
			arr[-1] = 3
	print(max(arr))
	print(*arr)
testcases = 1
testcases = int(input())
for _ in range(testcases):
	solution()


def f(a):
	n = len(a)
	if len(set(a)) == 1:
		print(1)
		return [1] * len(a)
	ans = [None] * len(a)
	if n % 2 == 0:
		print(2)
		for i in range(n):
			print(i % 2 + 1, end=' ')
		return ''
	for i in range(len(a)):
		if a[i] == a[(i + 1) % n]:
			print(2)
			j = 0
			for pos in range(i + 1, n):
				ans[pos] = j + 1
				j ^= 1
			j = 0
			for pos in range(i, -1, -1):
				ans[pos] = j + 1
				j ^= 1
			return ans
	print(3)
	j = 0
	for i in range(n):
		ans[i] = j + 1
		j ^= 1
	ans[-1] = 3
	return ans
for i in range(int(input())):
	n = input()
	a = list(map(int, input().strip().split()))
	print(*f(a))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	k = a[0]
	p = a.count(k)
	if p == n:
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()
	else:
		for i in range(1, n):
			if a[i] == a[i - 1]:
				l += 1
				break
		if l == 0:
			if a[0] == a[n - 1]:
				p = 0
				print(2)
				for i in range(n):
					if p == 0:
						print(1, end=' ')
						p = 1
						continue
					else:
						print(2, end=' ')
						p = 0
				print()
			elif n % 2 == 0:
				p = 0
				print(2)
				for i in range(n):
					if p == 0:
						print(1, end=' ')
						p = 1
						continue
					else:
						print(2, end=' ')
						p = 0
				print()
			else:
				print(3)
				p = 0
				for i in range(n - 1):
					if p == 0:
						print(1, end=' ')
						p = 1
						continue
					else:
						print(2, end=' ')
						p = 0
				print(3, end=' ')
				print()
		else:
			(c, d) = ([1], [1])
			i = 1
			while i < n:
				if a[i] == a[i - 1]:
					c.append(1)
					d.append(2)
					break
				elif c[i - 1] == 1:
					c.append(2)
					d.append(2)
				else:
					c.append(1)
					d.append(1)
				i += 1
			j = i + 1
			p = 0
			while j < n:
				if p == 0:
					c.append(2)
					d.append(1)
					p = 1
					j += 1
					continue
				else:
					c.append(1)
					d.append(2)
					p = 0
					j += 1
			if a[0] == a[n - 1]:
				print(2)
				print(*c)
			elif c[n - 1] == 1:
				print(2)
				print(*d)
			else:
				print(2)
				print(*c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set(a)
	if len(s) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		m = n
		for i in range(n):
			if a[i] == a[(i + 1) % n]:
				m -= 1
				break
		if m % 2 == 0:
			print(2)
			ans = [1]
			k = 1
			f = 1
			for i in range(1, n):
				if a[i] == a[i - 1] and f:
					ans.append(k)
					f = 0
				else:
					k = k % 2 + 1
					ans.append(k)
			print(*ans)
		else:
			print(3)
			print('1 2 ' * (n // 2) + '3')


import collections, heapq, itertools, math, functools
groupby = itertools.groupby
rs = lambda : input()
ri = lambda : int(input())
rm = lambda : map(int, input().split())
rai = lambda : [int(x) for x in input().split()]

def solve():
	if a.count(a[0]) == n:
		print(1)
		print('1 ' * n)
		return
	if n % 2 == 0:
		print(2)
		for i in range(n):
			print(str(i % 2 + 1), end=' ')
		return
	index = 0
	for i in range(n):
		if a[i] == a[(i + 1) % n]:
			ans = [0 for i in range(n)]
			j = 0
			for pos in range(i + 1, n):
				ans[pos] = j + 1
				j ^= 1
			j = 0
			for pos in range(i, -1, -1):
				ans[pos] = j + 1
				j ^= 1
			print(2)
			print(*ans)
			return
	print(3)
	for i in range(n - 1):
		print(str(i % 2 + 1), end=' ')
	print(3)
	return
for t in range(ri()):
	n = ri()
	a = rai()
	solve()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	col = [1]
	a = -1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			a = i - 1
			col.append(col[-1])
		else:
			col.append(col[-1] ^ 3)
	if col[0] == col[-1] and arr[0] != arr[-1]:
		if a != -1:
			for j in range(a + 1, n):
				col[j] ^= 3
			print(2)
			print(*col)
		else:
			col.pop()
			col.append(3)
			print(3)
			print(*col)
	else:
		print(len(set(col)))
		print(*col)


n = int(input())
for i in range(n):
	n = int(input())
	lst = list(map(int, input().split()))
	out = [0] * n
	now = 1
	last = 1
	row = -1
	out[0] = now
	for i in range(1, n):
		if lst[i] != lst[i - 1]:
			now = now % 2 + 1
			out[i] = now
			last = 2
		else:
			row = i
			out[i] = now
	if n > 1 and lst[n - 1] != lst[0] and (out[n - 1] == out[0]):
		if row == -1:
			out[n - 1] = 3
			last = 3
		else:
			out[row] = out[row] % 2 + 1
			now = out[row]
			for i in range(row, n):
				if lst[i] != lst[i - 1]:
					now = now % 2 + 1
					out[i] = now
					last = 2
				else:
					row = i
					out[i] = now
	if n > 1 and out[n - 1] == out[0] and (lst[n - 1] != lst[0]):
		last = 3
		out[n - 1] = 3
	print(last)
	print(*out)


import sys
from operator import xor

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

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

def input():
	return sys.stdin.readline().strip()
import bisect
for _ in range(int(input())):
	N = int(input())
	A = alele()
	f = len(set(A))
	if f == 1:
		print(1)
		z = [1] * N
		print(*z)
	elif N % 2 == 0:
		if f == 1:
			print(1)
			z = [1] * N
			print(*z)
		else:
			print(2)
			z = [1, 2] * (N // 2)
			print(*z)
	elif A[-1] == A[0]:
		print(2)
		z = [1, 2] * (N // 2) + [1]
		print(*z)
	else:
		flag = 0
		for i in range(len(A) - 1):
			if A[i] == A[i + 1]:
				x = i
				flag = 1
				break
		z = [1, 2] * (N // 2)
		if flag == 1:
			print(2)
			z.append(1)
			for j in range(x + 1, len(z)):
				if z[j] == 1:
					z[j] = 2
				else:
					z[j] = 1
			print(*z)
		else:
			print(3)
			z.append(3)
			print(*z)


import math
t = int(input())
for kl in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	z = 0
	res = ''
	j = 0
	deff = 0
	if a[0] == a[-1]:
		z += 1
		ind = 0
	for i in range(1, n):
		if a[i] == a[i - 1]:
			z += 1
			ind = i
	if z == n:
		deff = 1
		print(1)
		print('1 ' * n)
	elif z == 0 and n % 2 == 1:
		print(3)
		for i in range(n // 2):
			res += '1 '
			res += '2 '
		res += '3'
	elif z == 0 and n % 2 == 0:
		print(2)
		for i in range(n // 2):
			res += '1 '
			res += '2 '
	elif z >= 1 and n % 2 == 0:
		print(2)
		for i in range(n // 2):
			res += '1 '
			res += '2 '
	elif z >= 1 and n % 2 == 1:
		print(2)
		for i in range(ind // 2):
			res += '1 '
			res += '2 '
			j += 2
		if ind % 2 == 0:
			res += '2 '
			j += 1
			for i in range((n - j) // 2):
				res += '1 '
				res += '2 '
		else:
			res += '1 '
			res += '1 '
			j += 2
			for i in range(n - j):
				if i % 2 == 0:
					res += '2 '
				else:
					res += '1 '
	if deff == 0:
		print(res)


from collections import defaultdict
from heapq import heappop, heappush, heapify
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	if len(set(l)) == 1:
		print(1)
		print(*[1] * n)
		continue
	if n == 2:
		print(2)
		print(*[1, 2])
		continue
	elif n % 2 == 0:
		ans = []
		print(2)
		for i in range(n):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(2)
	elif l[0] == l[-1]:
		ans = []
		print(2)
		for i in range(n):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(2)
	else:
		ans = [0] * n
		flag = -1
		for i in range(n - 1):
			if l[i] == l[i + 1]:
				flag = i
				break
		if flag == -1:
			print(3)
			ans = []
			for i in range(n):
				k = i % 2
				if k == 0:
					ans.append(1)
				elif k == 1:
					ans.append(2)
			ans[-1] = 3
		else:
			print(2)
			ans = []
			for i in range(flag + 1):
				k = i % 2
				if k == 0:
					ans.append(1)
				elif k == 1:
					ans.append(2)
			if (flag + 1) % 2 == 0:
				cnt = 0
				for i in range(flag + 1, n):
					if cnt % 2 == 0:
						ans.append(2)
					elif cnt % 2 == 1:
						ans.append(1)
					cnt += 1
			else:
				cnt = 0
				for i in range(flag + 1, n):
					if cnt % 2 == 0:
						ans.append(1)
					elif cnt % 2 == 1:
						ans.append(2)
					cnt += 1
	print(*ans)


import sys
inp = sys.stdin.readline

def input():
	return inp().strip()

def iin():
	return int(input())

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

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		a = lin()

		def work(a):
			sol = -1
			ans = []
			if len(set(a)) == 1:
				sol = 1
				ans = [1] * n
			elif n % 2 == 0:
				sol = 2
				ans = [1, 2] * (n // 2)
			else:
				ans = [1, 2] * (n // 2)
				for i in range(n - 1):
					if a[i] == a[i + 1]:
						sol = 2
						ans = ans[:i + 1] + ans[i:]
						break
				else:
					sol = 3
					ans = ans + [3]
			return (sol, ans)
		(s1, a1) = work(a)
		(s2, a2) = work(a[1:] + a[:1])
		a2 = a2[-1:] + a2[:-1]
		if s1 > s2:
			(s1, a1) = (s2, a2)
		print(s1)
		print(*a1)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if len(set(l)) == 1:
		print(1)
		print('1 ' * len(l))
	else:
		k = []
		c = 0
		for j in range(n - 1):
			if l[j] != l[j + 1]:
				k.append(j + 1 - c)
				c = j + 1
		k.append(j + 2 - c)
		res = ''
		c = 0
		if n % 2 == 0:
			print(2)
			print('1 2 ' * (n // 2))
		elif len(k) % 2 == 0:
			res = ''
			for r in range(len(k)):
				if r % 2 == 1:
					res += '1 ' * k[r]
				else:
					res += '2 ' * k[r]
			print(2)
			print(res)
		else:
			count = 0
			for j in range(len(k)):
				if j == 0:
					if k[j] > 1:
						res += '1' + ' 2' * (k[j] - 1)
						count = 1
					else:
						res += '1'
				elif count == 0:
					if k[j] > 1:
						if res[-1] == '1':
							res += ' 2' + ' 1' * (k[j] - 1)
						else:
							res += ' 1' + ' 2' * (k[j] - 1)
						count = 1
					elif res[-1] == '1':
						res += ' 2'
					else:
						res += ' 1'
				elif res[-1] == '1':
					res += ' 2' * k[j]
				else:
					res += ' 1' * k[j]
			if count == 0 and l[0] != l[-1]:
				print(3)
				print(res[:len(res) - 1] + '3')
			else:
				print(2)
				print(res)


from collections import defaultdict as d
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			print(i % 2 + 1, '', end='')
		print()
	else:
		b = 0
		j = 0
		index = 0
		tab = [0] * n
		for i in range(n):
			tab[i] = i % 2 + 1
			if arr[i] == arr[(i + 1) % n]:
				b = 1
				j = tab[i]
				index = (i + 1) % n
				break
		if b:
			j += 1
			for i in range(index, n):
				if tab[i] == 0:
					tab[i] = j % 2 + 1
					j += 1
		else:
			tab[-1] = 3
		print(2 if b else 3)
		print(*tab)


t = int(input())
ans = []
for i in range(0, t):
	n = int(input())
	data = list(map(int, input().split()))
	color = [0 for i in range(0, n)]
	color[0] = 1
	invertible = -1
	for i in range(1, n):
		if data[i] == data[i - 1]:
			color[i] = color[i - 1]
			invertible = i
		elif color[i - 1] == 1:
			color[i] = 2
		else:
			color[i] = 1
	if color[-1] == 1 and data[-1] != data[0]:
		if invertible == -1:
			color[-1] = 3
		else:
			for i in range(invertible, n):
				color[i] = 3 - color[i]
	ans.append([max(color)])
	ans.append(color)
for i in range(0, len(ans)):
	print(*ans[i])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	new_l = [1]
	start = l[0]
	mp = 1
	for i in range(1, n):
		if l[i] == start:
			new_l.append(new_l[-1])
		elif new_l[-1] == 1:
			new_l.append(2)
		else:
			new_l.append(1)
		start = l[i]
	if new_l[0] == new_l[-1] and l[0] != l[-1]:
		n_l = new_l.copy()
		n_l[-1] = 2
		for i in range(n - 2, -1, -1):
			if l[i] != l[i + 1] and n_l[i] == n_l[i + 1]:
				if n_l[i + 1] == 2:
					n_l[i] = 1
				else:
					n_l[i] = 2
		if n_l[0] == 2:
			new_l[-1] = 3
		else:
			new_l = n_l
	print(len(set(new_l)))
	print(*new_l)


import sys
input = sys.stdin.readline
from collections import *
from math import *
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	r = []
	c = 1
	rt = []
	ref = a[0]
	yy = [a[0]]
	for i in range(1, n):
		if a[i] == ref:
			yy.append(ref)
			continue
		rt.append(yy)
		ref = a[i]
		yy = [a[i]]
	if len(yy) != 0:
		rt.append(yy)
	if len(rt) == 1:
		print(1)
		print(*[1] * n)
		continue
	if len(rt) % 2 == 0:
		r = []
		for i in rt:
			for j in i:
				r.append(c ^ 3)
			c = c ^ 3
		print(2)
		print(*r)
		continue
	flag = 0
	for i in rt:
		if len(i) > 1:
			flag = 1
			break
	if 1:
		c = 1
		flag = 0
		for i in rt:
			if flag == 0 and len(i) > 1:
				r.append(c ^ 3)
				flag = 1
				for j in i[1:]:
					r.append(c)
				c = c ^ 3
			else:
				for j in i:
					r.append(c ^ 3)
			c = c ^ 3
		if a[-1] == a[0] or (a[-1] != a[0] and r[-1] != r[0]):
			print(2)
			print(*r)
		else:
			print(3)
			r[-1] = 3
			print(*r)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = [0 for i in range(n)]
	flag1 = 0
	if max(a) == min(a):
		print(1)
		for i in range(n):
			print('1', end=' ')
		print()
	else:
		for i in range(n - 1):
			if a[i] == a[i + 1]:
				flag1 = 1
				break
		if a[-1] == a[0]:
			i = n - 1
			flag1 = 1
		if n % 2 == 0:
			flag = 1
			for i in range(n):
				if flag == 1:
					k[i] = 1
					flag = 2
				else:
					k[i] = 2
					flag = 1
		elif flag1 == 1:
			j = 0
			flag = 1
			while j < n:
				if j == i:
					if flag == 1:
						k[j] = 1
						k[(j + 1) % n] = 1
						flag = 2
					else:
						k[j] = 2
						k[(j + 1) % n] = 2
						flag = 1
					j += 1
				elif flag == 1:
					k[j] = 1
					flag = 2
				else:
					k[j] = 2
					flag = 1
				j += 1
		else:
			flag = 1
			for i in range(n - 1):
				if flag == 1:
					k[i] = 1
					flag = 2
				else:
					k[i] = 2
					flag = 1
			k[-1] = 3
		print(max(k))
		for i in range(n):
			print(k[i], end=' ')
		print()


t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [1]
	f = 1
	flag = 0
	index = 0
	for k in range(1, n):
		if a[k] == a[k - 1]:
			flag = 1
			index = k
			ans.append(ans[k - 1])
		elif ans[k - 1] == 1:
			ans.append(2)
			f = 2
		else:
			ans.append(1)
	if a[0] != a[n - 1] and ans[0] == ans[n - 1]:
		if ans[n - 2] == ans[n - 1]:
			if ans[n - 2] == 1:
				ans[n - 1] = 2
			else:
				ans[n - 1] = 1
		elif flag == 1:
			for j in range(index, n):
				if ans[j] == 1:
					ans[j] = 2
				else:
					ans[j] = 1
		else:
			ans[n - 1] = 3
			f = 3
	print(f)
	for k in range(0, n):
		if k == n - 1:
			print(ans[k])
		else:
			print(ans[k], end=' ')


from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	t = [int(x) for x in input().split()]
	l = len(set(t))
	if l == 1:
		print(1)
		print(*[1] * n)
		continue
	if n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
		continue
	b = False
	for i in range(n - 1):
		if t[i] == t[i + 1]:
			b = True
			x = i + 1
	if t[0] == t[n - 1]:
		b = True
		x = 0
	if not b:
		print(3)
		print(*[1, 2] * (n // 2) + [3])
		continue
	z = True
	ans = []
	for i in range(n):
		if i != x:
			z = not z
		ans.append(z + 1)
	print(2)
	print(*ans)


def pos(ls):
	for i in range(-1, len(ls) - 1):
		if ls[i] == ls[i + 1]:
			return i
	return -2
for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	if len(set(lst)) == 1:
		print(1)
		lll = [1] * n
		print(*lll)
	elif n % 2 == 0:
		lll = [1, 2] * (n // 2)
		print(2)
		print(*lll)
	else:
		k = pos(lst)
		if k != -2:
			lll = [1, 2] * (n // 2)
			if k == -1:
				print(2)
				print(*lll, 1)
			else:
				if lll[k] == 1:
					lll[k] = '1 1'
				else:
					lll[k] = '2 2'
				print(2)
				print(*lll)
		else:
			print(3)
			lll = [1, 2] * (n // 2)
			print(*lll, 3)


from enum import *
from copy import *
from sys import *
from collections import *
from itertools import *
from functools import *
from math import *

def l2i(fr=None):
	return map_type_to_fr(int, fr)[0]

def i2i(fr=None):
	return l2i(fr)

def dbg(*args):
	print(*args, file=stderr)

def dbv(var_name):
	print(f'{var_name} = {eval(var_name)}', file=stderr)

def map_type_to_fr(t, fr):
	global GETLINE_OFFSET
	if fr is None:
		if RUNNING_ON_MY_PC:
			fr = TEST_INP[GETLINE_OFFSET].split()
			GETLINE_OFFSET += 1
		else:
			fr = input().split()
	return list(map(t, fr))

def mis(fr=None):
	return map_type_to_fr(int, fr)

def mbs(fr=None):
	return map_type_to_fr(bool, fr)
import os
import sysconfig
RUNNING_ON_MY_PC = os.name == 'nt' and platform == 'win32' and (sysconfig.get_platform() == 'win-amd64')
GETLINE_OFFSET = 0
TEST_INP = '7\n5\n1 2 1 2 2\n6\n1 2 2 1 2 2\n5\n1 2 1 2 3\n3\n10 10 10\n7\n5 6 6 1 3 5 4\n8\n13 13 9 12 13 1 13 1\n3\n1 2 1\n'.split('\n')
q = i2i()
for _ in range(q):
	n = i2i()
	ans = [None for _ in range(n)]
	t = mis()
	for el in t[1:]:
		if el != t[0]:
			break
	else:
		print(1)
		print(*[1] * n)
		continue
	if n % 2 == 0:
		print(2)
		print(*chain(*[[1, 2] for _ in range(n // 2)]))
		continue
	prev_idx = 0
	ans[0] = 1
	for (i, el) in enumerate(t[1:]):
		i = i + 1
		if el == t[prev_idx]:
			ans[i] = ans[prev_idx]
			for j in range(i + 1, n):
				ans[j] = 3 - ans[j - 1]
			break
		ans[i] = 3 - ans[i - 1]
		prev_idx = i
	else:
		if t[-1] != t[0]:
			print(3)
			print(*[i % 2 + 1 for i in range(n - 1)] + [3])
			continue
	print(2)
	print(*ans)


import sys
I = sys.stdin.readline
x = 0
y = 0

def same(t, n):
	global x, y
	if t[0] == t[-1]:
		x = 0
		y = n - 1
		return 1
	else:
		for i in range(n - 1):
			if t[i] == t[i + 1]:
				x = i
				y = i + 1
				return 1
	return 0
for _ in range(int(I())):
	n = int(I())
	t = list(map(int, I().split()))
	sett = set()
	for i in t:
		sett.add(i)
	if len(sett) == 1:
		print(1)
		ans = [1] * n
		print(*ans)
	elif n % 2 == 0:
		print(2)
		ans = [1, 2] * (n // 2)
		print(*ans)
	else:
		idx = same(t, n)
		if idx:
			if x == 0 and y == n - 1:
				c = [1, 2]
				ans = [1]
				i = 1
				j = 0
				while i < n - 1:
					j = (j + 1) % 2
					ans.append(c[j])
					i += 1
				ans.append(1)
				print(2)
				print(*ans)
			else:
				c = [1, 2]
				ans = [1]
				i = 1
				j = 0
				while i < n:
					if i != y:
						j = (j + 1) % 2
					ans.append(c[j])
					i += 1
				print(2)
				print(*ans)
		else:
			print(3)
			ans = [1, 2] * (n // 2) + [3]
			print(*ans)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(200001)]
pp = [0] * 200001

def SieveOfEratosthenes(n=200000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dp = [0] * n
	curr = 1
	dp[0] = 1
	ch = -1
	s = set()
	s.add(1)
	for i in range(1, n - 1):
		if a[i] == a[i - 1]:
			ch = i
			dp[i] = dp[i - 1]
		else:
			curr = 3 - curr
			s.add(curr)
			dp[i] = curr
	if n <= 2:
		print(len(s))
		print(*dp)
		continue
	if a[0] == a[n - 2]:
		if a[0] == a[n - 1]:
			dp[-1] = dp[0]
		elif dp[0] == dp[n - 2]:
			dp[-1] = 3 - dp[0]
		elif ch == -1:
			dp[-1] = 3
		else:
			for j in range(ch, n - 1):
				dp[j] = 3 - dp[j]
			dp[-1] = 3 - dp[0]
	elif dp[0] == dp[n - 2]:
		dp[-1] = 3 - dp[0]
	elif a[0] == a[-1]:
		dp[-1] = dp[0]
	elif a[n - 2] == a[-1]:
		dp[-1] = dp[n - 2]
	elif ch == -1:
		dp[-1] = 3
	else:
		for j in range(ch, n - 1):
			dp[j] = 3 - dp[j]
		dp[-1] = 3 - dp[0]
	s = set(dp)
	print(len(s))
	print(*dp)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	q = int(input())
	X = list(map(int, input().split()))
	s = 1
	b = -1
	r = [0] * q
	ll = 1
	j = -1
	for i in range(q):
		if b == -1 or X[i] == b:
			if X[i] == b:
				j = i
			r[i] = s
		else:
			ll = 2
			s = 3 - s
			r[i] = s
		b = X[i]
	if j != -1:
		s = 1
		b = -1
		r = [0] * q
		ll = 1
		for i in range(q):
			i = (i + j) % q
			if b == -1 or X[i] == b:
				r[i] = s
			else:
				ll = 2
				s = 3 - s
				r[i] = s
			b = X[i]
		print(ll)
		print(*r)
	else:
		if X[0] != X[-1] and r[0] == r[-1]:
			ll = 3
			r[-1] = 3
		print(ll)
		print(*r)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if len(set(arr)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		a = arr[-2]
		b = arr[-1]
		c = arr[0]
		if a == b:
			print(2)
			print('1 2 ' * (n // 2) + '2')
		elif a != b:
			if b == c:
				print(2)
				print('1 2 ' * (n // 2) + '1')
			else:
				i = 0
				while i < n - 1 and arr[i + 1] != arr[i]:
					i += 1
				if i == n - 1:
					print(3)
					print('1 2 ' * (n // 2) + '3')
				else:
					print(2)
					d = i // 2
					if i % 2 == 0:
						print('1 2 ' * d + '1 1 ' + '2 ' + (n - i - 3) // 2 * '1 2 ')
					else:
						print('1 2 ' * d + '1 2 2 ' + '1 2 ' * ((n - i - 2) // 2))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(b, c) = (1, 1)
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			break
		b += 1
	for i in range(n - 1, 0, -1):
		if a[i] != a[i - 1]:
			break
		c += 1
	if b == n:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	elif b + c == n:
		print(2)
		print('1 ' * b + '2 ' * c)
	elif a[-1] == a[0]:
		print(2)
		print('1 ' + '2 1 ' * ((n - 2) // 2) + '2 1')
	elif a[0] == a[1]:
		print(2)
		print('1 1 ' + '2 1 ' * ((n - 2) // 2) + '2')
	else:
		i = 0
		ma = 0
		ind = -1
		while i < n:
			j = i + 1
			while j < n:
				if a[j] != a[i]:
					break
				j += 1
			if ma < j - i:
				ma = j - i
				ind = i
				if ma >= 2:
					break
			i = j
		if ma >= 2:
			c = []
			for i in range(ind):
				if i % 2:
					c.append(2)
				else:
					c.append(1)
			s = 2
			if c[-1] == 1:
				c.append(2)
				c.append(2)
				for i in range(n - len(c)):
					if i % 2:
						c.append(2)
					else:
						c.append(1)
			else:
				c.append(1)
				c.append(1)
				for i in range(n - len(c)):
					if i % 2:
						c.append(1)
					else:
						c.append(2)
			print(2)
			print(*c)
		else:
			print(3)
			a = []
			b = [3, 1, 2]
			for i in range(1, n + 1):
				a.append(b[i % 3])
			if n % 3 == 1:
				a[0] = 2
				a[1] = 1
			print(*a)


for tc in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	if len(set(ls)) == 1:
		print(1)
		print(' '.join(['1' for _ in range(n)]))
	else:
		solo = True
		ngroups = 0
		for i in range(n):
			if ls[i] == ls[i - 1]:
				solo = False
			else:
				ngroups += 1
		shuffle = 1 if ngroups % 2 and (not solo) else 0
		i = 0
		while ls[i] == ls[i - 1]:
			i += 1
		res = [None for _ in range(n)]
		st = 1
		for j in range(n):
			if shuffle and ls[i] == ls[i - 1]:
				st = 3 - st
				shuffle = 0
			res[i] = st
			i = (i + 1) % n
			if ls[i] != ls[i - 1]:
				st = 3 - st
		if st == 2:
			i = (i - 1) % n
			res[i] = 3
			while ls[(i - 1) % n] == ls[i]:
				i = (i - 1) % n
				res[i] = 3
		print(max(res))
		print(' '.join(map(str, res)))


import sys

class DCarousel:

	def solve(self):
		for _ in range(int(input())):
			n = int(input())
			t = [int(_) for _ in input().split()]
			nodes = 1
			for i in range(1, n):
				if t[i] != t[i - 1]:
					nodes += 1
			cur_color = 0
			colors = []
			for i in range(n):
				if i != 0 and t[i] == t[i - 1] and (nodes % 2 == 0 or nodes == 1):
					colors.append(colors[-1])
					cur_color = colors[-1]
					cur_color ^= 1
				else:
					colors.append(cur_color)
					cur_color ^= 1
					if i != 0 and t[i] == t[i - 1]:
						nodes += 1
			if colors[0] == colors[-1] and t[0] != t[-1]:
				if colors[-1] != colors[-2]:
					colors[-1] = 2
				else:
					colors[-1] = 1 - colors[-2]
			print(len(set(colors)))
			print(*[x + 1 for x in colors])
solver = DCarousel()
input = sys.stdin.readline
solver.solve()


n = int(input())
for a in range(n):
	length = int(input())
	order = list(map(int, input().split()))
	if max(order) == min(order):
		print(1)
		print('1 ' * length)
	elif length % 2 == 0:
		print(2)
		print('1 2 ' * int(length / 2))
	else:
		consecutive = -1
		for b in range(length):
			if order[b] == order[(b + 1) % length]:
				consecutive = b
		if consecutive == -1:
			print(3)
			answer = '1 2 ' * int(length // 2) + '3'
			print(answer)
		else:
			print(2)
			if consecutive == length - 1:
				print('1 2 ' * int(length // 2) + '1')
			elif consecutive == 0:
				print('1 ' + '1 2 ' * int(length // 2))
			else:
				answer = '1 2 ' * int(consecutive // 2) + '1 ' * (consecutive % 2)
				if answer[-2] == '1':
					answer += '2 2 '
					answer += '1 2 ' * int((length - consecutive - 2) // 2) + '1' * int((length - consecutive - 2) % 2)
				else:
					answer += '1 1 '
					answer += '2 1 ' * int((length - consecutive - 2) // 2) + '2' * int((length - consecutive - 2) % 2)
				print(answer)


q = int(input())
while q:
	q -= 1
	n = int(input())
	types = list(map(int, input().split()))
	types = types + types
	c = [''] * n
	ok = True
	i = 0
	while i < n and ok:
		ok = types[i] ^ types[i + 1]
		i += 1
	if ok:
		if n & 1:
			print(3)
			for i in range(n - 1):
				print(str(1 + i % 2) + ' ', end='')
			print('3')
		else:
			print(2)
			for i in range(n):
				print(str(1 + i % 2) + ' ', end='')
			print()
		continue
	s = n
	while types[s - 1] ^ types[s]:
		s -= 1
	ans = 0
	i = 0
	j = 0
	while i < n:
		i = j
		j += 1
		while j < n and types[s + j] != types[s + j - 1]:
			j += 1
		ans = max(min(j - i, 2), ans)
		for k in range(i, j):
			c[(s + k) % n] = str(1 + (k - i) % 2)
	print(ans)
	print(' '.join(c))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ANS = [-1] * n
	ANS[0] = 1
	if min(A) == max(A):
		print(1)
		print(*[1] * n)
		continue
	if n % 2 == 1:
		flag = 0
	else:
		flag = 1
	for i in range(1, n):
		if flag == 0:
			if A[i] == A[i - 1]:
				ANS[i] = ANS[i - 1]
				flag = 1
			else:
				ANS[i] = 3 - ANS[i - 1]
		else:
			ANS[i] = 3 - ANS[i - 1]
	if flag == 0 and A[i] != A[0]:
		ANS[n - 1] = 3
	print(max(ANS))
	print(*ANS)


for i in range(int(input())):
	n = int(input())
	kinds = [int(i) for i in input().split()]
	id1 = 1
	k = 1
	answer = [1] * n
	while id1 < n:
		if kinds[id1] == kinds[id1 - 1]:
			break
		if answer[id1 - 1] == 1:
			answer[id1] = 2
		else:
			answer[id1] = 1
		id1 += 1
		k = 2
	if id1 == n:
		if n % 2 and kinds[n - 1] != kinds[0]:
			answer[0] = 3
			print(3)
			print(*answer)
		else:
			print(2)
			print(*answer)
		continue
	id2 = n - 1
	while id2 >= 0:
		if kinds[id2] == kinds[(id2 + 1) % n]:
			break
		if answer[(id2 + 1) % n] == 1:
			answer[id2] = 2
		else:
			answer[id2] = 1
		id2 -= 1
		k = 2
	for j in range(id1, id2 + 1):
		if kinds[j] != kinds[j - 1]:
			if answer[j - 1] == 1:
				answer[j] = 2
			else:
				answer[j] = 1
			k = 2
		else:
			answer[j] = 1
	print(k)
	print(*answer)


testcases = int(input())
for j in range(testcases):
	n = int(input())
	car = list(map(int, input().split()))
	diffvals = set(car)
	if len(diffvals) == 1:
		print(1)
		print(' '.join(['1' for k in range(n)]))
	else:
		noreps = [car[0]]
		replist = [1]
		for s in range(1, n):
			if car[s] == car[s - 1]:
				replist[-1] += 1
			else:
				replist.append(1)
				noreps.append(car[s])
		greatestsofar = 0
		exists = 0
		for b in range(len(replist)):
			if replist[b] >= 2:
				greatestsofar = b
				exists = 1
		ind1 = 0
		ind2 = 0
		ind1 = sum(replist[0:greatestsofar])
		ind2 = ind1 + replist[greatestsofar] - 1
		if len(noreps) == n:
			if n % 2 == 0:
				print(2)
				print(' '.join([str(m % 2 + 1) for m in range(n)]))
			elif n % 2 == 1:
				if car[0] == car[-1]:
					print(2)
					print(' '.join([str(m % 2 + 1) for m in range(n)]))
				else:
					outputlist = [m % 3 + 1 for m in range(n)]
					diffs = set([1, 2, 3])
					diffs.discard(outputlist[0])
					diffs.discard(outputlist[-2])
					outputlist[-1] = list(diffs)[0]
					print(3)
					print(' '.join(map(str, outputlist)))
		else:
			print(2)
			if (n + exists - replist[greatestsofar]) % 2 == 0 or car[0] == car[-1]:
				output = []
				for b in range(n):
					if b <= ind1:
						output.append(str(b % 2 + 1))
					elif b > ind1 and b <= ind2:
						output.append(output[-1])
					elif b > ind2:
						output.append(str(int(output[-1]) % 2 + 1))
				print(' '.join(output))
			elif (n + exists - replist[greatestsofar]) % 2 == 1 and car[0] != car[-1]:
				output1 = []
				for b in range(n):
					if b <= ind1:
						output1.append(str(b % 2 + 1))
					elif b > ind1 and b <= ind2:
						if b == ind1 + 1:
							output1.append(str(int(output1[-1]) % 2 + 1))
						else:
							output1.append(output1[-1])
					elif b > ind2:
						output1.append(str(int(output1[-1]) % 2 + 1))
				print(' '.join(output1))


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	n = int(sys.stdin.readline())
	t = list(map(int, sys.stdin.readline().split()))
	res = [0] * n
	res[0] = 1
	is_same = 1
	check = 0
	for i in range(1, n):
		if not check and t[i] == t[i - 1]:
			res[i] = res[i - 1]
			check = 1
			continue
		res[i] = res[i - 1] % 2 + 1
		if is_same and (not t[i] == t[i - 1]):
			is_same = 0
	k = 2
	if is_same:
		k = 1
		res = [1] * n
	elif not n % 2:
		k = 2
		res = [i % 2 + 1 for i in range(n)]
	elif not check:
		if t[-1] == t[-2]:
			res[-1] = res[-2]
		elif t[-1] == t[0]:
			res[-1] = res[0]
		else:
			k = 3
			res[-1] = 3
	print(k)
	print(*res)


from sys import stdin, stdout
from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, stdin.readline().split()))
	c = Counter(l)
	if len(c) == 1:
		print(1)
		stdout.write('1 ' * n + '\n')
	else:
		l1 = []
		k = '1'
		ans = 2
		if n % 2 != 0:
			an = False
		else:
			an = True
		if an == True:
			for j in range(n):
				l1.append(k)
				if k == '1':
					k = '2'
				else:
					k = '1'
		else:
			q = 0
			for j in range(n - 1):
				l1.append(k)
				if l[j] == l[j + 1]:
					q += 1
				if q == 1:
					q += 1
				elif k == '1':
					k = '2'
				else:
					k = '1'
			if q == 0:
				if l[n - 1] == l[0]:
					l1.append(k)
				else:
					ans += 1
					l1.append('3')
			else:
				l1.append(k)
		print(ans)
		stdout.write(' '.join(l1) + '\n')


from sys import stdin

def solve(n, ts):
	pos = -1
	for x in range(0, n):
		if ts[x] == ts[(x + 1) % n]:
			pos = x
			break
	if pos == -1:
		T = 2
		c = [1 if x % 2 else 2 for x in range(n)]
		if n % 2 == 1:
			c[-1] = 3
			T += 1
	else:
		T = 1
		c = [1] * n
		for x in range(pos, pos + n):
			if ts[x % n] != ts[(x + 1) % n]:
				c[(x + 1) % n] = 3 - c[x % n]
				T = 2
	print(T)
	print(*c)
input()
for (a, b) in zip(*[iter(stdin)] * 2):
	n = int(a)
	ts = list(map(int, b.split()))
	solve(n, ts)


t = int(input())
for i2 in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	check = 1
	check2 = 0
	for i in range(1, n):
		if x[i] != x[i - 1]:
			check = 0
		else:
			check2 = 1
	if check:
		print(1)
		for i in range(n):
			print(1, end=' ')
	elif n % 2 == 0 or x[n - 1] == x[0]:
		print(2)
		k = 1
		for i in range(n):
			print(k, end=' ')
			if k == 1:
				k = 2
			else:
				k = 1
	elif check2 == 1:
		print(2)
		k = 1
		for i in range(n):
			if i > 0 and x[i] == x[i - 1] and (check2 == 1):
				if k == 1:
					k = 2
				else:
					k = 1
				check2 = 0
			print(k, end=' ')
			if k == 1:
				k = 2
			else:
				k = 1
	else:
		print(3)
		k = 3
		for i in range(n):
			print(k, end=' ')
			if k == 1:
				k = 2
			else:
				k = 1
	print('')


from itertools import chain
T = int(input())
for t in range(T):
	N = int(input())
	ans = input().split(' ')
	a0 = ans[0]
	for i in range(N):
		if ans[i] != a0:
			break
	else:
		print(1)
		print(' '.join(('1' for i in range(N))))
		continue
	if N % 2 == 0:
		print(2)
		print(' '.join(('1' if i % 2 else '2' for i in range(N))))
	else:
		for i in range(N):
			if ans[i] == ans[(i + 1) % N]:
				print(2)
				print(' '.join(chain(('1' if j % 2 else '2' for j in range(i + 1)), ('2' if j % 2 else '1' for j in range(i + 1, N)))))
				break
		else:
			print(3)
			print(' '.join(('1' if i % 2 else '2' for i in range(N - 1))) + ' 3')


n = int(input())
for x in range(n):
	a = int(input())
	t = list(map(int, input().split()))
	s = ''
	if min(t) == max(t):
		for y in range(a):
			s += '1 '
		print(1)
		print(s)
		continue
	if a % 2 == 0:
		s = ''
		for y in range(a // 2):
			s += '1 2 '
		print(2)
		print(s)
		continue
	else:
		neigh = False
		for y in range(1, a):
			if t[y] == t[y - 1]:
				neigh = True
				break
		if neigh == False:
			s = ''
			for y in range(a // 2):
				s += '1 2 '
			if t[0] != t[-1]:
				print(3)
				print(s + '3')
				continue
			else:
				print(2)
				print(s + '1')
				continue
		else:
			s = '1 '
			col = 1
			change = False
			for y in range(1, a):
				if t[y] == t[y - 1] and change == False:
					change = True
					s += str(col) + ' '
					continue
				if col == 1:
					col = 2
				elif col == 2:
					col = 1
				s += str(col) + ' '
			print(2)
			print(s)


entrada = int(input())
for k in range(entrada):
	n = int(input())
	string = ''
	carrosel = list(map(int, input().split()))
	if carrosel.count(carrosel[0]) == n:
		print('1')
		print('1 ' * (n - 1) + '1')
	elif n % 2 == 0:
		print('2')
		for i in range(n):
			string += str(i % 2 + 1) + ' '
		print(string)
	else:
		flag = False
		for i in range(n):
			if carrosel[i] == carrosel[(i + 1) % n]:
				flag = True
				print('2')
				j = 0
				for pos in range(i + 1, n):
					string = string + str(j + 1) + ' '
					j = (j + 1) % 2
				j = 0
				for pos in range(i, -1, -1):
					string = str(j + 1) + ' ' + string
					j = (j + 1) % 2
				print(string)
				break
		if not flag:
			print('3')
			for i in range(n - 1):
				string += str(i % 2 + 1) + ' '
			string += '3'
			print(string)


q = int(input())
while q:
	q -= 1
	n = int(input())
	anims = list(map(int, input().split(' ')))
	a = len(anims)
	if len(set(anims)) == 1:
		print(1)
		for i in range(a):
			print(1, end=' ')
		print()
		continue
	flag = False
	i = 1
	while i < a:
		if anims[i - 1] == anims[i]:
			flag = True
			break
		i += 1
	while i < a and anims[i - 1] == anims[i]:
		i += 1
	i -= 1
	if flag:
		anims = anims[i:] + anims[:i]
	cols = [j % 2 + 1 for j in range(a)]
	if cols[0] == cols[-1]:
		if anims[0] != anims[-1]:
			cols[-1] = 3
	if flag:
		cols = cols[-i:] + cols[:-i]
	print(len(set(cols)))
	print(' '.join(map(str, cols)))


for _ in range(int(input())):
	n = int(input())
	car = list(map(int, input().split()))
	flag = 0
	for c in range(n - 1):
		if not car[c] == car[c + 1]:
			flag = 1
			break
	if flag == 0:
		print(1)
		for i in range(n):
			if i == n - 1:
				print(1)
			else:
				print(1, end=' ')
		continue
	color = [0] * n
	color[0] = 1
	maxColor = 1
	for i in range(n - 1):
		if car[i] == car[i + 1]:
			if (n - i - 2) % 2 == 0:
				color[i + 1] = 2
			else:
				color[i + 1] = 1
		else:
			color[i + 1] = color[i] % 2 + 1
			maxColor = 2
	if not car[n - 1] == car[0] and color[n - 1] == color[0]:
		color[n - 1] = 3
		maxColor = 3
	print(maxColor)
	for i in range(n):
		if i == n - 1:
			print(color[i])
		else:
			print(color[i], end=' ')


from sys import stdin
input = stdin.readline
import bisect
import math

def px(ll):
	if ll == 1:
		return 2
	else:
		return 1
for xoxo in range(1):
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		b = [a[0]]
		c = [1]
		cnt = [1]
		p = 0
		for i in range(1, n):
			if a[i] == a[i - 1]:
				cnt[-1] += 1
				continue
			cnt.append(1)
			b.append(a[i])
			p = (p + 1) % 2
			c.append(p + 1)
		if len(b) == 1:
			ans = [1] * n
			print('1')
			print(*ans)
			continue
		mc = 2
		if a[-1] != a[0] and c[-1] == c[0] and (max(cnt) == 1):
			mc += 1
			c[-1] = 3
		p = 0
		ans = [0] * n
		ans[0] = 1
		for i in range(1, n):
			if a[i] == a[i - 1]:
				ans[i] = ans[i - 1]
			else:
				p += 1
				ans[i] = c[p]
		xx = 0
		if a[-1] != a[0] and c[-1] == c[0]:
			for i in range(1, n):
				if a[i] == a[i - 1] and xx == 0:
					ans[i] = px(ans[i])
					xx = 1
					continue
				if xx == 1:
					ans[i] = px(ans[i])
			print(mc)
			print(*ans)
		else:
			print(mc)
			print(*ans)


for _ in range(int(input())):
	n = int(input())
	ani = list(map(int, input().split()))
	if len(set(ani)) == 1:
		print(1)
		print(*[1 for i in range(n)])
	elif n % 2 == 0:
		print(2)
		ans = []
		for i in range(n // 2):
			ans.extend([1, 2])
		print(*ans)
	else:
		matched = False
		for i in range(n):
			if ani[i] == ani[i - 1]:
				matched = True
				break
		if matched:
			print(2)
			ans = []
			c = 0
			for t in range(n):
				if t == i and i != 0:
					ans.append(ans[i - 1])
				else:
					ans.append(c + 1)
					c = (c + 1) % 2
			print(*ans)
		else:
			print(3)
			ans = []
			for i in range(n // 2):
				ans.extend([1, 2])
			ans.append(3)
			print(*ans)


import sys

def input():
	return sys.stdin.readline()[:-1]
q = int(input())
for _ in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		print(1)
		print(*[1 for _ in range(n)])
		continue
	t.append(t[0])
	diffs = 0
	succ = False
	for i in range(n):
		if t[i] != t[i + 1]:
			diffs ^= 1
		elif not succ:
			succ = True
			change_ind = i
	if diffs == 0:
		print(2)
		ans = [1]
		cur = 0
		for i in range(1, n):
			if t[i] != t[i - 1]:
				cur ^= 1
			ans.append(cur + 1)
		print(*ans)
	elif not succ:
		print(3)
		ans = [1]
		cur = 0
		first = True
		for i in range(1, n):
			if first:
				if t[i] == t[i - 1]:
					ans.append(1)
				else:
					ans.append(3)
					cur = 2
					first = False
			elif cur == 2:
				if t[i] == t[i - 1]:
					ans.append(3)
				else:
					ans.append(2)
					cur = 1
			else:
				if t[i] != t[i - 1]:
					cur ^= 1
				ans.append(cur + 1)
		print(*ans)
	else:
		print(2)
		t[change_ind] = 200001
		ans = [1]
		cur = 0
		for i in range(1, n):
			if t[i] != t[i - 1]:
				cur ^= 1
			ans.append(cur + 1)
		print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	count = set(ls)
	ans = []
	if len(count) == 1:
		ans = [1] * n
	elif n % 2 == 0:
		ans = [1, 2] * (n // 2)
		if n % 2 != 0:
			ans.append(1)
	else:
		flag = 0
		ind = 0
		for i in range(n):
			if ls[i] == ls[(i + 1) % n]:
				flag = 1
				ind = i
				break
		if flag == 1:
			ans = [0 for i in range(n)]
			for i in range(ind + 1, n):
				ans[i] = i % 2 + 1
			for i in range(ind, -1, -1):
				ans[i] = (i - 1) % 2 + 1
		elif n % 2 == 0:
			ans = [1, 2] * ((n - 1) // 2)
			ans.append(1)
			ans.append(3)
		else:
			ans = [1, 2] * (n // 2)
			ans.append(3)
	print(len(set(ans)))
	print(' '.join(map(str, ans)))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = Counter(l)
	if len(x) == 1:
		print(1)
		z = [1] * n
		print(*z)
	elif n % 2 == 0:
		print(2)
		z = [1, 2] * (n // 2)
		print(*z)
	else:
		f = 0
		idx = 0
		for t in range(1, n):
			if l[t] == l[t - 1]:
				f = 1
				idx = t
				break
		if f == 1:
			print(2)
			z = [1, 2] * (n // 2)
			z.append(1)
			z[idx] = z[idx - 1]
			for t in range(idx + 1, n):
				if z[t - 1] == 1:
					z[t] = 2
				elif z[t - 1] == 2:
					z[t] = 1
			print(*z)
		else:
			z = [1, 2] * (n // 2)
			z.append(1)
			if l[0] == l[-1]:
				print(2)
				print(*z)
			else:
				print(3)
				z[-1] = 3
				print(*z)


import math as m

def D():
	T = int(input())
	while T != 0:
		T = T - 1
		N = int(input())
		ARR = [int(i) for i in input().split(' ')]
		RRA = [int(i) for i in range(len(ARR) - 1, -1, -1)]
		dict1 = dict()
		dict1['index'] = -1000
		(co1, a1, index) = slvr(ARR, -1, True)
		(co2, a2) = (len(ARR), 0)
		if co1 == 3:
			(co2, a2, index) = slvr(ARR, index, False)
		if co1 > co2:
			print(co2)
			ARR = a2
		else:
			print(co1)
			ARR = a1
		for i in ARR:
			print(i, end=' ')
		print()

def slvr(ARR, index, flag):
	co = 1
	Colors = list()
	ARR2 = [int(i) for i in range(0, len(ARR))]
	ARR2[0] = 1
	Colors.append(1)
	ptr = 0
	for i in range(1, len(ARR)):
		if ARR[i - 1] != ARR[i] or index == i:
			if co > 1:
				if i == len(ARR) - 1:
					ptr = (ptr + 1) % len(Colors)
					if ARR[0] != ARR[i] and ARR2[0] == Colors[ptr]:
						co = co + 1
						ARR2[i] = co
					else:
						ARR2[i] = Colors[ptr]
				else:
					ptr = (ptr + 1) % len(Colors)
					ARR2[i] = Colors[ptr]
			else:
				co = co + 1
				ptr = ptr + 1
				Colors.append(co)
				ARR2[i] = Colors[ptr]
		else:
			if flag == True:
				index = i
			if i == len(ARR) - 1:
				if ARR2[0] == ARR2[i - 1] and ARR[0] != ARR[i]:
					ptr = ptr + 1
					if ptr < len(Colors):
						ARR2[i] = Colors[ptr]
					else:
						co = co + 1
						Colors.append(co)
						ARR2[i] = Colors[ptr]
				else:
					ARR2[i] = ARR2[i - 1]
			else:
				ARR2[i] = ARR2[i - 1]
	return (co, ARR2, index)
D()


q = int(input())
while q:
	q -= 1
	n = int(input())
	t = [int(x) for x in input().split()]
	out = []
	if len(set(t)) == 1:
		out = [1] * n
	elif n % 2 == 0:
		out = [1, 2] * (n // 2)
	elif t[0] == t[-1]:
		out = [1, 2] * (n // 2) + [1]
	elif all((t[i] != t[i + 1] for i in range(n - 1))):
		out = [1, 2] * (n // 2) + [3]
	else:
		for i in range(n - 1):
			if t[i] == t[i + 1]:
				out = [1 if ii % 2 == 0 else 2 for ii in range(i + 1)]
				out.extend((2 if ii % 2 == 0 else 1 for ii in range(i + 1, n)))
				break
	print(len(set(out)))
	print(*out)


q = int(input())
res = []

def flip(x):
	if x == 1:
		return 2
	else:
		return 1
for k in range(q):
	n = int(input())
	T = [int(x) for x in input().split()]
	swapable = False
	painted = [-1] * n
	painted[0] = 1
	used = 1
	for i in range(1, n - 1):
		if T[i] == T[i - 1]:
			swapable = True
			swap_index = i
			painted[i] = painted[i - 1]
		else:
			used = 2
			painted[i] = flip(painted[i - 1])
	if used == 1:
		if T[n - 1] == T[0]:
			painted[n - 1] = 1
		else:
			painted[n - 1] = 2
			used = 2
	elif T[n - 1] == T[0]:
		painted[n - 1] = flip(painted[n - 2])
	elif T[n - 1] == T[n - 2]:
		painted[n - 1] = flip(painted[0])
	elif painted[n - 2] == 1:
		painted[n - 1] = 2
	elif swapable:
		for i in range(swap_index, n - 1):
			painted[i] = flip(painted[i])
		painted[n - 1] = flip(painted[n - 2])
	else:
		painted[n - 1] = 3
		used = 3
	res.append(used)
	res.append(painted)
for i in range(q):
	print(res[i * 2])
	for item in res[i * 2 + 1]:
		print(item, end=' ')
	print()


from collections import defaultdict
from sys import stdin, stdout

def doColor(graph, root, color):
	k = 1
	while True:
		for i in graph[root]:
			if color[i] == k:
				break
		else:
			break
		k += 1
	color[root] = k

def main():
	for _ in range(int(input())):
		N = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		if arr.count(arr[0]) == N:
			res = [1] * N
			m = 1
		elif N % 2 == 0:
			res = [1, 2] * (N // 2)
			m = 2
		else:
			f = -1
			for i in range(N):
				if arr[i] == arr[i - 1]:
					f = i
			if f != -1:
				res = [1, 2] * (N // 2)
				res.insert(f, res[f - 1])
				m = 2
			else:
				res = [1, 2] * (N // 2)
				res.append(3)
				m = 3
		print(m)
		print(' '.join(map(str, res)))
main()


q = int(input())
for _ in range(q):
	n = int(input())
	ty = list(map(int, input().split()))
	if len(set(ty)) == 1:
		print(1)
		print(*[1] * n)
	elif n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
	elif ty[0] == ty[-1]:
		print(2)
		print(*[1, 2] * (n // 2) + [1])
	else:
		li = []
		bol = True
		bo = True
		for i in range(n - 1):
			if bol:
				li.append(1)
			else:
				li.append(2)
			if bo and ty[i] == ty[i + 1]:
				bo = False
				bol = not bol
			bol = not bol
		if bo:
			print(3)
			li.append(3)
			print(*li)
		else:
			print(2)
			li.append(2)
			print(*li)


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	d = [1 for i in range(n)]
	if len(set(a)) == 1:
		print(1)
		print(*d)
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print()
	else:
		s = set()
		s.add(a[0])
		s.add(a[n - 1])
		s.add(a[n - 2])
		if len(s) == 1 or (len(s) == 2 and a[0] == a[n - 1]):
			print(2)
			for i in range(n):
				if i % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
			print()
		elif a[n - 2] == a[n - 1]:
			print(2)
			for i in range(n - 1):
				if i % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
			print(2)
		else:
			p = -1
			for i in range(0, n - 2):
				if a[i] == a[i + 1]:
					p = i + 1
					break
			if p == -1:
				print(3)
				for i in range(n - 1):
					if i % 2 == 0:
						print(1, end=' ')
					else:
						print(2, end=' ')
				print(3)
			else:
				print(2)
				for i in range(n):
					if i < p:
						if i % 2 == 0:
							print(1, end=' ')
						else:
							print(2, end=' ')
					elif i % 2 == 1:
						print(1, end=' ')
					else:
						print(2, end=' ')
				print()


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n,) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	st = set(a)
	if len(st) == 1:
		print(1)
		print(*[1] * n)
	else:
		if n % 2 == 0:
			ans = [-(int(i) % 2) + 2 for i in range(n)]
		if n % 2 == 1:
			k = -1
			ans = []
			a.append(-1)
			for i in range(len(a) - 1):
				if i == k:
					continue
				elif a[i] == a[i + 1] and k == -1:
					ans.append(-(int(i) % 2) + 2)
					ans.append(-(int(i) % 2) + 2)
					k = i + 1
				elif k != -1:
					ans.append(-(int(i - 1) % 2) + 2)
				else:
					ans.append(-(int(i) % 2) + 2)
			a.pop()
		if a[-1] != a[0] and ans[-1] == ans[0]:
			if a[1] == a[0]:
				ans[0] = ans[1]
			elif a[-2] == a[-1]:
				ans[-1] = ans[-2]
			else:
				ans[-1] = 3
		print(len(set(ans)))
		print(*ans)


T = int(input())
for _ in range(T):
	n = int(input())
	fg = list(map(int, input().split()))
	dup = -1
	for i in range(n):
		p = n - 1 if i == 0 else i - 1
		if fg[p] == fg[i]:
			dup = i
			break
	res = []
	if all((fg[0] == u for u in fg)):
		print(1)
		res = [1] * n
	elif n % 2 == 0 or dup != -1:
		print(2)
		nres = n if n % 2 == 0 else n - 1
		res = [2 if u % 2 else 1 for u in range(nres)]
		if n % 2:
			p = -1 if dup == 0 else dup - 1
			res.insert(dup, res[p])
	else:
		print(3)
		res = [2 if u % 2 else 1 for u in range(n)]
		res[-1] = 3
	print(*res)


import math
T = int(input())
for _ in range(T):
	N = int(input())
	l = list(map(int, input().split()))
	flag = 0
	for i in range(1, N):
		if l[i] != l[i - 1]:
			flag = 1
			break
	if flag == 0:
		print(1)
		for i in range(N):
			print(1, end=' ')
		print()
		continue
	d = dict()
	for i in range(N):
		d[l[i]] = 1
	if len(d.keys()) == 2:
		print(2)
		x = 1
		for i in d.keys():
			d[i] = x
			x += 1
		for i in range(N):
			print(d[l[i]], end=' ')
		print()
		continue
	X = [0 for i in range(N)]
	for i in range(1, N):
		X[i] = 1 - X[i - 1]
	flag = 0
	if l[0] != l[N - 1]:
		if X[0] == X[N - 1]:
			for i in range(1, N):
				if l[i - 1] == l[i]:
					for j in range(i, N):
						X[j] = 1 - X[j]
					flag = 1
					break
		else:
			print(2)
			for i in X:
				print(i + 1, end=' ')
			print()
			continue
	else:
		print(2)
		for i in X:
			print(i + 1, end=' ')
		print()
		continue
	if flag == 0:
		X[0] = 2
		print(3)
		for i in X:
			print(i + 1, end=' ')
	else:
		print(2)
		for i in X:
			print(i + 1, end=' ')
	print()


import os
import 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')
t = int(input())
li = [0]
for i in range(int(100000.0 + 10)):
	li.append(li[-1] + i + 1)
for ti in range(t):
	n = int(input())
	s = input().split(' ')
	d = {}
	ans = []
	mc = 1
	for (idx, i) in enumerate(s):
		if idx > 0:
			if s[idx - 1] == i:
				ans.append(ans[-1])
			else:
				mc = 2
				if ans[-1] == 1:
					ans.append(2)
				else:
					ans.append(1)
		else:
			ans.append(1)
	if s[-1] != s[0] and ans[-1] == ans[0]:
		ddd = True
		for (idx, i) in enumerate(ans):
			if idx == 0:
				continue
			if not ddd:
				ans[idx] = (ans[idx] - 1 ^ 1) + 1
			elif ans[idx - 1] == i:
				ans[idx] = (ans[idx] - 1 ^ 1) + 1
				ddd = False
		if ddd:
			ans[-1] = 3
			mc = 3
	print(mc)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = input().split()
	if len(set(a)) == 1:
		print(1)
		for i in range(n):
			print(1, end=' ')
	elif n % 2 == 0:
		print(2)
		for i in range(n // 2):
			print(1, end=' ')
			print(2, end=' ')
	else:
		p = 0
		prev = a[0]
		for i in range(1, n):
			if a[i] == prev:
				p = i
				break
			prev = a[i]
		if p != 0:
			x = True
		else:
			x = False
		if x:
			print(2)
			for i in range(n):
				if i == p - 1:
					if x:
						print(1, end=' ')
					else:
						print(2, end=' ')
				elif i == p:
					if x:
						print(1, end=' ')
						x = False
					else:
						print(2, end=' ')
						x = True
				elif x:
					x = False
					print(1, end=' ')
				else:
					x = True
					print(2, end=' ')
		elif a[0] == a[-1]:
			print(2)
			for i in range((n - 1) // 2):
				print(1, end=' ')
				print(2, end=' ')
			print(1, end=' ')
		else:
			print(3)
			for i in range((n - 1) // 2):
				print(1, end=' ')
				print(2, end=' ')
			print(3, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	t = list(map(int, input().split()))
	col = [1]
	c = 1
	lent = 1
	count = 0
	f = 0
	for i in range(n):
		if i == n - 1:
			if col[i] == 1:
				if t[i] != t[0]:
					if count > 0:
						f = 1
					else:
						del col[-1]
						col.append(3)
						lent = 3
			continue
		if t[i] == t[i + 1]:
			count += 1
			col.append(c)
			continue
		c += 1
		lent = 2
		if c > 2:
			c = 1
		col.append(c)
	print(lent)
	ft = 0
	if f == 1:
		for i in range(n - 1):
			if col[i] == col[i + 1] and ft == 0:
				ft = 1
				continue
			if ft == 1:
				col[i] = 3 - col[i]
		col[n - 1] = 3 - col[n - 1]
	for i in col:
		print(i, end=' ')
	print()


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())
t = inp()
while t > 0:
	n = int(input())
	a = list(invr())
	flag = 1
	p = 1
	while p < n and flag:
		if a[p] != a[p - 1]:
			flag = 0
		p += 1
	if flag == 1:
		print('1 ')
		for i in range(n):
			print('1', end=' ')
		print()
		t -= 1
		continue
	if n % 2 == 0:
		print('2 ')
		for i in range(0, n):
			if i & 1:
				print('2', end=' ')
			else:
				print('1', end=' ')
		print()
	else:
		b = []
		k = 2
		for i in range(0, n):
			if i & 1:
				b.append(2)
			else:
				b.append(1)
		if a[n - 1] != a[0] and b[n - 1] == b[0]:
			idx = 0
			for i in range(n - 1, 0, -1):
				if a[i] == a[i - 1]:
					idx = i
					break
			if idx:
				b[idx] = b[idx - 1]
				for i in range(idx + 1, n):
					if b[i - 1] == 2:
						b[i] = 1
					else:
						b[i] = 2
			else:
				k += 1
				b[n - 1] = k
		print(str(k))
		for i in range(0, n):
			print(str(b[i]), end=' ')
		print()
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	k = 1
	flag = f = 0
	if len(s) == 1:
		print(1)
		for i in range(n):
			print(1, end=' ')
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
	else:
		for i in range(n):
			if i == n - 1:
				if l[i] == l[0]:
					f = 1
					k = 0
					break
			elif l[i] == l[i + 1]:
				f = 1
				break
			else:
				continue
		if f == 0:
			print(3)
			for j in range(n):
				if j == n - 1:
					print(3, end=' ')
				elif j % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
		else:
			print(2)
			for j in range(n):
				if j == i:
					if flag == 0:
						print(1, end=' ')
					else:
						print(2, end=' ')
				elif j == i + 1 or k == 1:
					if flag == 0:
						print(1, end=' ')
						flag = 1
					else:
						print(2, end=' ')
						flag = 0
				elif flag == 0:
					print(1, end=' ')
					flag = 1
				else:
					print(2, end=' ')
					flag = 0
	print()


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		n = int(input())
		tt = [int(a) for a in input().split()]
		for t in tt:
			if t != tt[0]:
				break
		else:
			print(1)
			print('1 ' * n)
			return
		if n % 2 == 0:
			cc = ['1', '2'] * (n // 2)
			print(2)
			print(' '.join(cc))
			return
		elif tt[0] == tt[-1]:
			cc = ['1', '2'] * (n // 2) + ['1']
			print(2)
			print(' '.join(cc))
			return
		else:
			count = 2
			cc = ['1']
			for i in range(1, n):
				if tt[i] == tt[i - 1]:
					cc.append(cc[-1])
					for j in range(i + 1, n):
						if cc[-1] == '1':
							cc.append('2')
						else:
							cc.append('1')
					break
				elif cc[-1] == '1':
					cc.append('2')
				else:
					cc.append('1')
			else:
				count = 3
				cc[-1] = '3'
			print(count)
			print(' '.join(cc))
	q = int(input())
	for _ in range(q):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0 for i in range(n)]
	c[0] = 1
	doesRepeat = 0
	tillWhere = -1
	newColor = 0
	for i in range(1, n):
		if a[i] == a[i - 1]:
			c[i] = c[i - 1]
			doesRepeat = 1
			tillWhere = i
		elif c[i - 1] == 1:
			c[i] = 2
			newColor = 1
		else:
			c[i] = 1
	if c[n - 1] == c[0] and a[0] != a[n - 1]:
		if doesRepeat:
			i = tillWhere
			if c[i - 1] == 1:
				c[i] = 2
			else:
				c[i] = 1
			for i in range(tillWhere + 1, n):
				if a[i] == a[i - 1]:
					c[i] = c[i - 1]
				elif c[i - 1] == 1:
					c[i] = 2
				else:
					c[i] = 1
			print(2)
			for i in range(n):
				print(c[i], end=' ')
			print('')
		else:
			print(3)
			c[n - 1] = 3
			for i in range(n):
				print(c[i], end=' ')
			print('')
	elif newColor:
		print(2)
		for i in range(n):
			print(c[i], end=' ')
		print('')
	else:
		print(1)
		for i in range(n):
			print(c[i], end=' ')
		print('')


for h in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	if t == [t[0]] * n:
		print(1)
		print(*[1] * n)
		continue
	colour = [0] * n
	for i in range(n):
		colour[i] = 1 + i % 2
	if t[-1] != t[0] and colour[-1] == colour[0]:
		ind = -1
		for i in range(1, n):
			if t[i] == t[i - 1]:
				ind = i
				break
		if ind != -1:
			colour[ind] = colour[ind - 1]
			for i in range(ind + 1, n):
				colour[i] = abs(colour[i - 1] - 3)
	if colour[-1] != colour[0] or t[-1] == t[0]:
		print(2)
		print(*colour)
		continue
	colour[-1] = 3
	print(3)
	print(*colour)


import math
t = int(input())
for g in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(1)
		for i in range(0, n):
			print(1, end=' ')
		print('')
	elif n % 2 == 0:
		print(2)
		for i in range(0, n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print('')
	elif a[0] == a[n - 1]:
		print(2)
		for i in range(0, n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print('')
	else:
		b = 0
		for i in range(0, n - 1):
			if a[i] == a[i + 1]:
				b = 1
				break
		if b == 1:
			temp = i
			print(2)
			for i in range(0, temp + 1):
				if i % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
			if temp % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
			for i in range(temp + 2, n):
				if i % 2 == 0:
					print(2, end=' ')
				else:
					print(1, end=' ')
			print('')
		else:
			print(3)
			for i in range(0, n - 1):
				if i % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
			print(3)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	t = [int(x) for x in input().split()]
	c = [0] * n
	d = defaultdict(int)
	for x in t:
		d[x] += 1
	p = len(d)
	if p == 1:
		print(1)
		print('1 ' * n)
	elif p == 2:
		print(2)
		for i in range(n):
			if t[i] == t[0]:
				c[i] = 1
			else:
				c[i] = 2
		print(*c)
	else:
		subseq = 0
		sind = -1
		for i in range(n):
			l = [1, 2]
			c[i] = l[i % 2]
		for i in range(1, n):
			if t[i] == t[i - 1]:
				subseq = 1
				sind = i
				break
		if n & 1 == 0 or (n & 1 and t[0] == t[-1]):
			print(2)
			print(*c)
		elif subseq == 1:
			print(2)
			l = [1, 2]
			for z in range(sind, n):
				c[z] = l[(z + 1) % 2]
			print(*c)
		else:
			c[-1] = 3
			print(3)
			print(*c)


num_tests = input()
num_tests = int(num_tests)

def solution(num_fig, figs):
	figs = figs.split(' ')
	unique_fig = list(set(figs))
	if len(unique_fig) == 1:
		return [1] * num_fig
	if num_fig % 2 == 0:
		return [1, 2] * (num_fig // 2)
	else:
		cnt = 0
		check = 0
		colors = []
		for i in range(num_fig):
			if figs[i] == figs[(i + 1) % num_fig]:
				check = 1
				break
			cnt += 1
		if check == 1:
			for i in range(cnt + 1):
				colors.append(i % 2 + 1)
			if cnt + 1 < len(figs):
				colors.append(colors[-1])
				for i in range(cnt + 1, len(figs) - 1):
					colors.append(i % 2 + 1)
			return colors
		else:
			return [1, 2] * ((len(figs) - 1) // 2) + [3]
for i in range(num_tests):
	num_fig = input()
	num_fig = int(num_fig)
	figs = input()
	colors = solution(num_fig, figs)
	print(max(colors))
	print(' '.join([str(x) for x in colors]))


from collections import Counter
q = int(input())
for i in range(q):
	n = int(input())
	arr = input().split()
	count = Counter(arr)
	if len(count) == 1:
		k = 1
		ans = ['1'] * n
	elif n % 2 == 0:
		k = 2
		ans = ['1', '2'] * (n // 2)
	else:
		idx = -1
		for j in range(n - 1):
			if arr[j] == arr[j + 1]:
				idx = j
				break
		if arr[0] == arr[-1]:
			k = 2
			ans = ['1', '2'] * (n // 2)
			ans.append('1')
		elif idx == -1:
			k = 3
			ans = ['1', '2'] * (n // 2)
			ans.append('3')
		else:
			k = 2
			idx += 1
			tmp1 = ['1', '2'] * (idx // 2)
			if idx % 2:
				tmp1.append('1')
			tmp = n - idx
			tmp2 = ['1', '2'] * (tmp // 2)
			if tmp % 2:
				tmp2.append('1')
			ans = tmp1[::-1]
			ans.extend(tmp2)
	print(k)
	print(' '.join(ans))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [1]
	col = 1
	c = -1
	for i in range(1, n):
		if l[i] == l[i - 1]:
			ans.append(col)
			c = i
			continue
		col = col % 2 + 1
		ans.append(col)
	if ans[0] == ans[-1] and c > -1 and (l[n - 1] != l[0]):
		for i in range(c, n):
			ans[i] = ans[i] % 2 + 1
	elif ans[-1] == ans[0] and l[n - 1] != l[0]:
		ans[n - 1] = 3
	print(max(ans))
	for i in ans:
		print(i, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [i % 2 + 1 for i in range(n)]
	if max(l) == min(l):
		print(1)
		print('1 ' * n)
	elif n % 2 == 0 or l[0] == l[-1]:
		print(2)
		print(*ans)
	else:
		pos = -1
		for i in range(n - 1):
			if l[i] == l[i + 1]:
				pos = i + 1
		if pos == -1:
			ans[-1] = 3
		else:
			for i in range(n - 1, pos - 1, -1):
				ans[i] = ans[i - 1]
		print(max(ans))
		print(*ans)


from sys import stdin
from collections import defaultdict, Counter
t = int(input())
for _ in range(t):
	(n,) = map(int, stdin.readline().split())
	animals = list(map(int, stdin.readline().split()))
	d = len(set(animals))
	if d == 1:
		print(1)
		out = ['1'] * n
	elif n % 2 == 0:
		print(2)
		out = ['1', '2'] * (n // 2)
	else:
		adj = False
		for i in range(n):
			if animals[i] == animals[(i + 1) % n]:
				adj = True
				break
		out = []
		for j in range(n):
			if j % 2 == 0:
				out.append('1')
			else:
				out.append('2')
		if adj:
			print(2)
			out[(i + 1) % n] = out[i]
			if i + 2 <= n - 1:
				out[i + 2:] = [str(abs(int(k) - 2) + 1) for k in out[i + 2:]]
		else:
			print(3)
			out[-1] = '3'
	print(' '.join(out))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	st = set(a)
	if len(st) == 1:
		print(1)
		print(*[1 for i in range(n)])
		continue
	if n % 2 == 0:
		ans = [1, 2] * (len(a) // 2)
		print(2)
		print(*ans)
	else:
		(fl, idx, val) = (False, -1, -1)
		ans = [1, 2] * (len(a) // 2)
		for i in range(n - 1):
			if a[i] == a[i + 1]:
				fl = True
				idx = i
				val = ans[idx]
				break
		if a[-1] == a[0]:
			fl = True
			val = 1
			idx = n - 1
		if fl:
			print(2)
			ans.insert(idx, val)
		else:
			ans.append(3)
			print(3)
		print(*ans)


q = int(input())
for _ in range(q):
	n = int(input())
	caros = list(map(int, input().split(' ')))
	if caros.count(caros[0]) == n:
		print(1)
		ans = [1] * n
		print(*ans, sep=' ')
		continue
	flag = 0
	ind = 0
	for i in range(n):
		if caros[i] == caros[(i + 1) % n]:
			ind = i
			flag = 1
			break
	if flag != 1 and n % 2 != 0:
		print(3)
		ans = [1, 2] * (n // 2)
		ans += [3]
		print(*ans, sep=' ')
		continue
	if n % 2 == 0:
		print(2)
		ans = [1, 2] * (n // 2)
		print(*ans, sep=' ')
		continue
	ans = [0] * n
	ind = ind + 1
	for i in range(ind, ind + n):
		index = i % n
		if ans[index - 1] != 1:
			ans[index] = 1
		else:
			ans[index] = 2
	print(2)
	print(*ans, sep=' ')


import sys
import math
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	s = list(map(int, sys.stdin.readline().split()))
	ans = [0 for _ in range(n)]
	ans[0] = 1
	if s[0] == s[-1]:
		rem = n - 1
		z = False
	else:
		i = n - 1
		ans[-1] = 2
		z = True
		rem = 0
		while i > 0 and z:
			if s[i] == s[i - 1]:
				rem = i - 1
				z = False
			else:
				if ans[i] == 1:
					if i - 1 != 0:
						ans[i - 1] = 2
					i -= 1
					continue
				if ans[i] == 2:
					if i - 1 != 0:
						ans[i - 1] = 1
					i -= 1
					continue
	if not z:
		for i in range(1, rem + 1):
			if s[i] == s[i - 1]:
				ans[i] = 1
			else:
				if ans[i - 1] == 1:
					ans[i] = 2
					continue
				if ans[i - 1] == 2:
					ans[i] = 1
	if s[0] != s[1] and ans[0] == ans[1]:
		ans[1] = 3
	print(max(ans))
	print(*ans)


import sys
inp = sys.stdin.read().splitlines()
inp.reverse()
q = int(inp.pop())
for __ in range(q):
	n = inp.pop()
	arr = list(map(int, inp.pop().split()))
	if len(set(arr)) == 1:
		print(1)
		print(' '.join(['1'] * len(arr)))
	else:
		color = [1]
		int_color = 1
		cluster_idx = -1
		for i in range(1, len(arr)):
			if arr[i - 1] == arr[i]:
				color.append(int_color)
				cluster_idx = i
			else:
				int_color ^= 3
				color.append(int_color)
		if color[0] == color[-1] and arr[0] != arr[-1]:
			if cluster_idx == -1:
				color[-1] = 3
			else:
				for i in range(cluster_idx, len(arr)):
					color[i] ^= 3
		print(len(set(color)))
		print(' '.join(map(str, color)))


for _ in range(int(input())):
	x = int(input())
	s = list(map(int, input().split()))
	ans = [0 for _ in range(x)]
	ans[0] = 1
	idd = -1
	a = 1
	for i in range(1, x):
		if s[i] == s[i - 1]:
			ans[i] = ans[i - 1]
			if i != x - 1:
				idd = i
		else:
			a = 2
			ans[i] = ans[i - 1] % 2 + 1
	ch = 0
	if ans[-1] == ans[0] and s[0] != s[-1]:
		ans[-1] = ans[0] % 2 + 1
		a = 2
		ch = 1
	if ch == 1 and ans[-1] == ans[-2] and (s[-1] != s[-2]):
		ans[-1] = 3
		a = 3
	if idd == -1:
		print(a)
		print(*ans)
	else:
		aa = 2
		anss = [0 for _ in range(x)]
		anss[0] = 1
		for i in range(1, x):
			if s[i] == s[i - 1]:
				anss[i] = anss[i - 1]
				if i == idd:
					anss[i] = anss[i - 1] % 2 + 1
			else:
				anss[i] = anss[i - 1] % 2 + 1
		ch = 0
		if anss[-1] == anss[0] and s[0] != s[-1]:
			anss[-1] = anss[0] % 2 + 1
			ch = 1
		if ch == 1 and anss[-1] == anss[-2] and (s[-1] != s[-2]):
			anss[-1] = 3
			aa = 3
		if aa < a:
			print(aa)
			print(*anss)
		else:
			print(a)
			print(*ans)


t = int(input())
for xx in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	clrs = []
	col = 2
	if n % 2 == 0:
		clrs = [i % 2 + 1 for i in range(n)]
	else:
		fl = ct = 0
		for i in range(n):
			if a[i] == a[(i + 1) % n]:
				ct = i + 1
				fl = 1
				break
		if fl == 1:
			ed = 0
			for i in range(n):
				if i == ct:
					ed = 1
				k = (i + ed) % 2 + 1
				clrs.append(k)
		else:
			col = 3
			for i in range(n - 1):
				clrs.append(i % 2 + 1)
			clrs.append(3)
	fg = 0
	for i in range(n):
		if a[i] != a[(i + 1) % n]:
			fg += 1
			break
	if fg >= 1:
		ans = ' '.join([str(v) for v in clrs])
		print(col)
	else:
		print(1)
		ans = ' '.join(['1' for i in range(n)])
	print(ans)


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

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

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

def invr():
	return map(int, input().split())
mod = 1000000007
f = []

def fact(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncr(n, r, m):
	if r == 0:
		return 1
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def main():
	D()

def xdfs(root, v, sub, parent):
	st = [root]
	while len(st) > 0:
		node = st.pop()
		for i in range(len(v[node])):
			if v[node][i] != node:
				st.append(v[node][i])

def X():
	try:
		t = pi()
		while t:
			t -= 1
			n = pi()
			v = [[] for i in range(n)]
			for i in range(n - 1):
				[x, y] = ti()
				v[x - 1].append(y - 1)
				v[y - 1].append(x - 1)
			m = pi()
			p = ti()
			e = [0 for i in range(n - 1)]
			sub = [0 for i in range(n)]
			dfs(0, v, sub, -1)
			for i in range(1, n):
				e[i - 1] = sub[i] * (n - sub[i])
			if len(p) < n - 1:
				while len(p) < n - 1:
					p.append(1)
			p = sorted(p)
			if len(p) > n - 1:
				x = 1
				for i in range(n - 2, len(p)):
					x = x * p[i]
				while len(p) > n - 2:
					p.pop()
				p.append(x)
			e = sorted(e)
			res = 0
			for i in range(n - 1):
				res = (res + p[i] * e[i]) % mod
			print(res)
	except:
		print(sys.exc_info())

def bfs(v, root):
	q = [root, None]
	l = 0
	visited = [0 for i in range(len(v))]
	dist = [0 for i in range(len(v))]
	while len(q) > 0:
		node = q.pop(0)
		if node is not None:
			visited[node] = 1
			dist[node] = l
			for i in range(len(v[node])):
				if visited[v[node][i]] == 0:
					visited[v[node][i]] = 1
					q.append(v[node][i])
		else:
			l += 1
			if len(q) != 0:
				q.append(None)
	return dist

def B():
	n = pi()
	v = [[] for i in range(n)]
	for i in range(n - 1):
		[x, y] = ti()
		v[x - 1].append(y - 1)
		v[y - 1].append(x - 1)
	leafs = []
	for i in range(n):
		if len(v[i]) == 1:
			leafs.append(i)
	mn = 1
	d = bfs(v, leafs[0])
	for i in range(1, len(leafs)):
		if d[leafs[i]] % 2 != 0:
			mn = 3
			break
	count = 0
	for i in range(n):
		f = 0
		for j in range(len(v[i])):
			if len(v[v[i][j]]) == 1:
				f = 1
				break
		if f:
			count += 1
	mx = n - 1 - len(leafs) + count
	print(mn, mx)

def D():
	q = pi()
	while q:
		q -= 1
		(n, t) = (pi(), ti())
		count = 0
		for i in range(1, n):
			if t[i] != t[i - 1]:
				count += 1
		if count == 0:
			print(1)
			c = [1 for i in range(n)]
			print(*c, sep=' ')
			continue
		if n % 2 == 0:
			print(2)
			c = []
			for i in range(n):
				if i % 2 == 0:
					c.append(2)
				else:
					c.append(1)
			print(*c, sep=' ')
			continue
		if count == n - 1:
			c = []
			x = 2
			for i in range(n):
				if i == n - 1:
					if t[0] != t[i]:
						c.append(3)
						x = 3
					else:
						c.append(c[0])
					continue
				if i % 2 == 0:
					c.append(2)
				else:
					c.append(1)
			print(x)
			print(*c, sep=' ')
			continue
		c = [1 for i in range(n)]
		f = 0
		for i in range(1, n):
			if f == 0 and t[i] == t[i - 1]:
				c[i] = c[i - 1]
				f = 1
				continue
			c[i] = 1 if c[i - 1] == 2 else 2
		print(2)
		print(*c, sep=' ')
main()


from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	if len(set(t)) == 1:
		print(1)
		print(*[1 for i in range(n)])
	elif n % 2 == 0:
		print(2)
		ans = [i % 2 + 1 for i in range(n)]
		print(*ans)
	else:
		idx = -1
		for i in range(n - 1):
			if t[i] == t[i + 1]:
				idx = i
				break
		if t[n - 1] == t[0] and idx == -1:
			idx = n - 1
		if idx == -1:
			print(3)
			ans = [i % 2 + 1 for i in range(n - 1)] + [3]
			print(*ans)
		elif idx == n - 1:
			print(2)
			ans = [i % 2 + 1 for i in range(idx)] + [1]
			print(*ans)
		else:
			print(2)
			ans = [i % 2 + 1 for i in range(idx)] + [idx % 2 + 1] * 2 + [(i + 1) % 2 + 1 for i in range(idx + 2, n)]
			print(*ans)


from sys import stdin, stdout
from math import *
input = stdin.readline
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * n
	c[0] = 1
	if max(a) == min(a):
		for i in range(n):
			c[i] = 1
	elif n % 2 == 0:
		for i in range(n):
			if i % 2 == 0:
				c[i] = 1
			else:
				c[i] = 2
	elif a[0] == a[-1]:
		for i in range(n):
			if i % 2 == 0:
				c[i] = 1
			else:
				c[i] = 2
	elif a[-1] == a[-2]:
		for i in range(n - 1):
			if i % 2 == 0:
				c[i] = 1
			else:
				c[i] = 2
		c[n - 1] = 2
	else:
		t = 0
		for i in range(1, n):
			if a[i - 1] != a[i]:
				t += 1
		if t == n - 1:
			for i in range(n - 1):
				if i % 2 == 0:
					c[i] = 1
				else:
					c[i] = 2
			c[-1] = 3
		else:
			for i in range(1, n):
				if i % 2 == 1 and a[i] == a[i - 1]:
					t = i
					break
				elif i % 2 == 0 and a[i] == a[i - 1]:
					c[i] = c[i - 1]
					t = i + 1
					break
				elif c[i - 1] == 1:
					c[i] = 2
				else:
					c[i] = 1
			c[t] = 1
			for i in range(t + 1, n):
				if c[i - 1] == 1:
					c[i] = 2
				else:
					c[i] = 1
	print(len(list(set(c))))
	print(*c)


for _ in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	if t.count(t[0]) == n:
		print(1)
		for _ in range(n):
			print(1, end=' ')
		continue
	if n % 2:
		ans = False
		cnt = 0
		ind = 0
		if t[0] == t[-1]:
			ans = True
		else:
			for i in range(1, n):
				if t[i] == t[i - 1] and cnt == 0:
					ans = True
					ind = i
					cnt += 1
					break
		if ans:
			print(2)
			z = 1
			for i in range(n):
				if i == ind:
					if z == 2:
						print(1, end=' ')
					else:
						print(2, end=' ')
					continue
				print(z, end=' ')
				if z == 1:
					z = 2
				else:
					z = 1
		else:
			print(3)
			for i in range(n - 1):
				if i % 2:
					print(2, end=' ')
				else:
					print(1, end=' ')
			print(3, end=' ')
	else:
		print(2)
		for i in range(n):
			if i % 2:
				print(2, end=' ')
			else:
				print(1, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	if arr.count(arr[0]) == n:
		print(1)
		ans = [1] * n
		print(*ans)
		continue
	flag = 0
	for i in range(n):
		if arr[i] == arr[i - 1]:
			ind = i
			flag = 1
			break
	if flag == 0 and n % 2 != 0:
		print(3)
		ans = [1, 2] * (n // 2)
		ans += [3]
		print(*ans)
		continue
	if n % 2 == 0:
		print(2)
		ans = [1, 2] * (n // 2)
		print(*ans)
		continue
	ans = [0] * n
	for i in range(ind, ind + n):
		x = i % n
		if ans[x - 1] != 1:
			ans[x] = 1
		else:
			ans[x] = 2
	print(2)
	print(*ans)


count = int(input())
for i in range(count):
	n = int(input())
	t = input().split(' ')
	animals = set(t)
	if len(animals) == 1:
		print(1)
		for j in range(n):
			print(1)
	elif n % 2 == 0 or t[0] == t[n - 1]:
		print(2)
		for j in range(n):
			if j % 2 == 0:
				print(1)
			else:
				print(2)
	else:
		replay_detected = 0
		for j in range(n):
			if t[j - 1] == t[j]:
				replay_detected = 1
				break
		if replay_detected == 0:
			print(3)
			for j in range(n - 1):
				if j % 2 == 0:
					print(1)
				else:
					print(2)
			print(3)
		else:
			print(2)
			replay_found = 0
			for j in range(n):
				if replay_found == 0:
					if j % 2 == 0:
						print(1)
					else:
						print(2)
					if t[j] == t[j + 1]:
						replay_found = 1
				elif j % 2 == 0:
					print(2)
				else:
					print(1)


for _ in range(int(input())):
	n = int(input())
	t = [*map(int, input().split())]
	if len(set(t)) == 1:
		print(1)
		res = [1] * n
		print(*res)
	elif n % 2 == 0:
		print(2)
		res = [i % 2 + 1 for i in range(n)]
		print(*res)
	else:
		ans = [i % 2 + 1 for i in range(n)]
		for i in range(n):
			if t[i - 1] == t[i]:
				print(2)
				print(*([1, 2] * n)[:i][::-1] + ([1, 2] * n)[:n - i])
				break
		else:
			print(3)
			ans[-1] = 3
			print(*ans)


import sys
from collections import Counter

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	ans = [0] * N
	cur = 0
	for i in range(1, N):
		if A[i - 1] != A[i]:
			cur = 1 - cur
		ans[i] = cur
	if A[-1] != A[0] and ans[-1] == ans[0]:
		for i in range(1, N):
			if A[i - 1] == A[i]:
				j = i - 1
				while j >= 0:
					ans[j] = 1 - ans[j]
					j -= 1
				break
		else:
			ans[-1] = 2
	ans = [a + 1 for a in ans]
	print(max(ans))
	print(*ans)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

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

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
s = read_int()
for i in range(s):
	n = read_int()
	t = read_int_line()
	if max(t) == min(t):
		ans = [1] * n
		print(1)
		print(*ans)
	elif n % 2 == 0:
		a = [1, 2] * (n // 2)
		print(2)
		print(*a)
	else:
		ans = [0] * n
		ind = -1
		for i in range(1, n + 1):
			if t[i % n] == t[i - 1]:
				ind = i % n
				break
		if ind == -1:
			a = [1, 2] * ((n - 1) // 2)
			a += [3]
			print(3)
			print(*a)
		else:
			val = -1
			for i in range(n):
				if i == ind:
					continue
				if val == -1:
					ans[i] = 1
				else:
					ans[i] = 2
				val *= -1
			ans[ind] = ans[ind - 1]
			print(2)
			print(*ans)


from sys import stdin

def func():
	return
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	ans = [1] * n
	m = 1
	for i in range(n - 1):
		if arr[i] != arr[i + 1]:
			if m % 2 == 0:
				ans[i + 1] = ans[i] - 1
			else:
				ans[i + 1] = ans[i] + 1
			m += 1
		else:
			ans[i + 1] = ans[i]
	if arr[0] != arr[n - 1]:
		if ans[0] == ans[n - 1]:
			if ans[1] == ans[0] == 1:
				ans[0] = 2
			elif ans[1] == ans[0] == 2:
				ans[0] = 1
			elif ans[n - 1] == ans[n - 2] == 1:
				ans[n - 1] = 2
			elif ans[n - 2] == ans[n - 1] == 2:
				ans[n - 1] = 1
			else:
				i = n - 1
				while i > 0:
					if ans[i] == ans[i - 1]:
						break
					i -= 1
				if i == 0:
					ans[n - 1] = 3
				else:
					for j in range(i, n):
						if ans[j] == 1:
							ans[j] = 2
						else:
							ans[j] = 1
	print(len(set(ans)))
	print(*ans)


q = int(input())
for _ in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	s = set(t)
	if len(s) <= 2:
		print(len(s))
		for i in range(n):
			if t[i] == t[0]:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print()
	else:
		z = [1, 2]
		if n % 2 == 0:
			print(2)
			for i in range(n):
				print(z[i % 2], end=' ')
			print()
		else:
			t.append(t[0])
			tf = False
			for i in range(n):
				if t[i] == t[i + 1]:
					tf = True
					break
			if tf:
				print(2)
				ans = [0] * n
				ans[i] = 1
				c = 0
				for j in range(i + 1, i + n):
					ans[j % n] = z[c % 2]
					c += 1
				print(*ans)
			else:
				print(3)
				for i in range(n - 1):
					print(z[i % 2], end=' ')
				print(3)


def problem(n, t):
	c = [0] * n
	j = -1
	k = '1'
	for i in range(1, n):
		if t[i] != t[i - 1]:
			k = '2'
			c[i] = (c[i - 1] + 1) % 2
		else:
			j = i
	if c[0] == c[-1] and t[0] != t[-1]:
		if j == -1:
			c[-1] = 2
			return ('3', c)
		else:
			for i in range(j, n):
				c[i] = (c[i] + 1) % 2
	return (k, c)
for _ in range(int(input())):
	(k, c) = problem(int(input()), list(map(int, input().split())))
	print(k)
	print(*map(lambda i: i + 1, c))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * n
	c[0] = 1
	f = 0
	ff = 0
	for i in range(1, n + 1):
		if i != n:
			if a[i] == a[i - 1]:
				f = 1
				c[i] = c[i - 1]
			elif c[i - 1] == 1:
				c[i] = 2
			else:
				c[i] = 1
		elif a[n - 1] != a[0] and c[n - 1] == c[0]:
			c[n - 1] = 3
	if f == 1 and len(set(c)) == 3:
		for i in range(1, n + 1):
			if i != n:
				if a[i] == a[i - 1] and ff == 0:
					if c[i - 1] == 1:
						c[i] = 2
					else:
						c[i] = 1
					ff = 1
				elif a[i] == a[i - 1]:
					c[i] = c[i - 1]
				elif c[i - 1] == 1:
					c[i] = 2
				else:
					c[i] = 1
			elif a[n - 1] != a[0] and c[n - 1] == c[0]:
				c[n - 1] = 3
	print(len(set(c)))
	print(*c)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	f = 1
	s = set(a)
	if len(s) == 1:
		print(1)
		s = [1] * n
		print(*s)
		continue
	for i in range(0, n):
		if i % 2 == 0:
			ans.append(1)
		else:
			ans.append(2)
	f = 1
	if n % 2 == 0:
		print(2)
		print(*ans)
	else:
		f = -1
		for i in range(0, n):
			if a[i] == a[(i + 1) % n]:
				f = i
				break
		if f == -1:
			ans[-1] = 3
			print(3)
			print(*ans)
			continue
		ans = []
		for i in range(0, f + 1):
			if i % 2 == 0:
				ans.append(1)
			else:
				ans.append(2)
		for i in range(f + 1, n):
			if i % 2 == 0:
				ans.append(2)
			else:
				ans.append(1)
		print(2)
		print(*ans)


T = int(input())
while T:
	N = int(input())
	Data = list(map(int, input().split()))
	flag = True
	for i in range(1, N):
		if Data[i] != Data[i - 1]:
			flag = False
			break
	if flag:
		print(1)
		for i in range(0, N - 1):
			print(1, end=' ')
		print(1)
		T -= 1
		continue
	if not N & 1:
		print(2)
		for i in range(0, N - 1):
			if i & 1:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print(1)
	else:
		Color = [0 for i in range(0, N)]
		pre = 1
		Color[0] = 1
		flag = True
		for i in range(1, N):
			if Data[i] == Data[i - 1] and flag:
				Color[i] = pre
				flag = False
			elif pre == 1:
				(Color[i], pre) = (2, 2)
			else:
				(Color[i], pre) = (1, 1)
		if flag and Data[N - 1] == Data[0]:
			flag = False
		if flag:
			Color[N - 1] = 3
			print(3)
		else:
			print(2)
		for i in range(0, N - 1):
			print(Color[i], end=' ')
		print(Color[N - 1])
	T -= 1


def solve(n, a):
	z = [1, 2]
	if n % 2 == 0:
		print(2)
		print(*z * (n // 2))
	else:
		ans = [None] * n
		x = 0
		f = 1
		for i in range(0, n):
			if a[i] == a[(i + 1) % n]:
				x = 0
				for j in range(i + 1, n):
					ans[j] = (x ^ 1) + 1
					x = x ^ 1
				x = 0
				for j in range(i, -1, -1):
					ans[j] = (x ^ 1) + 1
					x = x ^ 1
				print(2)
				print(*ans)
				return
		print(3)
		print(*z * (n // 2), 3)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = set(a)
	if len(k) == 1:
		print(1)
		print('1 ' * n)
	else:
		solve(n, a)


import math
t = int(input())
for tc in range(t):
	n = int(input())
	arr = [int(z) for z in input().split()]
	if len(set(arr)) == 1:
		print(1)
		print(*[1] * n)
		continue
	if n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
		continue
	model = ([1, 2] * math.ceil(n / 2))[:n]
	p = -1
	for i in range(1, n):
		if arr[i] == arr[i - 1]:
			p = i
			break
	if p > 0:
		r = model[:p]
		r.append(r[-1])
		r += model[p:]
		r = r[:n]
	elif arr[0] != arr[-1]:
		r = model[:n - 1]
		r.append(3)
	else:
		r = model
	print(len(set(r)))
	print(*r)


def coloring(n, types):
	if not False in [types[i] == types[0] for i in range(1, n)]:
		return (1, [1 for _ in range(n)])
	if n & 1 == 0:
		return (2, [(i & 1) + 1 for i in range(n)])
	c = [0 for _ in range(n)]
	for i in range(n):
		if types[i - 1] == types[i]:
			c[i - 1] = 1
			for j in range(n - 1):
				c[(i + j) % n] = (j & 1) + 1
			break
	if c[0]:
		return (2, c)
	c = [(i & 1) + 1 for i in range(n - 1)]
	c.append(3)
	return (3, c)
t = int(input())
for i in range(t):
	n = int(input())
	types = [int(s) for s in input().split()]
	ans = coloring(n, types)
	print(ans[0])
	print(*ans[1])


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if min(a) == max(a):
		print(1)
		print(*[1] * n)
	elif n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
	else:
		for j in range(n):
			if a[j] == a[(j + 1) % n]:
				print(2)
				res = [1] * n
				for i in range(1, n):
					if i == j + 1:
						res[i] = res[i - 1]
					elif res[i - 1] == 1:
						res[i] = 2
				print(*res)
				break
		else:
			print(3)
			print(*[3] + [1, 2] * (n // 2))


def switch(j):
	if j == 1:
		return 2
	elif j == 2:
		return 1
q = int(input())
for _ in range(q):
	n = int(input())
	t = list(map(int, input().split()))
	c = [1]
	prev = 1
	flag = False
	for i in range(1, n):
		if t[i] != t[i - 1]:
			prev = switch(prev)
			c.append(prev)
		else:
			c.append(prev)
			flag = True
			idx = i
	if t[0] == t[n - 1] or c[0] != c[n - 1]:
		if len(set(c)) == 1:
			print(1)
			print(*c)
		else:
			print(2)
			print(*c)
	elif not flag:
		c[n - 1] = 3
		print(3)
		print(*c)
	else:
		for i in range(idx, n):
			c[i] = switch(c[i])
		print(2)
		print(*c)


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for i in range(int(ri())):
	n = int(ri())
	a = RI()
	ans = [0] * n
	if a[-1] == a[-2] or a[-1] == a[0]:
		ans[0] = 1
		colors = 1
		for i in range(1, len(a)):
			if i == n - 1:
				if a[i] == a[i - 1]:
					ans[i] = ans[i - 1]
					if ans[i] == ans[0] and a[i] != a[0]:
						ans[i] = 3 - ans[i - 1]
						colors = 2
				else:
					ans[i] = ans[0]
					if ans[i] == ans[i - 1]:
						ans[i] = 3 - ans[0]
						colors = 2
			elif a[i] == a[i - 1]:
				ans[i] = ans[i - 1]
			else:
				ans[i] = 3 - ans[i - 1]
				colors = 2
		print(colors)
		print(*ans)
	else:
		flag = False
		came = False
		ans[0] = 1
		for i in range(1, len(a)):
			if i == n - 1:
				if ans[0] == ans[n - 2]:
					ans[i] = 3 if (ans[i - 1] + 1) % 3 == 0 else (ans[i - 1] + 1) % 3
				else:
					came = True
					ans[i] = 3
			elif a[i] == a[i - 1]:
				ans[i] = ans[i - 1]
			else:
				ans[i] = 3 - ans[i - 1]
		if not came:
			print(2)
			print(*ans)
		else:
			flag = False
			ans[0] = 1
			came = False
			for i in range(1, len(a)):
				if i == n - 1:
					if ans[0] == ans[n - 2]:
						ans[i] = 3 - ans[i - 1]
					else:
						came = True
						ans[i] = 3
				elif a[i] == a[i - 1]:
					if not flag:
						ans[i] = 3 - ans[i - 1]
						flag = not flag
					else:
						ans[i] = ans[i - 1]
				else:
					ans[i] = 3 - ans[i - 1]
			if came:
				print(3)
			else:
				print(2)
			print(*ans)


def solve():
	n = int(input())
	A = list(map(int, input().strip().split()))
	for i in range(n - 1):
		if A[i] != A[i + 1]:
			break
	else:
		print(1)
		print(*[1] * n)
		return
	if n % 2 == 0:
		print(2)
		print(*[1, 2] * (n // 2))
		return
	switched = False
	out = [1]
	last = A[0]
	for a in A[1:]:
		if switched:
			out.append(3 - out[-1])
		elif a == last:
			switched = True
			out.append(out[-1])
		else:
			last = a
			out.append(3 - out[-1])
	if switched:
		print(2)
		print(*out)
		return
	elif A[-1] == A[0]:
		print(2)
		print(*out)
		return
	else:
		out[-1] = 3
		print(3)
		print(*out)
		return
t = int(input())
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	if len(set(a)) == 1:
		l = ['1'] * n
	else:
		l = ['1' if i % 2 == 0 else '2' for i in range(n)]
		if n % 2 != 0 and a[0] != a[-1]:
			for i in range(1, n):
				if a[i] == a[i - 1]:
					l.insert(i, l[i - 1])
					l.pop(-1)
					break
			else:
				l[-1] = '3'
	print(len(set(l)))
	print(*l)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		print('1 2 ' * (n // 2))
	else:
		ans = [1]
		en = 1
		colour = 2
		for i in range(1, n):
			if en and a[i] == a[i - 1]:
				colour = 3 - colour
				en = 0
			ans.append(colour)
			colour = 3 - colour
		if a[-1] != a[0] and ans[-1] == 1:
			ans[-1] = 3
		print(max(ans))
		print(*ans)


q = int(input())
for i in range(q):
	n = int(input())
	l2 = list(map(int, input().split()))
	k = 0
	for j in range(1, n):
		if l2[j - 1] == l2[j]:
			k = j
			break
	l = []
	for j in range(k, n):
		l.append(l2[j])
	for j in range(k):
		l.append(l2[j])
	l1 = [1]
	for j in range(1, n - 1):
		if l[j] == l[j - 1]:
			l1.append(l1[len(l1) - 1])
		else:
			l1.append(l1[len(l1) - 1] * 2 % 3)
	if l[n - 2] == l[n - 1]:
		if l[n - 1] == l[0]:
			l1.append(l1[len(l1) - 1])
		elif l1[n - 2] != l1[0]:
			l1.append(l1[len(l1) - 1])
		else:
			l1.append(l1[len(l1) - 1] * 2 % 3)
	elif l[n - 1] == l[0]:
		if l1[n - 2] == l1[0]:
			l1.append(l1[len(l1) - 1] * 2 % 3)
		else:
			l1.append(l1[0])
	elif l1[n - 2] == l1[0]:
		l1.append(l1[len(l1) - 1] * 2 % 3)
	else:
		l1.append(3)
	l3 = [0] * n
	for j in range(n - k):
		l3[k + j] = l1[j]
	for j in range(n - k, n):
		l3[j - (n - k)] = l1[j]
	print(max(l3))
	print(*l3)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = 1
	b = []
	p = -1
	r = -1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			p = i
		else:
			r = i
	if a[0] == a[-1]:
		p = 0
	else:
		r = 0
	if p == -1:
		if n % 2 == 0:
			print(2)
			for i in range(n):
				if i % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
			print()
		else:
			print(3)
			s = '1 2 ' * (n // 2)
			s += '3'
			print(s)
	elif r == -1:
		print(1)
		print('1 ' * n)
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print()
	elif p == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print()
	else:
		j = 1
		print(2)
		for i in range(n):
			if i == p:
				if j == 1:
					print(2, end=' ')
				else:
					print(1, end=' ')
			else:
				print(j, end=' ')
				if j == 1:
					j = 2
				else:
					j = 1
		print()


t = int(input())
for i in range(t):
	n = int(input())
	p = [int(j) for j in input().split()]
	if n == 1:
		print(1)
		print(1)
		continue
	match = None
	types = set()
	types.add(p[0])
	for j in range(1, len(p)):
		if len(types) < 2:
			types.add(p[j])
		if p[j - 1] == p[j]:
			match = j
	if p[0] == p[-1]:
		match = 0
	if len(types) == 1:
		print(1)
		for j in range(n):
			print(1, end=' ')
		print('')
	elif n % 2 == 0:
		print(2)
		for j in range(n):
			if j % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print('')
	elif match == None:
		print(3)
		for j in range(n - 1):
			if j % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print(3)
	else:
		switch = False
		print(2)
		if match == 0:
			print(1, end=' ')
			for j in range(1, n - 1):
				if j % 2 == 0:
					print(1, end=' ')
				else:
					print(2, end=' ')
			print(1)
		else:
			for j in range(n):
				if j == match:
					if j % 2 == 0:
						print(2, end=' ')
					else:
						print(1, end=' ')
					switch = True
				elif j % 2 == 0 and switch == False:
					print(1, end=' ')
				elif j % 2 != 0 and switch == False:
					print(2, end=' ')
				elif j % 2 == 0 and switch == True:
					print(2, end=' ')
				elif j % 2 != 0 and switch == True:
					print(1, end=' ')
			print('')


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = list(set(l))
	if len(s) == 1:
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()
	elif n % 2 == 0:
		print(2)
		for i in range(n):
			if i % 2 == 0:
				print(1, end=' ')
			else:
				print(2, end=' ')
		print()
	else:
		ans = 2
		x = -1
		for i in range(n):
			if l[i] == l[i - 1]:
				x = i
				break
		if x == -1:
			ans += 1
			print(ans)
			for i in range(n - 1):
				print(i % 2 + 1, end=' ')
			print(3)
		if x == 0:
			print(ans)
			for i in range(n):
				if i % 2 == 0:
					print(1)
				else:
					print(2)
		elif x > 0:
			print(ans)
			l1 = []
			l1.append(1)
			f = 0
			for i in range(1, n):
				if i == x:
					l1.append(l1[x - 1])
				elif l1[i - 1] == 1:
					l1.append(2)
				else:
					l1.append(1)
			for i in l1:
				print(i, end=' ')
			print()


t = int(input())
for g in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	last = -1
	clr = 1
	res = []
	was = False
	for i in arr:
		if last != i:
			clr += 1
			clr %= 2
			if last != -1:
				was = True
			last = i
		res.append(clr)
	cnt = 2
	if arr[-1] != arr[0] and res[0] == res[-1]:
		w = False
		ind = -1
		for i in range(1, n):
			if res[i - 1] == res[i]:
				res[i] = (res[i] + 1) % 2
				w = True
				ind = i
				break
		if w:
			clr = res[ind]
			last = arr[ind]
			for i in range(ind + 1, n):
				if last != arr[i]:
					clr += 1
					clr %= 2
					if last != -1:
						was = True
					last = arr[i]
				res[i] = clr
		else:
			cnt += 1
			res[-1] = 2
	print(cnt if was else 1)
	print(*map(lambda x: x + 1, res))


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	pos = -2
	notSame = False
	for i in range(n):
		if arr[i] == arr[i - 1]:
			pos = i
			val = i - 1 & 1
		else:
			notSame = True
	if notSame:
		if n & 1:
			if pos == -2:
				print(3)
				s = 0
				for i in range(n - 1):
					print(s + 1, end=' ')
					s ^= 1
				print(3)
			else:
				print(2)
				s = 0
				for i in range(n):
					if i == pos or i == (pos - 1) % n:
						print(val + 1, end=' ')
						s = val
					else:
						print(s + 1, end=' ')
					s ^= 1
				print()
		else:
			print(2)
			s = 0
			for i in range(n):
				print(s + 1, end=' ')
				s ^= 1
			print()
	else:
		print(1)
		for i in range(n):
			print(1, end=' ')
		print()


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.append(a[0])
	n += 1
	c = Counter(a)
	if len(c) == 1:
		print(1)
		print(*[1] * (n - 1))
		continue
	if n % 2:
		print(2)
		print(*[1, 2] * (n // 2))
		continue
	ans = [1]
	flg = 0
	pr = -1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			flg = 1
			pt = i
	if not flg:
		print(3)
		print(*[1, 2] * (n // 2 - 1) + [3])
	else:
		print(2)
		if pt % 2:
			print(*[1, 2] * (pt // 2) + [1] + [1, 2] * ((n - pt) // 2))
		else:
			print(*[1, 2] * (pt // 2) + [2] + [1, 2] * ((n - pt - 1) // 2))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	eqstart = -1
	eqend = -1
	ans = [0] * n
	if arr[0] == arr[-1]:
		eqright = n - 1
		for i in range(n - 1, 0, -1):
			eqright = i
			if arr[i - 1] != arr[i]:
				break
		eqleft = 0
		for i in range(eqright):
			eqleft = i
			if arr[i] != arr[i + 1]:
				break
		if eqleft == eqright - 1:
			for i in range(n):
				ans[i] += 1
			print(max(ans))
			print(*ans)
			continue
		groups = 0
		for i in range(eqleft, eqright):
			if arr[i] != arr[i - 1]:
				groups += 1
		col = 0
		if groups % 2 == 0:
			col = 1
		ans[eqleft] = col
		for i in range(eqleft + 1, eqright):
			if arr[i] != arr[i - 1]:
				col = col ^ 1
			ans[i] = col
	else:
		for i in range(n - 1):
			if arr[i] == arr[i + 1]:
				eqstart = i
				while i < n - 1 and arr[i] == arr[i + 1]:
					eqend = i + 1
					i += 1
				break
		if eqstart == -1:
			col = 0
			if n % 2:
				ans[0] = 2
			else:
				ans[0] = 0
			for i in range(1, n):
				if arr[i] != arr[i - 1]:
					col = col ^ 1
				ans[i] = col
		else:
			groups = 0
			for i in range(0, eqstart):
				if arr[i] != arr[i + 1]:
					groups += 1
			for i in range(eqend + 1, n):
				if arr[i - 1] != arr[i]:
					groups += 1
			if groups % 2 == 0:
				col = 0
				for i in range(1, eqstart):
					if arr[i] != arr[i - 1]:
						col = col ^ 1
					ans[i] = col
				col = col ^ 1
				ans[eqstart] = col
				col = col ^ 1
				for i in range(eqstart + 1, n):
					if arr[i] != arr[i - 1]:
						col = col ^ 1
					ans[i] = col
			else:
				col = 0
				for i in range(n):
					if arr[i] != arr[i - 1]:
						col = col ^ 1
					ans[i] = col
	for i in range(n):
		ans[i] += 1
	print(max(ans))
	print(*ans)