A positive integer is called composite if it can be represented as a product of two positive integers, both greater than 1. For example, the following numbers are composite: 6, 4, 120, 27. The following numbers aren't: 1, 2, 3, 17, 97.

Alice is given a sequence of n composite numbers a_1,a_2,…,a_n.

She wants to choose an integer m ≤ 11 and color each element one of m colors from 1 to m so that:

  * for each color from 1 to m there is at least one element of this color; 
  * each element is colored and colored exactly one color; 
  * the greatest common divisor of any two elements that are colored the same color is greater than 1, i.e. \gcd(a_i, a_j)>1 for each pair i, j if these elements are colored the same color. 



Note that equal elements can be colored different colors — you just have to choose one of m colors for each of the indices from 1 to n.

Alice showed already that if all a_i ≤ 1000 then she can always solve the task by choosing some m ≤ 11.

Help Alice to find the required coloring. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases. Then the descriptions of the test cases follow.

The first line of the test case contains a single integer n (1 ≤ n ≤ 1000) — the amount of numbers in a sequence a.

The second line of the test case contains n composite integers a_1,a_2,…,a_n (4 ≤ a_i ≤ 1000).

It is guaranteed that the sum of n over all test cases doesn't exceed 10^4.

Output

For each test case print 2 lines. The first line should contain a single integer m (1 ≤ m ≤ 11) — the number of used colors. Consider colors to be numbered from 1 to m. The second line should contain any coloring that satisfies the above conditions. Print n integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ m), where c_i is the color of the i-th element. If there are multiple solutions then you can print any of them. Note that you don't have to minimize or maximize the number of colors, you just have to find the solution with some m from 1 to 11.

Remember that each color from 1 to m should be used at least once. Any two elements of the same color should not be coprime (i.e. their GCD should be greater than 1).

Example

Input


3
3
6 10 15
2
4 9
23
437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961


Output


1
1 1 1
2
2 1
11
4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6

Note

In the first test case, \gcd(6,10)=2, \gcd(6,15)=3 and \gcd(10,15)=5. Therefore, it's valid to color all elements the same color. Note that there are other colorings which satisfy Alice's requirement in this test case.

In the second test case there is only one element of each color, so the coloring definitely satisfies Alice's requirement.

Difficulty: MEDIUM
Tags: Constructive algorithms

Greedy algorithms

Complete search

Number theory

Mathematics
Skill types: Complete search

Greedy algorithms

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dct = {}
	m = 1
	arr1 = []
	for n1 in arr:
		check = -1
		n2 = int(n1 ** 0.5)
		for j in range(2, n2 + 1, 1):
			if n1 % j == 0:
				check = 0
				if j in dct.keys():
					arr1.append(dct[j])
				else:
					dct[j] = m
					arr1.append(m)
					m += 1
				break
		if check == -1:
			dct[n1] = m
			arr1.append(m)
			m += 1
	print(m - 1)
	for i in arr1:
		print(i, end=' ')
	print()


import sys
I = lambda : int(input())
readline = lambda : sys.stdin.readline().strip('\n')
RM = readmap = lambda x=int: map(x, readline().split(' '))
primes11 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(I()):
	(n, l) = (I(), [*RM()])
	primes_used = {}
	sol = [0] * n
	for (ind, i) in enumerate(l):
		for prime in primes11:
			if i % prime == 0:
				if not prime in primes_used:
					primes_used[prime] = len(primes_used) + 1
				sol[ind] = primes_used[prime]
				break
	print(len(set(sol)))
	print(' '.join([str(i) for i in sol]))
quit()
for _ in range(I()):
	(a, b, c, d, x, y, x1, y1, x2, y2) = (*RM(), *RM())
	flag1 = x2 - x >= b - a and x - x1 >= a - b and (y2 - y >= d - c) and (y - y1 >= c - d)
	flag2 = (b == 0 and a == 0 or x2 - x1 > 0) and (c == 0 and d == 0 or y2 - y1 > 0)
	print(['NO', 'YES'][flag1 and flag2])


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	temp = []
	for i in range(n):
		for j in range(11):
			if l[i] % m[j] == 0:
				temp.append(m[j])
				break
	ans = []
	b = []
	for i in temp:
		if i not in ans:
			ans.append(i)
	for i in range(len(temp)):
		j = 0
		while 1:
			if temp[i] == ans[j]:
				break
			else:
				j += 1
		b.append(j + 1)
	print(len(ans))
	for i in b:
		print(i, end=' ')
	print(' ')


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

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

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

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

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

def s(d):
	dis = 1 + 4 * 2 * 3 * d
	ds = sqrt(dis)
	return (-1 + ds) / 6

def main():
	d = inp()
	data = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]
	for i in range(d):
		r = inp()
		vals = inlt()
		res = []
		pos = {}
		for v in vals:
			for (j, dd) in enumerate(data):
				if v % dd == 0:
					if j not in pos:
						pos[j] = len(pos) + 1
					res.append(j)
					break
		print(len(set(res)))
		print(' '.join([str(pos[j]) for j in res]))
main()


ttt = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for qqq in range(ttt):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 11
	mask = [False] * 11
	for k in range(n):
		for i in range(11):
			if a[k] % primes[i] == 0:
				a[k] = i
				mask[i] = True
				break
	k = 0
	for i in range(11):
		if mask[i]:
			k += 1
			c[i] = k
	print(k)
	for x in a:
		print(c[x], end=' ')
	print()


t = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * n
	for i in range(n):
		for j in range(11):
			if a[i] % p[j] == 0:
				c[i] = j + 1
				break
	t = sorted(set(c))
	d = {e: i for (i, e) in enumerate(t, 1)}
	c = [d[x] for x in c]
	print(len(t))
	print(*c)


def primes1(n):
	sieve = [True] * (n // 2)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i // 2]:
			sieve[i * i // 2::i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [2 * i + 1 for i in range(1, n // 2) if sieve[i]]
primes = primes1(40)
for _ in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	mylist = [0] * n
	m = 1
	boolean = True
	for item in primes:
		if boolean == False:
			m += 1
		boolean = True
		for items in range(n):
			if mylist[items] == 0:
				if ai[items] % item == 0:
					boolean = False
					mylist[items] = m
	print(max(mylist))
	print(*mylist)


for _ in ' ' * int(input()):
	a = int(input())
	z = []
	k = {}
	for i in map(int, input().split()):
		for j in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
			if i % j == 0:
				if j not in k:
					k[j] = len(k) + 1
				z += [k[j]]
				break
	print(len(k))
	print(*z)
	k = {}


def is_pr(k):
	i = 2
	while i < int(k ** 0.5) + 1:
		if k % i == 0:
			return False
		i += 1
	return True
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ras = [0 for k in range(n)]
	now_kol = 1
	for p in range(2, 32):
		bol = False
		for j in range(n):
			if ras[j] == 0 and a[j] % p == 0:
				ras[j] = now_kol
				bol = True
		if bol:
			now_kol += 1
	print(now_kol - 1)
	print(' '.join(map(str, ras)))


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def find_ans(n, s):
	ans = []
	m = 1
	q = dict()
	for i in s:
		for j in primes:
			if i % j == 0:
				if j in q:
					ans.append(str(q[j]))
				else:
					ans.append(str(m))
					q[j] = m
					m += 1
				break
	print(m - 1)
	print(' '.join(ans))
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	find_ans(n, s)


I = input
for _ in [0] * int(I()):
	I()
	a = [next((p for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31) if int(x) % p < 1)) for x in I().split()]
	b = [*{*a}]
	print(len(b), *(b.index(x) + 1 for x in a))


T = int(input())
for _ in range(T):
	n = int(input())
	A = list(map(int, input().split()))
	R = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	C = [0 for i in range(32)]
	D = [0 for i in range(n)]
	m = 1
	for i in range(n):
		for j in range(11):
			if A[i] % R[j] == 0:
				if C[R[j]] == 0:
					D[i] = m
					C[R[j]] = m
					m = m + 1
				else:
					D[i] = C[R[j]]
				break
	print(m - 1)
	print(*D)


from math import gcd

def primes(n):
	is_prime = [True] * (n + 1)
	for i in range(2, int(n ** 0.5) + 1):
		if not is_prime[i]:
			continue
		for j in range(i * 2, n + 1, i):
			is_prime[j] = False
	return [i for i in range(n + 1) if not is_prime[i]]
N = 1000
P = primes(N)

def pr():
	X = [(i, set()) for i in range(N + 1)]
	for i in P:
		for j in P:
			if gcd(i, j) == 1:
				X[i][1].add(j)
				X[j][1].add(i)
	return X
d = pr()
d = sorted(d, key=lambda x: len(x[1]))[::-1]
colors = [0] * (N + 1)
for (i, ss) in d:
	tmp = set()
	for u in ss:
		tmp.add(colors[u])
	c = 1
	while 1:
		if c not in tmp:
			colors[i] = c
			break
		c += 1
import sys
input = sys.stdin.readline
(t,) = map(int, input().split())
for _ in range(t):
	(n,) = map(int, input().split())
	X = list(map(int, input().split()))
	X = [colors[x] for x in X]
	d = dict()
	for (i, u) in enumerate(list(set(X))):
		d[u] = i + 1
	print(i + 1)
	print(*[d[x] for x in X])


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	ans = []
	k = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
	for _ in range(ri()):
		n = ri()
		a = ria()
		m = [0] * n
		c = 1
		f = 0
		for i in k:
			t = 0
			for j in range(n):
				if a[j] % i == 0 and m[j] == 0:
					m[j] = c
					f += 1
					t = 1
			if t == 1:
				c += 1
			if f == n:
				break
		print(len(set(m)))
		print(*m)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	colors = {}
	color = 1
	ans = []
	for num in arr:
		d = None
		for j in range(2, num):
			if num % j == 0:
				d = j
				break
		if d not in colors:
			colors[d] = color
			color += 1
		ans.append(colors[d])
	print(max(ans))
	print(*ans)


from collections import Counter as Co
import sys
input = sys.stdin.readline
p = [0] * 1001
x = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(11):
	for j in range(x[i], 1001, x[i]):
		if p[j] == 0:
			p[j] = i + 1
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = [p[arr[i]] for i in range(len(arr))]
	r = dict(Co(d))
	l = [i for i in r]
	di = dict()
	for i in range(len(l)):
		di[l[i]] = i + 1
	xi = [di[d[i]] for i in range(len(d))]
	print(len(r))
	print(*xi)


t = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
ans = []
for i in range(0, t):
	n = int(input())
	A = list(map(int, input().split()))
	answer = [0 for i in range(0, n)]
	color = 1
	for j in range(0, 11):
		flag = 0
		for k in range(0, n):
			if answer[k] == 0 and A[k] % p[j] == 0:
				answer[k] = color
				flag = 1
		color += flag
	ans.append([color - 1])
	ans.append(answer)
for i in range(0, len(ans)):
	print(*ans[i])


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
R = lambda : map(int, input().rstrip().split())
for _ in range(int(input())):
	n = int(input())
	a = list(R())
	ans = []
	colours = {}
	l = 0
	for x in a:
		for i in range(11):
			if x % primes[i] == 0:
				color = colours.get(i, 0)
				if color == 0:
					l += 1
					colours[i] = l
					color = l
				ans += [color]
				break
	print(l)
	print(*ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')

def primeFactors(n):
	dic = dd(bool)
	sam = set()
	while n % 2 == 0:
		sam.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sam.add(i)
			n = n // i
	if n > 2:
		sam.add(n)
	return sam
t = ip()
for _ in range(t):
	n = ip()
	arr = list(inp())
	color = [None] * n
	sam = [None] * n
	mark = [False] * n
	ch = set()
	for i in range(n):
		sam[i] = primeFactors(arr[i])
		ch = ch | sam[i]
	ch = sorted(list(ch))
	col = 1
	for i in ch:
		if i > 32:
			break
		f = False
		for j in range(n):
			if mark[j]:
				pass
			elif i in sam[j]:
				mark[j] = True
				color[j] = col
				f = True
		if f:
			col += 1
	print(len(set(color)))
	print(*color)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

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

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

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

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

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	for t in range(ii()):
		d = collections.defaultdict(list)
		n = ii()
		arr = li()
		r = sieve(int(max(arr) ** 0.5))
		b = [0] * n
		for p in r:
			d[p]
		for idx in range(n):
			for p in r:
				if arr[idx] % p == 0:
					d[p].append(idx)
					arr[idx] //= p
					if arr[idx] == 1:
						break
		m = 1
		for key in list(d.keys()):
			f = 0
			for i in d[key]:
				if b[i] == 0:
					f = 1
					b[i] = m
			if f == 1:
				m += 1
		print(m - 1)
		print(*b)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	p = [1] * n
	f = [0] * n
	i = 2
	y = max(l)
	while i <= y:
		for j in range(n):
			if l[j] % i == 0:
				if f[j] == 0:
					f[j] = 1
					p[j] = i
		i += 1
	print(len(set(p)))
	x = {}
	k = 1
	for i in range(n):
		if p[i] not in x:
			x[p[i]] = k
			print(k, end=' ')
			k += 1
		else:
			print(x[p[i]], end=' ')
	print()


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, stdin.readline().split()))
	color = defaultdict(lambda : -1)
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	curr = 1
	for i in primes:
		thereis = False
		for j in a:
			if j not in color and j % i == 0:
				color[j] = curr
				thereis = True
		if thereis:
			curr += 1
	print(curr - 1)
	for i in a:
		print(color[i], end=' ')
	print()


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

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

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

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

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

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

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

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

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 2
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def getprime(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1

def main():
	try:
		primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
		for _ in range(inp()):
			n = inp()
			a = inlt()
			used = [False for i in range(11)]
			clr = []
			for i in range(n):
				x = primes.index(getprime(a[i]))
				used[x] = True
				clr += [x]
			cnt = 0
			num = []
			for i in range(11):
				num.append(cnt)
				if used[i]:
					cnt += 1
			print(cnt)
			for i in range(n):
				x = primes.index(getprime(a[i]))
				print(num[x] + 1, end=' ')
			print()
	except Exception as e:
		print(e)
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())
for i in range(t):
	n = int(input())
	num1 = list(map(int, input().split()))
	num2 = []
	for i in range(n):
		if num1[i] % 2 == 0:
			num2.append(i)
		else:
			continue
	num3 = []
	for i in range(n):
		if num1[i] % 3 == 0 and num1[i] % 2 != 0:
			num3.append(i)
		else:
			continue
	num5 = []
	for i in range(n):
		if num1[i] % 5 == 0 and num1[i] % 3 != 0 and (num1[i] % 2 != 0):
			num5.append(i)
		else:
			continue
	num7 = []
	for i in range(n):
		if num1[i] % 7 == 0 and num1[i] % 5 != 0 and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num7.append(i)
		else:
			continue
	num11 = []
	for i in range(n):
		if num1[i] % 11 == 0 and num1[i] % 7 != 0 and (num1[i] % 5 != 0) and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num11.append(i)
		else:
			continue
	num13 = []
	for i in range(n):
		if num1[i] % 13 == 0 and num1[i] % 11 != 0 and (num1[i] % 7 != 0) and (num1[i] % 5 != 0) and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num13.append(i)
		else:
			continue
	num17 = []
	for i in range(n):
		if num1[i] % 17 == 0 and num1[i] % 13 != 0 and (num1[i] % 11 != 0) and (num1[i] % 7 != 0) and (num1[i] % 5 != 0) and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num17.append(i)
		else:
			continue
	num19 = []
	for i in range(n):
		if num1[i] % 19 == 0 and num1[i] % 17 != 0 and (num1[i] % 13 != 0) and (num1[i] % 11 != 0) and (num1[i] % 7 != 0) and (num1[i] % 5 != 0) and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num19.append(i)
		else:
			continue
	num23 = []
	for i in range(n):
		if num1[i] % 23 == 0 and num1[i] % 19 != 0 and (num1[i] % 17 != 0) and (num1[i] % 13 != 0) and (num1[i] % 11 != 0) and (num1[i] % 7 != 0) and (num1[i] % 5 != 0) and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num23.append(i)
		else:
			continue
	num29 = []
	for i in range(n):
		if num1[i] % 29 == 0 and num1[i] % 23 != 0 and (num1[i] % 19 != 0) and (num1[i] % 17 != 0) and (num1[i] % 13 != 0) and (num1[i] % 11 != 0) and (num1[i] % 7 != 0) and (num1[i] % 5 != 0) and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num29.append(i)
		else:
			continue
	num31 = []
	for i in range(n):
		if num1[i] % 31 == 0 and num1[i] % 29 != 0 and (num1[i] % 23 != 0) and (num1[i] % 19 != 0) and (num1[i] % 17 != 0) and (num1[i] % 13 != 0) and (num1[i] % 11 != 0) and (num1[i] % 7 != 0) and (num1[i] % 5 != 0) and (num1[i] % 3 != 0) and (num1[i] % 2 != 0):
			num31.append(i)
		else:
			continue
	num100 = [0 for i in range(n)]
	s = 0
	if len(num2) != 0:
		s += 1
		for j in num2:
			num100[j] = s
	if len(num3) != 0:
		s += 1
		for j in num3:
			num100[j] = s
	if len(num5) != 0:
		s += 1
		for j in num5:
			num100[j] = s
	if len(num7) != 0:
		s += 1
		for j in num7:
			num100[j] = s
	if len(num11) != 0:
		s += 1
		for j in num11:
			num100[j] = s
	if len(num13) != 0:
		s += 1
		for j in num13:
			num100[j] = s
	if len(num17) != 0:
		s += 1
		for j in num17:
			num100[j] = s
	if len(num19) != 0:
		s += 1
		for j in num19:
			num100[j] = s
	if len(num23) != 0:
		s += 1
		for j in num23:
			num100[j] = s
	if len(num29) != 0:
		s += 1
		for j in num29:
			num100[j] = s
	if len(num31) != 0:
		s += 1
		for j in num31:
			num100[j] = s
	print(s)
	print(' '.join((str(x) for x in num100)))


t = int(input())
primes = '2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31'.split(', ')
primes = list(map(int, primes))
while t:
	t -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	asig = {}
	ans = [0 for _ in range(n)]
	col = 0
	for (i, num) in enumerate(arr):
		for p in primes:
			if num % p == 0:
				if p not in asig:
					col += 1
					asig[p] = col
				ans[i] = asig[p]
				break
	print(col)
	print(' '.join(map(str, ans)))


def find_nod(number):
	i = 2
	while i <= number:
		if number % i == 0:
			return i
		i += 1
t = int(input())
for i in range(t):
	n = int(input())
	numbers = [int(i) for i in input().split()]
	output = [0 for i in numbers]
	n_colors = 0
	divs = []
	for (j, number) in enumerate(numbers):
		flag = 0
		for (k, div) in enumerate(divs):
			if number % div == 0:
				flag = 1
				output[j] = k + 1
		if flag == 0:
			n_colors += 1
			divs.append(find_nod(number))
			output[j] = len(divs)
	print(n_colors)
	print(*output, sep=' ')


I = input
for _ in [0] * int(I()):
	I()
	a = [min((2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31), key=lambda p: int(x) % p) for x in I().split()]
	b = (*{*a},)
	print(len(b), *(b.index(x) + 1 for x in a))


t = int(input())
a = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	ans = []
	count = 0
	dict = {}
	l = [int(i) for i in input().split()]
	for (u, e) in enumerate(l):
		for f in a:
			if e % f == 0:
				if f not in dict:
					dict[f] = [u]
					count += 1
					break
				else:
					dict[f].append(u)
					break
	var = 1
	for e in dict.values():
		for x in e:
			l[x] = var
		var += 1
	print(count)
	print(*l)


t = int(input())
first_11_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(t):
	n = int(input())
	assignment = []
	used = [False for i in range(11)]
	for x in map(int, input().split()):
		broken = False
		for (i, prime) in enumerate(first_11_primes):
			if x % prime == 0:
				assignment.append(i)
				used[i] = True
				broken = True
				break
		if not broken:
			print('Something wrong')
	print(used.count(True))
	current_no = 1
	for (i, x) in enumerate(used):
		if x:
			used[i] = current_no
			current_no += 1
	print(' '.join((str(used[x]) for x in assignment)))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	col = [0] * n
	d = dict()
	for t in range(len(a)):
		j = 2
		isprime = True
		while j * j <= a[t]:
			if a[t] % j == 0:
				isprime = False
				break
			j += 1
		if isprime == True:
			d[a[t]] = len(d) + 1
			col[t] = len(d)
	for t in range(len(a)):
		if col[t] == 0:
			x = a[t]
			j = 2
			fs = []
			while j * j <= x:
				if x % j == 0:
					fs.append(j)
				while x % j == 0:
					x //= j
				j += 1
			fs.append(x)
			ok = False
			for y in fs:
				if d.get(y) != None:
					col[t] = d[y]
					ok = True
					break
			if ok == False:
				d[fs[0]] = len(d) + 1
				col[t] = len(d)
	print(len(d))
	print(*col)


y = int(input())
ans = []
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
c = [0] * len(p)
for i in range(y):
	n = int(input())
	al = input().split()
	m = list(map(int, al))
	c = [0] * n
	for j in range(n):
		q = m[j]
		for t in range(len(p)):
			if q % p[t] == 0:
				c[j] = t + 1
				continue
	sc = set(c)
	sd = set(range(1, len(sc) + 1))
	if sc == sd:
		ans.append(c)
	else:
		ext = list(sc - sd)
		toc = list(sd - sc)
		for j in range(n):
			if c[j] in ext:
				ind = ext.index(c[j])
				c[j] = toc[ind]
		ans.append(c)
for i in ans:
	print(len(set(i)))
	for j in i:
		print(j, end=' ')
	print()


from math import gcd

def getprime(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	used = [False for i in range(11)]
	clr = []
	for i in range(n):
		x = primes.index(getprime(a[i]))
		used[x] = True
		clr.append(x)
	cnt = 0
	num = []
	for i in range(11):
		num.append(cnt)
		if used[i]:
			cnt += 1
	print(cnt)
	for i in range(n):
		x = primes.index(getprime(a[i]))
		print(num[x] + 1, end=' ')
	print()


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	dd = dict()
	for j in range(n):
		i = a[j]
		for firstfactor in range(2, int(sqrt(i)) + 1):
			if i % firstfactor == 0:
				if firstfactor in dd:
					dd[firstfactor].append(j)
				else:
					dd[firstfactor] = [j]
				break
	ks = sorted(dd.keys())
	ans = [0] * n
	print(len(ks))
	for i in range(len(ks)):
		for x in dd[ks[i]]:
			ans[x] = i + 1
	print(*ans)


import sys
input = sys.stdin.readline
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for ti in range(int(input().strip())):
	n = int(input().strip())
	a = [int(x) for x in input().strip().split()]
	v = [0] * len(a)
	ans = [0] * len(a)
	cc = [0] * len(primes)
	cn = 0
	for pi in range(len(primes)):
		for ai in range(len(a)):
			if not v[ai] and a[ai] % primes[pi] == 0:
				v[ai] = 1
				if not cc[pi]:
					cn += 1
				cc[pi] = 1
				ans[ai] = cn
	print(cn)
	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 = [[j, i] for (i, j) in enumerate(lin())]
		ans = []
		for i in range(2, 1000):
			if not a:
				break
			a1 = []
			a2 = []
			for (j, k) in a:
				if j % i == 0:
					a2.append(k)
				else:
					a1.append([j, k])
			if a2:
				ans.append(a2)
			a = a1
		print(len(ans))
		a1 = [0] * n
		for (k, i) in enumerate(ans):
			for j in i:
				a1[j] = k + 1
		print(*a1)
main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
import math
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)))
inamo = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def gift():
	for _ in range(t):
		n = int(input())
		elements = list(map(int, input().split()))
		res = []
		used = {}
		counter = 0
		for ele in elements:
			found = False
			for ina in inamo:
				if ele % ina == 0:
					res.append(ina)
					inorno = used.get(ina, False)
					if not inorno:
						counter += 1
						used[ina] = [True, counter]
					found = True
					break
			if not found:
				res.append(1)
		ans = []
		totlen = len(used)
		for ele in res:
			if ele == 1:
				totlen += 1
				ans.append(totlen)
			else:
				ans.append(used[ele][1])
		yield totlen
		yield ' '.join((str(kap) for kap in ans))
t = int(input())
ans = gift()
print(*ans, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	result = [0] * n
	k = 1
	flag = False
	for div in range(2, 32):
		for i in range(n):
			if a[i] and a[i] % div == 0:
				result[i] = k
				a[i] = 0
				flag = True
		if flag:
			k += 1
			flag = False
	print(k - 1)
	print(*result)


t = int(input())
for loop in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	lis = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	dic = {}
	ans = []
	for i in a:
		for j in range(11):
			if i % lis[j] == 0:
				if lis[j] not in dic:
					dic[lis[j]] = len(dic) + 1
				ans.append(dic[lis[j]])
				break
	print(len(dic))
	print(*ans)


import sys
input = sys.stdin.readline
div = [31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	color = [0] * n
	d_color = [0] * 11
	c = 1
	for i in range(n):
		for j in range(11):
			if a[i] % div[j] == 0:
				if d_color[j] == 0:
					d_color[j] = c
					c += 1
				color[i] = d_color[j]
				break
	print(c - 1)
	print(*color)


from collections import defaultdict
t = int(input())
ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [-1] * n
	for i in range(n):
		for j in range(11):
			if a[i] % ps[j] == 0:
				ans[i] = j
				break
	s = set(ans)
	d = defaultdict(int)
	c = 1
	for li in sorted(list(s)):
		d[li] = c
		c += 1
	for i in range(n):
		ans[i] = d[ans[i]]
	print(len(s))
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {2: 0, 3: 0, 5: 0, 7: 0, 11: 0, 13: 0, 17: 0, 19: 0, 23: 0, 29: 0, 31: 0}
	c = 0
	for i in range(n):
		for k in d:
			if l[i] % k == 0:
				if d[k] == 0:
					c += 1
					d[k] = c
				break
	print(c)
	for i in range(n):
		for k in d:
			if l[i] % k == 0:
				print(d[k], end=' ')
				break
	print()


prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def solve():
	n = int(input())
	array = list(map(int, input().split()))
	dic = {}
	res = []
	x = 1
	for a in array:
		for i in range(11):
			if a % prime[i - 1] == 0:
				res.append(i)
				if i not in dic.keys():
					dic[i] = x
					x += 1
				break
	print(len(set(res)))
	for r in res:
		print(dic[r], end=' ')
	print()
for _ in range(int(input())):
	solve()


from math import gcd

def smallestDivisor(a):
	for f1 in range(2, a):
		if a % f1 == 0:
			return f1
testCases = int(input())
colours_prime = {}
colours_assigned = {}
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for t in range(testCases):
	result = ''
	for i1 in range(11):
		colours_prime[prime[i1]] = 0
		colours_assigned[prime[i1]] = 0
	length = input()
	numbers = list(map(int, input().split()))
	currentColour = 0
	for i1 in numbers:
		temp = smallestDivisor(i1)
		if colours_prime[temp] == 0:
			colours_prime[temp] = 1
			currentColour += 1
			colours_assigned[temp] = currentColour
		result += str(colours_assigned[temp]) + ' '
	print(currentColour)
	print(result)


prime = []
for i in range(2, 32):
	temp = True
	for j in range(2, i // 2 + 1):
		if i % j == 0:
			temp = False
			break
		else:
			continue
	if temp:
		prime.append(i)
x = int(input())
for i in range(x):
	y = int(input())
	ans = [0] * 11
	temp1 = list(map(int, input().split()))
	temp2 = []
	temp3 = 0
	temp4 = 1
	for j in temp1:
		for k in range(11):
			if j % prime[k] == 0:
				if ans[k] == 0:
					ans[k] = temp4
					temp4 += 1
				temp2.append(str(ans[k]))
				break
	for i in ans:
		if i != 0:
			temp3 += 1
	print(temp3)
	print(' '.join(temp2))


import collections

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

def linp():
	return [int(i) for i in input().split()]
T = inp()
ans = []
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def find(x):
	for i in range(2, x):
		if x % i == 0:
			return i
for t in range(T):
	n = inp()
	a = linp()
	div = []
	used = [False for i in range(11)]
	for x in a:
		idx = primes.index(find(x))
		div.append(idx)
		used[idx] = True
	cnt = 1
	clr = {}
	for i in range(11):
		if used[i]:
			clr[i] = cnt
			cnt += 1
	print(cnt - 1)
	for i in range(n):
		print(clr[div[i]], end=' ')
	print()


dp = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for T in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	final = []
	mx = 0
	d = {}
	for i in range(n):
		for j in range(11):
			if arr[i] % dp[j] == 0:
				if d.get(j, 0):
					final.append(d[j])
				else:
					d[j] = mx + 1
					final.append(mx + 1)
					mx += 1
				break
	print(mx)
	print(*final)


import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
from functools import lru_cache
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

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

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())

def GCD(x, y):
	return GCD(y, x % y) if y else x
spf = [0] * 10005

def sieve():
	spf[1] = 1
	for i in range(2, 10005):
		spf[i] = i
	for i in range(4, 10005, 2):
		spf[i] = 2
	for i in range(3, int(10005 ** 0.5) + 1):
		if spf[i] == i:
			for j in range(i * i, 10005, i):
				if spf[j] == j:
					spf[j] = i
sieve()
for _ in range(int(input())):
	n = int(input())
	a = list(mapi())
	ls = []
	for i in range(n):
		ls.append([spf[a[i]], i])
	ls.sort()
	cnt = 0
	res = [0] * n
	i = 0
	while i < n:
		tmp = i
		for j in range(i, n):
			if ls[j][0] != ls[tmp][0]:
				break
			res[ls[j][1]] = cnt
			i = j
		cnt += 1
		i += 1
	print(cnt)
	for i in range(n):
		res[i] += 1
	print(*res)


from sys import stdin

def find_smallest_factor(n):
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for p in primes:
		if n % p == 0:
			return p

def choose_colours(num_list):
	factor_list = list(map(find_smallest_factor, num_list))
	unique_factors = list(set(factor_list))
	prime2colour = {k: v + 1 for (v, k) in enumerate(unique_factors)}
	colours = [prime2colour[d] for d in factor_list]
	return colours
N = int(stdin.readline())
for _ in range(N):
	_ = int(stdin.readline())
	num_list = list(map(int, stdin.readline().split()))
	colours = choose_colours(num_list)
	print(len(set(colours)))
	print(*colours, sep=' ')


from math import sqrt, ceil
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	buckets = {}
	ans = []
	count = 0
	for i in arr:
		j = 2
		root_i = ceil(sqrt(i))
		while j <= root_i:
			if i % j == 0 and count <= 11:
				if j not in buckets:
					count += 1
					buckets[j] = count
				ans.append(buckets[j])
				break
			j += 1
	print(count)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = 1
	ans = [0] * n
	for i in range(2, 1001):
		f = 0
		for j in range(n):
			if l[j] % i == 0 and ans[j] == 0:
				ans[j] = k
				f = 1
		if f == 1:
			k += 1
	print(k - 1)
	print(*ans)


for i in range(int(input())):
	a = int(input())
	li = list(map(int, input().split()))
	c = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	d = []
	e = [0 for i in range(11)]
	l = 1
	f = [0 for i in range(11)]
	for i in li:
		for j in range(11):
			if i % c[j] == 0:
				if f[j] == 0:
					f[j] = l
					l += 1
				d.append(f[j])
				break
	print(l - 1)
	print(*d)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
n = int(input())
for a in range(n):
	usedColors = 0
	colorKey = {}
	length = int(input())
	nums = list(map(int, input().split()))
	answer = ''
	for b in nums:
		for c in range(len(primes)):
			if b % primes[c] == 0:
				if c not in colorKey:
					usedColors += 1
					colorKey[c] = usedColors
				answer += str(colorKey[c]) + ' '
				break
	print(usedColors)
	print(answer)


pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	input()
	seq = [int(x) for x in input().split()]
	ans = [0 for _ in range(len(seq))]
	m = 0
	cmap = {}
	for i in range(len(seq)):
		for (c, p) in enumerate(pr):
			if seq[i] % p == 0:
				if c not in cmap:
					m += 1
					cmap[c] = str(m)
				ans[i] = cmap[c]
				break
	print(m)
	print(' '.join((x for x in ans)))


import sys
readline = sys.stdin.readline

def prsh(N):
	prime = [2]
	for L in range(3, N):
		for p in prime:
			if not L % p:
				break
			if p > L ** (1 / 2):
				prime.append(L)
				break
	return prime
PRIME = prsh(32)
pn = 11
T = int(readline())
Ans = [None] * T
for qu in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	col = [0] * N
	used = [False] * pn
	for i in range(N):
		a = A[i]
		for j in range(pn):
			pr = PRIME[j]
			if not a % pr:
				col[i] = j
				used[j] = True
				break
		else:
			assert False, 'cannot find a divisor'
	ncol = [0] * pn
	cnt = 0
	for j in range(pn):
		if used[j]:
			cnt += 1
			ncol[j] = cnt
	ans = [ncol[c] for c in col]
	Ans[qu] = str(cnt) + '\n' + ' '.join(map(str, ans))
print('\n'.join(Ans))


prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	ind = 0
	flag = [0] * 13
	c = 0
	for i in range(n):
		for j in range(len(prime)):
			if arr[i] % prime[j] == 0:
				if flag[j] == 0:
					ind += 1
					flag[j] = ind
					ans.append(ind)
				else:
					ans.append(flag[j])
				break
	print(ind)
	print(*ans)


def minpr(a):
	for i in range(2, a):
		if a % i == 0:
			return i
t = int(input())
for _ in range(t):
	l = int(input())
	arr = list(map(int, input().split()))
	count = 1
	d = {}
	for i in range(l):
		arr[i] = minpr(arr[i])
		if arr[i] not in d:
			d[arr[i]] = count
			count += 1
	for i in range(l):
		arr[i] = d[arr[i]]
	print(max(arr))
	print(*arr, sep=' ')


for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	lst = [0] * n
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
	color = 1
	for i in range(15):
		f = 0
		for j in range(n):
			if lst[j] == 0:
				if a[j] % prime[i] == 0:
					lst[j] = color
					f = 1
		if f == 1:
			color += 1
	print(len(set(lst)))
	print(*lst)


p = set()
for i in range(2, 1001):
	ok = True
	for j in range(2, int(i ** 0.5) + 1):
		if i % j == 0:
			ok = False
			break
	if ok:
		p.add(i)
first11Primes = sorted(list(p))[:11]
getColour = [-1 for _ in range(1001)]
for i in range(4, 1001):
	for j in range(len(first11Primes)):
		if i % first11Primes[j] == 0:
			getColour[i] = j
			break
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	usedColours = set()
	for x in a:
		usedColours.add(getColour[x])
	usedColours = sorted(list(usedColours))
	mapp = dict()
	j = 1
	for co in usedColours:
		mapp[co] = j
		j += 1
	ans = [-1 for __ in range(n)]
	for i in range(n):
		ans[i] = mapp[getColour[a[i]]]
	print(j - 1)
	print(' '.join([str(x) for x in ans]))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		r = [0] * n
		c = 1
		for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
			u = False
			for i in range(n):
				if r[i] == 0 and a[i] % p == 0:
					r[i] = c
					u = True
			if u:
				c += 1
		rr.append(c - 1)
		rr.append(JA(r, ' '))
	return JA(rr, '\n')
print(main())


t = int(input())
d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(t):
	dic = dict()
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	s = set()
	for i in a:
		for j in d:
			if i % j == 0:
				if j not in dic:
					dic[j] = len(dic) + 1
				ans.append(dic[j])
				s.add(j)
				break
	print(len(s))
	for i in ans:
		print(i, end=' ')
	print()


from collections import defaultdict

def getfactors(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return i
for _ in range(int(input())):
	n = int(input())
	d = defaultdict(list)
	arr = [int(num) for num in input().split(' ')]
	v = set()
	k = 1
	res = [0] * n
	for i in range(n):
		if i not in v:
			x = getfactors(arr[i])
			for j in range(n):
				if j not in v and arr[j] % x == 0:
					res[j] = k
					v.add(j)
			k = k + 1
	print(k - 1)
	for item in res:
		print(item, end=' ')
	print('')


import math

def get_smallest_prime_divisor(n):
	for i in range(2, n):
		if n % i == 0:
			return i
	return -1
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	v = [int(x) for x in input().split()]
	f = [False for i in range(11)]
	clr = []
	for i in range(n):
		x = primes.index(get_smallest_prime_divisor(v[i]))
		f[x] = True
		clr.append(x)
	cnt = 0
	num = []
	for i in range(11):
		num.append(cnt)
		if f[i]:
			cnt += 1
	print(cnt)
	for i in range(n):
		x = primes.index(get_smallest_prime_divisor(v[i]))
		print(num[x] + 1, end=' ')
	print()


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
while t:
	t -= 1
	n = int(input())
	res = []
	tracker = [False for x in range(11)]
	nums = list((int(x) for x in input().split()))
	for num in nums:
		for (i, p) in enumerate(primes):
			if num % p == 0:
				tracker[i] = True
				break
	count = 0
	tracker2 = [-1 for x in range(11)]
	for i in range(11):
		if tracker[i]:
			count += 1
			tracker2[i] = count
	for num in nums:
		for (i, p) in enumerate(primes):
			if num % p == 0:
				res.append(tracker2[i])
				break
	print(count)
	for x in res:
		print(x, ' ', end='')


class P1332B:

	def solve(self, a):
		primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)
		m = 1
		color = [-1 for _ in range(len(a))]
		for p in primes:
			update = False
			for (i, ai) in enumerate(a):
				if color[i] == -1 and ai % p == 0:
					color[i] = m
					update = True
			if update:
				m += 1
		m -= 1
		return (m, color)
t = int(input())
for _ in range(t):
	n = int(input())
	a = tuple(map(int, input().split()))
	sol = P1332B().solve(a)
	print(sol[0])
	s = ''
	for c in sol[1]:
		s += str(c) + ' '
	print(s)


from math import gcd
from collections import defaultdict

def prime(n):
	ans = set()
	if n % 2 == 0:
		ans.add(2)
		n = n // 2
	while n % 2 == 0:
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			ans.add(i)
		while n % i == 0:
			n = n // i
	return ans
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499]
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(list)
	ans = [0] * n
	for i in range(n):
		temp = prime(a[i])
		for j in primes:
			if j in temp:
				d[j].append([a[i], i])
				break
	m = 1
	for k in d:
		for j in d[k]:
			ans[j[1]] = m
		m += 1
	print(m - 1)
	print(' '.join(map(str, ans)))


T = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for kk in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 10002
	ans = 0
	for i in range(11):
		col = False
		for j in a:
			if c[j] == 0 and j % p[i] == 0:
				c[j] = ans + 1
				col = True
		if col:
			ans = ans + 1
	print(ans)
	j = 0
	for i in a:
		j = j + 1
		if j == n:
			print(c[i])
		else:
			print(c[i], end=' ')


def main():
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	n = int(input())
	a = []
	a = list(map(int, input().split()))
	dp = []
	dp = [-1 for _ in range(len(primes))]
	cnt = 0
	for i in range(len(a)):
		for j in range(len(primes)):
			if a[i] % primes[j] == 0:
				if dp[j] == -1:
					cnt += 1
					dp[j] = cnt
				a[i] = dp[j]
				break
	print(cnt)
	for x in a:
		print(x, end=' ')
t = int(input())
while t:
	main()
	print()
	t -= 1


def solve(array):
	current = 1
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = [-1 for i in range(len(array))]
	for prime in primes:
		used = False
		for i in range(len(array)):
			if ans[i] == -1:
				if array[i] % prime == 0:
					ans[i] = current
					used = True
		if used:
			current += 1
	print(current - 1)
	print(*ans)
x = int(input())
while x > 0:
	_ = input()
	array = list(map(int, input().split()))
	solve(array)
	x -= 1


l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	div = {}
	col = [0] * n
	m = 1
	a = list(map(int, input().split()))
	for j in range(11):
		for i in range(n):
			if a[i] % l[j] == 0 and col[i] == 0:
				col[i] = m
				div[l[j]] = m
				m += 1
				break
	for i in range(n):
		for j in range(len(l)):
			if a[i] % l[j] == 0 and col[i] == 0:
				col[i] = div[l[j]]
				break
	print(max(col))
	print(' '.join((str(item) for item in col)))


from math import floor, ceil
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	usedPrimes = set()
	ans = [0] * len(a)
	for (i, e) in enumerate(a):
		for prime in p:
			if e % prime == 0:
				ans[i] = -prime
				usedPrimes.add(prime)
				break
	up = list(usedPrimes)
	for (color, prime) in enumerate(up, 1):
		for i in range(len(a)):
			if ans[i] == -prime:
				ans[i] = color
	print(len(up))
	print(' '.join(map(str, ans)))


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 isprime(n):
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1
n = 2
prime = []
while 1:
	if isprime(n):
		prime.append(n)
	n += 1
	if len(prime) == 50:
		break

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		x1 = [0] * n
		c = 1
		for i in range(11):
			x = prime[i]
			for j in range(n):
				if x1[j] != 0:
					continue
				if a[j] % x == 0:
					x1[j] = c
			c += 1
		print(len(set(x1)))
		x2 = x1[:]
		x2 = list(set(x2))
		m = {}
		c = 1
		for i in x2:
			m[i] = c
			c += 1
		for i in x1:
			print(m[i], end=' ')
		print()
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	used = [0] * 11
	cur = 1
	c = [0] * n
	for j in range(n):
		f = 0
		for k in range(11):
			if not f and a[j] % d[k] == 0:
				f = 1
				if used[k] == 0:
					used[k] = cur
					cur += 1
				c[j] = used[k]
	print(cur - 1)
	print(*c)


import sys
input = sys.stdin.readline
LI = lambda : list(map(int, input().strip('\n').split()))
MI = lambda : map(int, input().strip('\n').split())
SI = lambda : input().strip('\n')
II = lambda : int(input().strip('\n'))
for _ in range(II()):
	n = II()
	a = LI()
	clr = {}
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = 1
	for p in primes:
		cur = False
		for v in a:
			if v % p == 0 and (not clr.get(v, False)):
				clr[v] = ans
				cur = True
		if cur:
			ans += 1
	print(ans - 1)
	for v in a:
		print(clr[v], end=' ')
	print()


t = int(input())
sosu = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	ans2 = 0
	for i in range(n):
		for j in range(11):
			if a[i] % sosu[j] == 0:
				ans.append(j + 1)
				ans2 = max(j + 1, ans2)
				break
	used = [1] * ans2
	for x in ans:
		used[x - 1] = 0
	for i in range(ans2 - 1):
		used[i + 1] += used[i]
	for i in range(n):
		ans[i] -= used[ans[i] - 1]
	print(ans2 - used[-1])
	print(*ans)


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def slv(a):
	cd = {}
	ans = []
	for i in a:
		for pp in p:
			if i % pp == 0:
				if pp not in cd:
					cd[pp] = len(cd) + 1
				ans.append(cd[pp])
				break
	print(len(cd))
	print(' '.join([str(i) for i in ans]))
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	slv(a)


t = int(input())
while t:
	n = int(input())
	a = input().split()
	a = list(map(lambda x: int(x), a))
	d = {}
	for i in range(n):
		j = 2
		while j * j <= a[i]:
			if a[i] % j == 0:
				break
			j += 1
		if j not in d:
			d[j] = []
		d[j].append(i)
	ans = [0 for i in range(n)]
	c = 1
	for key in d:
		for idx in d[key]:
			ans[idx] = c
		c += 1
	print(c - 1)
	for i in ans:
		print(i, end=' ')
	print()
	t -= 1


spf = [0] * 1001

def sieve():
	spf[1] = 1
	for i in range(2, 1001):
		spf[i] = i
	for i in range(4, 1001, 2):
		spf[i] = 2
	i = 3
	while i * i < 1001:
		if spf[i] == i:
			for j in range(i * i, 1001, i):
				if spf[j] == j:
					spf[j] = i
		i = i + 1
sieve()
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = input()
	A = list(map(int, list(a.split())))
	vis = [0] * n
	ta = [0] * n
	for i in range(n):
		ta[i] = spf[A[i]]
	c = 0
	for i in range(n):
		if vis[i] == 0:
			c = c + 1
			vis[i] = c
			for j in range(i + 1, n):
				if spf[A[j]] == spf[A[i]]:
					vis[j] = c
	d = {}
	e = 0
	for i in range(n):
		if vis[i] not in d:
			d[vis[i]] = 1
			e = e + 1
	print(e)
	for i in vis:
		print(i, end=' ')
	print()


from sys import stdin, stdout
import math
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(stdin.readline())
for test in range(t):
	n = int(stdin.readline())
	arr = [int(x) for x in stdin.readline().split()]
	ans = [-1] * n
	count = 1
	for i in range(11):
		check = False
		for j in range(n):
			if ans[j] == -1:
				if arr[j] % primes[i] == 0:
					ans[j] = count
					check = True
		if check == True:
			count += 1
	stdout.write(str(count - 1) + '\n')
	print(*ans, sep=' ')


def find_colour(n):
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in range(n):
		if n % primes[i] == 0:
			return i + 1
	return False

def solve():
	n = int(input())
	numbers = [int(x) for x in input().split()]
	answers = []
	colours = set()
	for i in numbers:
		c = find_colour(i)
		colours.add(c)
		answers.append(c)
	colours = list(colours)
	k = len(colours)
	transpose = dict()
	for i in range(k):
		transpose[colours[i]] = i + 1
	for i in range(n):
		answers[i] = transpose[answers[i]]
	return answers + [k]
t = int(input())
for case in range(t):
	answer = solve()
	print(answer.pop())
	print(*answer)


import math
import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	col = [0] * n
	prim = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	cur = 1
	for k in range(len(prim)):
		cnt = 0
		for j in range(n):
			if col[j] == 0 and arr[j] % prim[k] == 0:
				col[j] = cur
				cnt += 1
		if cnt > 0:
			cur += 1
	print(max(col))
	print(*col)


a = int(input())
for _ in range(a):
	b = int(input())
	c = [int(i) for i in input().split()]
	d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	e = []
	ans = []
	for i in c:
		for j in d:
			if i % j == 0:
				if not j in e:
					ans.append(str(len(e) + 1))
					e.append(j)
				else:
					ans.append(str(e.index(j) + 1))
				break
	print(len(e))
	print(' '.join(ans))


t = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def getPrime(num):
	for i in range(0, 11):
		prime = primes[i]
		if num % prime == 0:
			return prime
for _ in range(t):
	n = int(input())
	al = list(map(int, input().split()))
	primeused = []
	for i in range(len(al)):
		x = getPrime(al[i])
		if x not in primeused:
			primeused.append(x)
	ans = [0] * n
	for i in range(n):
		x = getPrime(al[i])
		ind = primeused.index(x)
		ans[i] = ind + 1
	print(len(primeused))
	for i in range(n - 1):
		print(ans[i], end=' ')
	print(ans[-1])


import math

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors
t = input()
for i in range(int(t)):
	n = input()
	n = int(n)
	a_list_string = input()
	a_list = a_list_string.split(' ')
	a_list = [int(j) for j in a_list]
	prime_list = [prime_factors(k) for k in a_list]
	counts = dict()
	for i in prime_list:
		for j in i:
			if j not in counts:
				counts[j] = 0
			else:
				counts[j] += 1
	color_dict = dict()
	for i in range(1, 12):
		color_dict[i] = []
	color_map = []
	for i in range(len(prime_list)):
		c = 0
		for color in range(1, 12):
			if len(color_dict[color]) == 0:
				c = color
			else:
				for prime in prime_list[i]:
					if prime in color_dict[color]:
						c = color
						break
			if c != 0:
				color_map.append(c)
				if len(color_dict[color]) == 0:
					color_dict[color].append(min(prime_list[i]))
				break
	tot = 0
	for entry in color_dict:
		if len(color_dict[entry]) != 0:
			tot += 1
	s = ' '.join((str(x) for x in color_map))
	print(tot)
	print(s)


t = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	track = 1
	for p in primes:
		flag = 0
		for i in range(n):
			if a[i] % p == 0:
				if b[i] == 0:
					b[i] = track
					flag = 1
		if flag:
			track += 1
	print(len(list(set(b))))
	print(*b)


import sys

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

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

def func():
	(n, m) = maps()
	if n > m + 1 or m > 2 * (n + 1):
		print(-1)
	elif n == m:
		print('10' * n)
	elif n == m + 1:
		print('01' * m + '0')
	elif 2 * n + 2 == m:
		print('110' * n + '11')
	else:
		t = m - n - 1
		print('110' * t + '10' * (n - t) + '1')
from collections import defaultdict

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res
pr = prime_list(int(1000 ** 0.5) + 1)
for _ in range(*maps()):
	(n,) = maps()
	a = [*maps()]
	occ = [0] * n
	for i in range(n):
		for j in range(11):
			if a[i] % pr[j] == 0:
				occ[i] = j + 1
				break
	print(len(set(occ)))
	d = defaultdict(list)
	for i in range(n):
		d[occ[i]].append(i)
	idx = 1
	for i in d:
		for j in d[i]:
			occ[j] = idx
		idx += 1
	print(*occ)


I = input
for _ in [0] * int(I()):
	I()
	m = 0
	d = {}
	c = []
	for x in I().split():
		p = next((p for p in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31) if int(x) % p < 1))
		if (p in d) < 1:
			m += 1
			d[p] = m
		c += (d[p],)
	print(m, *c)


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

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

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

def main():
	n = aint()
	l = lint()
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = [None] * n
	color = [0] * 11
	c = 0
	for i in range(n):
		for j in range(11):
			if l[i] % primes[j] == 0:
				if color[j] == 0:
					c += 1
					color[j] = c
				ans[i] = color[j]
				break
	print(c)
	print(*ans)
t = int(input())
for i in range(t):
	main()


import sys
input = sys.stdin.readline
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		for j in range(11):
			if arr[i] % primes[j] == 0:
				arr[i] = j + 1
				break
	S = set(arr)
	m = len(S)
	d = {s: i for (i, s) in enumerate(S, 1)}
	print(m)
	print(*[d[l] for l in arr])


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	ansli = [0] * n
	col = 1
	for i in range(len(primes)):
		boo = False
		for j in range(n):
			if ansli[j] == 0:
				if li[j] % primes[i] == 0:
					ansli[j] = col
					boo = True
		if boo:
			col += 1
	print(max(ansli))
	for i in ansli:
		print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	c = [0] * n
	r = 1
	for i in range(2, 1001):
		f = 0
		for j in range(n):
			if c[j] == 0 and a[j] % i == 0:
				c[j] = r
				f = 1
		if f == 1:
			r += 1
	print(r - 1)
	print(*c)


def factors(a):
	m = []
	i = 1
	while i <= a:
		if a % i == 0:
			m.append(i)
		i += 1
	return m

def common(a, b):
	c = 0
	for i in a:
		if i in b:
			c += 1
	if c > 1:
		return True
	return False
t = int(input())
for q in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = []
	for i in l:
		m.append(factors(i))
	count = 1
	colors = [0] * n
	prime = []
	for i in m:
		prime.append(i[1])
	nums = sorted(list(set(prime)))
	count = 1
	pos = 0
	while 0 in colors:
		for i in range(0, len(prime)):
			if prime[i] == nums[pos]:
				colors[i] = count
		count += 1
		pos += 1
	print(count - 1)
	y = ''
	for i in colors:
		y += str(i)
		y += ' '
	print(y)


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

def main():
	test = int(input())
	for t in range(test):
		n = int(input())
		l = [int(i) for i in input().split(' ')]
		c = [0 for i in range(len(l))]
		num = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
		color = 1
		col = 1
		for j in range(len(num)):
			flag = False
			for i in range(len(l)):
				if c[i] == 0:
					if l[i] % num[j] == 0:
						c[i] = col
						flag = True
			if flag:
				color = col
				col += 1
		cl = c.count(0)
		if cl < 11 - color:
			for i in range(len(c)):
				if c[i] == 0:
					color += 1
					c[i] = color
		print(color)
		for i in c:
			print(i, end=' ')
		print()
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n <= 11:
		color = list(set(range(1, n + 1)))
		print(n)
		print(*color)
	else:
		d = {}
		output = []
		prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
		for i in arr:
			for j in prime:
				if i % j == 0:
					if j not in d:
						d[j] = len(d) + 1
					output.append(d[j])
					break
		print(len(d))
		print(*output)


t = int(input())
sin_usar = []
usar = []
primos = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
dif = []
mostrar = []
for i in range(0, t):
	c = int(input())
	d = input()
	b = ''
	for i in range(0, c):
		sin_usar.append(d.split(' ')[i])
	for i in range(0, c):
		for j in range(0, len(primos)):
			if int(sin_usar[i]) % int(primos[j]) == 0:
				sin_usar[i] = int(primos[j])
	for i in sin_usar:
		if i not in dif:
			dif.append(i)
	for i in range(0, len(sin_usar)):
		for j in range(0, len(dif)):
			if sin_usar[i] == dif[j]:
				usar.append(j + 1)
	for i in range(0, len(usar)):
		b += str(usar[i]) + ' '
	mostrar.append(len(dif))
	mostrar.append(b)
	sin_usar = []
	usar = []
	dif = []
for i in range(0, len(mostrar)):
	print(mostrar[i])


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = [-1] * n
	curr_col = 1
	for p in prime:
		got = 0
		for i in range(n):
			if ans[i] != -1:
				continue
			if arr[i] % p != 0:
				continue
			got = 1
			ans[i] = curr_col
		if got == 1:
			curr_col += 1
	print(curr_col - 1)
	for i in ans:
		print(i, end=' ')
	print()


import math as m
import string

def f1():
	T = int(input())
	while T != 0:
		T = T - 1
		ARRAY1 = [int(i) for i in input().split(' ')]
		ARRAY2 = [int(i) for i in input().split(' ')]
		(L, R, D, U) = (ARRAY1[0], ARRAY1[1], ARRAY1[2], ARRAY1[3])
		(x, y) = (ARRAY2[0], ARRAY2[1])
		(x1, y1) = (ARRAY2[2], ARRAY2[3])
		(x2, y2) = (ARRAY2[4], ARRAY2[5])
		Flag1 = True
		Flag2 = False
		Flag1 = h1(U, D, y, y2, y1)
		Flag2 = h1(R, L, x, x2, x1)
		if Flag1 == True and Flag2 == True:
			print('YES')
		else:
			print('NO')

def h1(U, D, cy, y2, y1):
	Flag1 = True
	while U > 0 and D > 0:
		if y2 - cy > 0 and U > 0:
			if y2 - cy >= U:
				cy = cy + U
				U = 0
			else:
				U = U - (y2 - cy)
				cy = y2
		if cy - y1 > 0 and D > 0:
			if cy - y1 >= D:
				cy = cy - D
				D = 0
			else:
				D = D - (cy - y1)
				cy = y1
		if U == 0 and D != 0 and (cy - y1 < D):
			Flag1 = False
			break
		if D == 0 and U != 0 and (y2 - cy < U):
			Flag1 = False
			break
		if y2 - cy == 0 and cy - y1 == 0:
			if D > 0 or U > 0:
				Flag1 = False
				break
	return Flag1

def f2():
	T = int(input())
	while T != 0:
		T = T - 1
		N = int(input())
		ARRAY = [int(i) for i in input().split(' ')]
		ARR = [-1 for i in range(0, len(ARRAY))]
		CHECKER = [False] * N
		MAXELEMENT = max(ARRAY)
		Counter = len(ARRAY)
		Primes = GetPrimes(MAXELEMENT)
		Colour = 0
		Flag = False
		for i in range(2, len(Primes)):
			if Counter == 0:
				break
			if Primes[i] == True:
				Prime = i
				Flag = False
				Colour = Colour + 1
				for j in range(0, len(ARRAY)):
					if CHECKER[j] == True:
						continue
					if ARRAY[j] % Prime == 0:
						Flag = True
						ARR[j] = Colour
						CHECKER[j] = True
						Counter = Counter - 1
				if Flag == False:
					Colour = Colour - 1
		print(Colour)
		for i in range(0, len(ARR)):
			print(ARR[i], end=' ')
		print()

def GetPrimes(MAXELEMENT):
	ARRAY = [-1 for i in range(0, MAXELEMENT)]
	for i in range(0, MAXELEMENT):
		Number = i
		if Number == 1 or Number == 0:
			continue
		if ARRAY[i] == False:
			continue
		ARRAY[i] = True
		j = 2
		X = Number * j
		while X < MAXELEMENT:
			ARRAY[X] = False
			j = j + 1
			X = Number * j
	return ARRAY

def GCD(x, y):
	if x == 0:
		return y
	else:
		ans = GCD(y % x, x)
		return ans

def f3():
	T = int(input())
	ARRAY = [int(i) for i in input().split(' ')]
f2()


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	currno = 1
	d = {}
	mt = 0
	for i in l:
		for k in range(0, 11):
			j = p[k]
			if i % j == 0:
				if d.get(j, -1) == -1:
					d[j] = currno
					ans.append(currno)
					currno += 1
				else:
					ans.append(d[j])
				break
	m = len(d.keys())
	print(m)
	s = ''
	for i in ans:
		s += str(i) + ' '
	s.strip()
	print(s)


from sys import *
from math import *
from bisect import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	d = {}
	b = [0] * n
	x = 1
	for i in range(n):
		for j in range(11):
			if a[i] % p[j] == 0:
				if p[j] in d:
					b[i] = d[p[j]]
				else:
					b[i] = x
					d[p[j]] = x
					x += 1
				break
	print(max(b))
	print(*b)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	for i in range(n):
		for j in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31):
			if a[i] % j == 0:
				ans.append(j)
				break
	dc = defaultdict(int)
	cnt = 0
	for i in range(n):
		if dc[ans[i]]:
			ans[i] = dc[ans[i]]
		else:
			cnt += 1
			dc[ans[i]] = cnt
			ans[i] = cnt
	print(cnt)
	print(*ans)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def f():
	n = int(input())
	A = [int(s) for s in input().split()]
	tags = {p: 0 for p in primes}
	tg = 0
	for i in range(n):
		for p in primes:
			if not A[i] % p:
				if not tags[p]:
					tg += 1
					tags[p] = tg
				A[i] = tags[p]
				break
	print(tg)
	print(' '.join((str(a) for a in A)))
for t in range(int(input())):
	f()


import io
import os
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def primefactors(n):
	factorization = []
	while n % 2 == 0:
		factorization.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			factorization.append(i)
			n = n // i
	if n > 2:
		factorization.append(n)
	return sorted(factorization)
t = int(input())
for tc in range(t):
	n = int(input())
	lst = [int(z) for z in input().split()]
	primefactorizations = {}
	factors = []
	for i in range(n):
		primefactorizations[i] = min(primefactors(lst[i]))
		factors.append(min(primefactors(lst[i])))
	factors = list(set(factors))
	m = len(set(factors))
	fin = [-1 for c in range(n)]
	for x in range(m):
		for y in range(n):
			if primefactorizations[y] == factors[x]:
				fin[y] = str(x + 1)
	print(m)
	print(' '.join(fin))


t = int(input())
for i in range(t):
	a = int(input())
	l = list(map(int, input().split()))
	d = []
	c = []
	m = []
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for j in l:
		for k in p:
			if j % k == 0:
				if k in d:
					c.append(d.index(k) + 1)
				else:
					d.append(k)
					c.append(d.index(k) + 1)
				if p.index(k) not in m:
					m.append(p.index(k))
				break
	print(len(m))
	print(*c)


import math as mt
MAXN = 1001
spf = [0 for i in range(MAXN)]

def sieve():
	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, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
sieve()
for _ in range(int(input())):
	n = int(input())
	c = [0 for i in range(n)]
	a = list(map(int, input().split()))
	m = 0
	r = {}
	for i in range(n):
		if r.get(spf[a[i]], 0) == 0:
			m += 1
			c[i] = m
			r[spf[a[i]]] = m
		else:
			c[i] = r[spf[a[i]]]
	print(m)
	for i in c:
		print(i, end=' ')
	print('')


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

def seive():
	p = 2
	while p * p < 1001:
		if prime[p]:
			for i in range(p * p, 1001, p):
				if prime[i]:
					prime[i] = not prime[i]
					sp[i] = p
		p += 1
for _ in range(int(ri())):
	n = int(ri())
	a = RI()
	sp = [i for i in range(1001)]
	prime = [True] * 1001
	seive()
	ite = 1
	dic = {}
	ans = [0] * n
	for i in range(len(a)):
		if sp[a[i]] in dic:
			ans[i] = dic[sp[a[i]]]
		else:
			dic[sp[a[i]]] = ite
			ans[i] = ite
			ite += 1
	print(ite - 1)
	print(*ans)


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

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(I()):
	n = I()
	a = L()
	d = [0] * n
	ss = set()
	for i in range(n):
		for j in range(2, 33):
			if a[i] % j == 0:
				d[i] = j
				ss.add(j)
				break
	q = [0] * 33
	cnt = 1
	for i in ss:
		q[i] = cnt
		cnt += 1
	print(max([q[d[i]] for i in range(n)]))
	print(*[q[d[i]] for i in range(n)])


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input().split()]
	ans = [0] * n
	m = 1
	for i in p:
		val = False
		for j in range(len(arr)):
			if ans[j] == 0 and arr[j] % i == 0:
				ans[j] = m
				val = True
		if val:
			m += 1
	print(max(ans))
	print(*ans)


printn = lambda x: print(x, end='')
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
ins = lambda : input().strip()
DBG = True
BIG = 10 ** 18
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
import math

def prime_division2(x):
	q = int(math.sqrt(x))
	h = {}
	for i in range(2, q + 1):
		ex = 0
		while x % i == 0:
			ex += 1
			x //= i
		if ex > 0:
			h[i] = ex
	if x > q:
		h[x] = 1
	return h
prs = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = inn()
for tt in range(t):
	n = inn()
	a = inl()
	use = [False] * 32
	col = []
	for x in a:
		f = prime_division2(x)
		for p in prs:
			if p in f:
				use[p] = True
				col.append(p)
				break
	m = len(set(col))
	num = [0] * 32
	i = 1
	for p in prs:
		if p in col:
			num[p] = i
			i += 1
	ans = [num[x] for x in col]
	print(m)
	pad = ''
	for x in ans:
		printn(pad + str(x))
		pad = ' '
	print('')


x = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = [0] * n
	for i in range(n):
		for j in range(len(x)):
			if l[i] % x[j] == 0:
				m[i] = j + 1
	s = set(m)
	print(len(s))
	d = {x: y for (y, x) in enumerate(s, 1)}
	for i in m:
		print(d[i], end=' ')
	print()


t = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
for tc in range(t):
	n = int(input())
	li = [int(inp) for inp in input().split(' ')]
	c = set()
	s = ''
	color = [-1 for i in range(len(primes))]
	nextcolor = 1
	for num in li:
		for (i, prime) in enumerate(primes):
			if num % prime == 0:
				if color[i] == -1:
					color[i] = nextcolor
					nextcolor += 1
				s += str(color[i]) + ' '
				c.add(i)
				break
	print(len(c))
	print(s)


from sys import stdin
input = stdin.readline

def A():
	t = int(input())
	for _ in range(t):
		(a, b, c, d) = map(int, input().split())
		(x, y, x1, y1, x2, y2) = map(int, input().split())
		netr = b - a
		netu = d - c
		if x1 == x2 and (a > 0 or b > 0):
			print('No')
			continue
		if y1 == y2 and (c > 0 or d > 0):
			print('No')
			continue
		if netr + x < x1 or netr + x > x2:
			print('No')
			continue
		if netu + y < y1 or netu + y > y2:
			print('No')
			continue
		print('Yes')

def B():
	t = int(input())
	for _ in range(t):
		m = int(input())
		a = list(map(int, input().split()))
		c = [0] * m
		p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
		used = [False] * 11
		for i in range(m):
			j = 0
			while a[i] % p[j] != 0:
				j += 1
			used[j] = True
			c[i] = j
		used[0] = int(used[0])
		for i in range(1, 11):
			used[i] = int(used[i]) + used[i - 1]
		for i in range(m):
			c[i] = used[c[i]]
		print(max(used))
		print(*c)
B()


import math
maxn = 1000
im = [-1] * (maxn + 1)
bs = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in reversed(bs):
	im[i] = i
	for j in range(i + 1, maxn + 1):
		if j % i == 0:
			im[j] = i

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	for i in a:
		if im[i] not in d:
			d[im[i]] = len(d) + 1
	print(len(d))
	print(*(d[im[i]] for i in a))
t = int(input())
for _ in range(t):
	solve()


t = int(input())
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [11] * n
	cnt = 1
	for i in range(11):
		flag = False
		for j in range(n):
			if a[j] % prime[i] == 0:
				flag = True
				ans[j] = min(cnt, ans[j])
		if flag:
			cnt += 1
	for i in range(max(ans) - 1, 0, -1):
		if i not in ans:
			for j in range(n):
				if ans[j] > i:
					ans[j] -= 1
	print(max(ans))
	print(*ans)


import math

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

def rList():
	return list(map(int, input().split()))
t = int(input())
for i in range(t):
	n = int(input())
	a = rList()
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	d = {}
	ans = [0] * n
	temp = 1
	for i in range(n):
		for j in range(11):
			if a[i] % prime[j] == 0:
				if prime[j] not in d:
					d[prime[j]] = temp
					temp += 1
				ans[i] = d[prime[j]]
				break
	print(len(set(ans)))
	print(*ans)


import sys
input = sys.stdin.readline
import math

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		A = [int(x) for x in input().split()]
		ans = []
		ansc = set()
		x = [0] * 12
		for a in A:
			if a % 2 == 0:
				if x[1] == 0:
					x[1] = len(ansc) + 1
				ans.append(x[1])
				ansc.add(x[1])
			elif a % 3 == 0:
				if x[2] == 0:
					x[2] = len(ansc) + 1
				ans.append(x[2])
				ansc.add(x[2])
			elif a % 5 == 0:
				if x[3] == 0:
					x[3] = len(ansc) + 1
				ans.append(x[3])
				ansc.add(x[3])
			elif a % 7 == 0:
				if x[4] == 0:
					x[4] = len(ansc) + 1
				ans.append(x[4])
				ansc.add(x[4])
			elif a % 11 == 0:
				if x[5] == 0:
					x[5] = len(ansc) + 1
				ans.append(x[5])
				ansc.add(x[5])
			elif a % 13 == 0:
				if x[6] == 0:
					x[6] = len(ansc) + 1
				ans.append(x[6])
				ansc.add(x[6])
			elif a % 17 == 0:
				if x[7] == 0:
					x[7] = len(ansc) + 1
				ans.append(x[7])
				ansc.add(x[7])
			elif a % 19 == 0:
				if x[8] == 0:
					x[8] = len(ansc) + 1
				ans.append(x[8])
				ansc.add(x[8])
			elif a % 23 == 0:
				if x[9] == 0:
					x[9] = len(ansc) + 1
				ans.append(x[9])
				ansc.add(x[9])
			elif a % 29 == 0:
				if x[10] == 0:
					x[10] = len(ansc) + 1
				ans.append(x[10])
				ansc.add(x[10])
			elif a % 31 == 0:
				if x[11] == 0:
					x[11] = len(ansc) + 1
				ans.append(x[11])
				ansc.add(x[11])
		print(len(ansc))
		print(*ans)
main()


from collections import defaultdict
primes = set()
for i in range(2, 1000):
	x = i
	j = 2
	f = 1
	while j * j <= x:
		if x % j == 0:
			f = 0
			break
		j += 1
	if x > 1 and f:
		primes.add(x)
primes = sorted(list(primes))
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = [0] * n
	for i in range(n):
		for j in range(len(primes)):
			if a[i] % primes[j] == 0:
				ans[i] = j + 1
				break
	d = defaultdict()
	m = 0
	for i in range(n):
		if ans[i] in d.keys():
			ans[i] = d[ans[i]]
		else:
			m += 1
			d[ans[i]] = m
			ans[i] = m
	print(len(d))
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	colors = list()
	r = [0] * len(l1)
	for i in range(2, 1000):
		a = 1
		for color in colors:
			if i % color == 0:
				a = 0
				break
		if a:
			colors.append(i)
			b = False
			for j in range(len(l1)):
				if l1[j] % i == 0 and (not r[j]):
					b = True
					r[j] = len(colors)
			if not b:
				colors.pop()
		if sum(map(bool, r)) == len(l1):
			break
	print(len(colors))
	print(' '.join(map(str, r)))


from sys import stdin
inp = stdin.readline
t = int(inp().strip())
for i in range(t):
	n = int(inp().strip())
	array = [int(x) for x in inp().strip().split()]
	primeNumbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	d = {}
	colorArray = [-1] * n
	usedCounter = 1
	for j in range(n):
		for k in range(11):
			if array[j] % primeNumbers[k] == 0:
				if d.get(primeNumbers[k], 0) == 0:
					d[primeNumbers[k]] = usedCounter
					usedCounter += 1
				colorArray[j] = d[primeNumbers[k]]
				break
	print(usedCounter - 1)
	print(*colorArray)


def newf(x):
	for i in range(2, int(x ** (1 / 2) + 1)):
		if x % i == 0:
			return i

def composite(n, a):
	colorsdic = {}
	colors = []
	for x in a:
		i = newf(x)
		if i in colorsdic:
			colors.append(colorsdic[i])
		else:
			colorsdic[i] = len(colorsdic) + 1
			colors.append(colorsdic[i])
	print(len(colorsdic))
	for p in colors:
		print(p, end=' ')
	print()
	return
t = int(input())
array = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	array.append([n, a])
for x in array:
	composite(*x)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def primefactor(n):
	for i in range(2, int(n ** 0.5 + 1)):
		if n % i == 0:
			return i
	return -1
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	indices = []
	for i in range(n):
		ind = primes.index(primefactor(a[i]))
		indices.append(ind)
	color = list(set(indices))
	for elem in indices:
		b.append(color.index(elem) + 1)
	print(len(color))
	print(*b)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	y = 0
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 2 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 3 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 5 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 7 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 11 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 13 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 17 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 19 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 23 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 29 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	czy = True
	for j in range(n):
		if b[j] == 0 and a[j] % 31 == 0:
			if czy:
				y = y + 1
				czy = False
			b[j] = y
	stri = ''
	for j in range(n):
		stri = stri + str(b[j]) + ' '
	print(y)
	print(stri)


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits

def read_line():
	return stdin.readline().strip()

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def solve():
	n = read_int()
	a = read_int_arr()
	f = collections.defaultdict(list)
	for (i, v) in enumerate(a):
		f[v].append(i)
	res = [0] * n
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
	c = 1
	for (i, p) in enumerate(primes, 1):
		to_rem = []
		for (k, v) in f.items():
			if k % p == 0:
				for idx in v:
					res[idx] = c
				to_rem.append(k)
		if len(to_rem) > 0:
			c += 1
		for k in to_rem:
			f.pop(k, None)
		if len(f) == 0:
			break
	print(max(res))
	print(*res, sep=' ')

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		solve()
main()


t = int(input())
parr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	oarr = []
	carr = []
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		for j in range(11):
			if arr[i] % parr[j] == 0:
				oarr += [parr[j]]
				if parr[j] not in carr:
					carr += [parr[j]]
				break
	print(len(carr))
	carr.sort()
	for i in range(len(oarr)):
		print(carr.index(oarr[i]) + 1, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	m = 0
	d = {}
	for i in range(n):
		for j in range(11):
			if a[i] % pr[j] == 0:
				if j in d:
					a[i] = d[j]
				else:
					m += 1
					a[i] = m
					d[j] = m
				break
	print(m)
	print(*a)


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')
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [0] * n
	t = 1
	for j in range(2, 1000):
		h = 0
		for k in range(n):
			if l[k] % j == 0 and ans[k] == 0:
				h = 1
				ans[k] = t
		if h == 1:
			t += 1
	s = set(ans)
	print(len(s))
	print(*ans, sep=' ')


prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
import math
a = int(input())
for i in range(a):
	s = int(input())
	ans = []
	z = list(map(int, input().split()))
	col = 1
	ans = [0 for i in range(len(z))]
	tam = [0 for i in range(11)]
	for i in range(len(prime)):
		for j in range(len(z)):
			if z[j] % prime[i] == 0:
				if ans[j] == 0:
					ans[j] = col
					tam[i] = 1
		if tam[i] == 1:
			col = col + 1
	x = tam.count(1)
	print(tam.count(1))
	for i in range(len(z)):
		for j in range(len(z)):
			if math.gcd(z[i], z[j]) == 1 and ans[i] == ans[j]:
				print(z[i], z[j])
	print(' '.join(map(str, ans)))


from math import sqrt
from collections import defaultdict as dd
import sys
input = sys.stdin.readline
from collections import defaultdict as dd, deque as dq
t = int(input())
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
while t:
	n = int(input())
	l = list(map(int, input().split()))
	ans = [0] * n
	co = 0
	d = dd(int)
	for i in range(n):
		for j in pr:
			if l[i] % j == 0:
				if d[j] == 0:
					co += 1
					d[j] = co
					ans[i] = d[j]
				else:
					ans[i] = d[j]
				break
	print(co)
	print(*ans)
	t -= 1


def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		b = []
		count = 0
		color = {}
		for i in a:
			j = 2
			while j * j <= i:
				if i % j == 0:
					b.append(j)
					if j not in color:
						count += 1
						color[j] = count
					break
				j += 1
		print(count)
		for i in b:
			print(color[i], end=' ')
		print()
main()


from sys import stdin, stdout
import collections as clcns
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	d = clcns.defaultdict(list)
	s = 0
	for i in range(n):
		for f in {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}:
			if a[i] % f == 0:
				d[f] += [i]
				break
	c = 1
	for (k, l) in d.items():
		for indices in l:
			a[indices] = c
		c += 1
	stdout.write(str(c - 1) + '\n')
	print(*a)


t = int(input())
for _ in range(t):
	n = int(input())
	A = [*map(int, input().split())]
	colors = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	color_idx = {}
	mx_idx = 1
	res = []
	for a in A:
		for c in colors:
			if not a % c:
				if c not in color_idx:
					color_idx[c] = mx_idx
					mx_idx += 1
				i = color_idx[c]
				res += (i,)
				break
	print(mx_idx - 1)
	print(' '.join(map(str, res)))


def canwalk(a, b, c, d, x, y, x1, y1, x2, y2):
	if x1 == x2 and (a > 0 or b > 0):
		return 'NO'
	if y1 == y2 and (c > 0 or d > 0):
		return 'NO'
	if b + abs(x - x1) >= a and a + abs(x - x2) >= b:
		if d + abs(y - y1) >= c and c + abs(y - y2) >= d:
			return 'YES'
	return 'NO'

def length(x):
	return len(x)
colors = [0, 0, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 4, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 4, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 4, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 4, 1, 5, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 4, 1, 2, 1, 0, 1, 0, 1, 2, 1, 5, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 4, 1, 0, 1, 2, 1, 0, 1, 6, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 5, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 4, 1, 3, 1, 2, 1, 5, 1, 0, 1, 2, 1, 3, 1, 4, 1, 2, 1, 6, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 6, 1, 2, 1, 0, 1, 5, 1, 2, 1, 0, 1, 4, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 4, 1, 7, 1, 2, 1, 0, 1, 3, 1, 2, 1, 6, 1, 4, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 5, 1, 2, 1, 7, 1, 3, 1, 2, 1, 4, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 5, 1, 4, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 8, 1, 2, 1, 3, 1, 0, 1, 2, 1, 4, 1, 0, 1, 2, 1, 6, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 7, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 6, 1, 2, 1, 5, 1, 0, 1, 2, 1, 4, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 4, 1, 2, 1, 0, 1, 0, 1, 2, 1, 8, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 5, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 4, 1, 2, 1, 5, 1, 3, 1, 2, 1, 0, 1, 6, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 7, 1, 2, 1, 4, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 4, 1, 2, 1, 3, 1, 5, 1, 2, 1, 0, 1, 0, 1, 2, 1, 7, 1, 9, 1, 2, 1, 6, 1, 3, 1, 2, 1, 4, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 8, 1, 4, 1, 2, 1, 0, 1, 6, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 4, 1, 5, 1, 2, 1, 0, 1, 8, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 6, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 4, 1, 3, 1, 2, 1, 7, 1, 0, 1, 2, 1, 3, 1, 4, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 5, 1, 2, 1, 0, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 9, 1, 2, 1, 5, 1, 0, 1, 2, 1, 0, 1, 4, 1, 2, 1, 0, 1, 3, 1, 2, 1, 6, 1, 0, 1, 2, 1, 3, 1, 7, 1, 2, 1, 0, 1, 8, 1, 2, 1, 4, 1, 0, 1, 2, 1, 9, 1, 3, 1, 2, 1, 0, 1, 4, 1, 2, 1, 3, 1, 0, 1, 2, 1, 7, 1, 0, 1, 2, 1, 5, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 4, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 4, 1, 2, 1, 6, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 8, 1, 5, 1, 2, 1, 3, 1, 0, 1, 2, 1, 4, 1, 6, 1, 2, 1, 0, 1, 7, 1, 2, 1, 5, 1, 3, 1, 2, 1, 0, 1, 0, 1, 2, 1, 3, 1, 8, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 4, 1, 3, 1, 2, 1, 0, 1, 10, 1, 2, 1, 3, 1, 4, 1, 2, 1, 9, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 3, 1, 2, 1, 5, 1, 6, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 0, 1, 2, 1, 0, 1, 4, 1, 2, 1, 8, 1, 3, 1, 2, 1, 10, 1, 7, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 5, 1, 2, 1, 4, 1, 0, 1, 2, 1, 6, 1, 3, 1, 2, 1, 0, 1, 4, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 9, 1, 2, 1, 0, 1, 6, 1, 2, 1, 0, 1, 3, 1, 2, 1, 4, 1, 11, 1, 2, 1, 3, 1, 0, 1, 2, 1, 0, 1, 4, 1, 2, 1, 0, 1, 5, 1, 2, 1, 0, 1, 3, 1, 2, 1, 9, 1, 0, 1, 2, 1, 3, 1, 0, 1, 2, 1]

def compositecoloring(x):
	ccolors = []
	for i in range(len(x)):
		ccolors.append(colors[x[i] - 2])
	for i in range(1, max(ccolors)):
		s = 0
		for j in range(len(ccolors)):
			if ccolors[j] == i:
				s += 1
		if s == 0:
			minc = 12
			for j in range(len(ccolors)):
				if ccolors[j] > i and minc > ccolors[j]:
					minc = ccolors[j]
			if minc == 12:
				break
			for j in range(len(ccolors)):
				if ccolors[j] == minc:
					ccolors[j] = i
	return ccolors
cases = int(input())
for _ in range(cases):
	l = int(input())
	x = list(map(int, input().split()))
	y = compositecoloring(x)
	print(max(y))
	print(*y)


t = int(input())
arr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0] * n
	k = 1
	flag = 0
	for i in arr:
		if flag == 1:
			k += 1
			flag = 0
		for j in range(n):
			if ans[j] == 0:
				if a[j] % i == 0:
					flag = 1
					ans[j] = k
	print(len(set(ans)))
	print(*ans)


from math import *

def sd_n(n):
	for i in range(n):
		if n % (i + 2) == 0:
			return i + 2
t = int(input())
m = []
nn = []
for i in range(t):
	nn.append(int(input()))
	x = list(map(int, input().split()))
	m.append(x)
flag = -1
for i in range(t):
	n = nn[i]
	s = m[i]
	SD = []
	k = [0] * n
	c = 0
	for j in range(n):
		SD.append(sd_n(s[j]))
	for jj in range(11):
		flag = 0
		for j in range(n):
			if k[j] == 0 and flag == 0:
				tmp = j
				flag = 1
				c = c + 1
			if SD[tmp] == SD[j] and flag == 1:
				k[j] = c
	print(c)
	print(*k, sep=' ')


import sys
input = lambda : sys.stdin.readline().strip()
ipnut = input
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(int(input())):
	n = int(ipnut())
	a = list(map(int, ipnut().split()))
	ans = []
	an = 1
	color = {}
	for i in a:
		ansv = 0
		for j in prime:
			ansv += 1
			if i % j == 0:
				if ansv not in color:
					color[ansv] = an
					an += 1
				break
		ans.append(color[ansv])
	print(an - 1)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	result = []
	prime = {2: 1, 3: 1, 5: 1, 7: 1, 11: 1, 13: 1, 17: 1, 19: 1, 23: 1, 29: 1, 31: 1}
	dec = {}
	t = 1
	for i in range(n):
		for j in prime:
			if a[i] % j == 0:
				if j in dec:
					result.append(dec[j])
				else:
					dec[j] = t
					t += 1
					result.append(dec[j])
				break
	print(t - 1)
	print(*result)


pr = []
for i in range(2, 500):
	for j in range(2, i):
		if i % j == 0:
			break
	else:
		pr.append(i)
t = int(input())
for q in range(t):
	m = 0
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0] * n
	for i in range(len(a)):
		if a[i] == 0:
			continue
		for j in pr:
			if a[i] % j != 0:
				continue
			a[i] = 0
			m += 1
			ans[i] = m
			for k in range(i + 1, n):
				if a[k] % j == 0 and a[k] != 0:
					ans[k] = m
					a[k] = 0
			break
	print(m)
	print(*ans)


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	l = I()
	c = [0] * n
	for i in range(n):
		for j in range(11):
			if l[i] % p[j] == 0:
				c[i] = j + 1
	print(len(set(c)))
	cn = 1
	f = {}
	for i in set(c):
		f[i] = cn
		cn += 1
	anss = [f[i] for i in c]
	print(*anss)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for i in range(t):
	n = int(input())
	numbers = [int(i) for i in input().split()]
	colored_primes = [-1] * 11
	colors = []
	color = 1
	for number in numbers:
		for i in range(len(primes)):
			if number % primes[i] == 0:
				if colored_primes[i] == -1:
					colored_primes[i] = color
					color = color + 1
				colors.append(colored_primes[i])
				break
	print(color - 1)
	for c in colors:
		print(c, end=' ')
	print()


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def fc(n):
	for p in primes:
		if n % p == 0:
			return p
	raise ValueError
for _ in range(int(input())):
	input()
	arr = list(map(int, input().split()))
	s = set()
	ps = []
	for e in arr:
		f = fc(e)
		s.add(f)
		ps.append(f)
	s = list(s)
	print(len(s))
	print(*[s.index(p) + 1 for p in ps])


t = int(input())
r = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	ind = dict()
	cc = 0
	r1 = [1] * n
	for i in range(n):
		for j in range(11):
			if a[i] % r[j] == 0:
				if r[j] not in ind:
					ind[r[j]] = cc + 1
					cc += 1
				r1[i] = ind[r[j]]
				break
	print(max(r1))
	print(*r1)


test = int(input())
for i in range(test):
	n = int(input())
	nums = [int(i) for i in input().split(' ')]
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	color = [0] * n
	col = 1
	for i in primes:
		flag = 0
		enter = 0
		for j in range(n):
			if color[j] == 0:
				enter = 1
				if nums[j] % i == 0:
					color[j] = col
					flag = 1
		if flag and enter:
			col += 1
	print(col - 1)
	for i in color:
		print(i, end=' ')


from sys import stdin

def sieve_of_eratosthenes(n):
	all_prime = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n):
		if prime[p]:
			all_prime.append(p)
	return all_prime
all_primes = sieve_of_eratosthenes(int(1000 ** 0.5) + 1)
for _ in range(int(input())):
	n = int(stdin.readline().rstrip())
	l = list(map(int, stdin.readline().rstrip().split(' ')))
	x = set()
	t = 0
	r = {}
	for i in range(n):
		for j in range(len(all_primes)):
			if l[i] % all_primes[j] == 0:
				a = r.get(j, 0)
				if a:
					l[i] = a
				else:
					l[i] = t + 1
					t += 1
					r[j] = t
				break
	print(t)
	print(*l)


t = int(input())
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	colors = [0] * n
	k = 1
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in primes:
		flag = False
		for j in range(n):
			if colors[j] == 0:
				if arr[j] % i == 0:
					colors[j] = k
					flag = True
		if flag:
			k += 1
	print(k - 1)
	print(*colors)
	t -= 1


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(int(input())):
	input()
	a = [min((i + 1 for i in range(11) if a % p[i] == 0), default=10 ** 4) for a in map(int, input().split())]
	sa = sorted(set(a))
	print(len(sa))
	print(*[sa.index(x) + 1 for x in a])


for _ in range(int(input())):
	w = int(input())
	data = list(map(int, input().split()))
	count = 1
	ans = []
	p = {2: 12, 3: 12, 5: 12, 7: 12, 11: 12, 13: 12, 17: 12, 19: 12, 23: 12, 29: 12, 31: 12}
	for item in data:
		for j in p:
			if item % j == 0:
				if p[j] == 12:
					p[j] = count
					count += 1
				ans.append(p[j])
				break
	print(count - 1)
	print(*ans)


t = int(input())
from sys import stdin, stdout
from collections import defaultdict
lp = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(t):
	n = int(input())
	l = list(map(int, stdin.readline().split()))
	d = defaultdict(int)
	d1 = defaultdict(int)
	l1 = []
	for j in l:
		for k in lp:
			if j % k == 0:
				d[j] = k
				d1[k] = 1
				break
	c = 0
	for j in d1:
		c += 1
		d1[j] = c
	for j in l:
		l1.append(str(d1[d[j]]))
	print(c)
	stdout.write(' '.join(l1) + '\n')


t = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	sol = [0 for k in range(n)]
	for i in range(n):
		for j in range(11):
			if nums[i] % primes[j] == 0:
				sol[i] = j + 1
				break
	print(len(set(sol)))
	groups = {}
	k = 0
	for s in sol:
		if s not in groups:
			k += 1
			groups[s] = k
			print(k, end=' ')
		else:
			print(groups[s], 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())
testcases = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for case in range(testcases):
	used = {}
	n = int(input())
	l = [int(zax) for zax in input().split()]
	p = []
	for i in range(n):
		for j in range(11):
			if l[i] % primes[j] == 0:
				p.append(j + 1)
				if j + 1 not in used:
					used[j + 1] = j + 1
				break
	last = 1
	for i in range(1, 12):
		if i in used:
			used[i] = last
			last += 1
	for i in range(n):
		p[i] = str(used[p[i]])
	print(last - 1)
	print(' '.join(p))


cases = int(input())
for case in range(cases):
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	primes_used = []
	numbers = int(input())
	sequence = list(map(int, input().split(' ')))
	result = [0] * len(sequence)
	colors_used = 0
	for i in range(len(sequence)):
		for p in range(len(primes)):
			if sequence[i] % primes[p] == 0:
				if primes[p] in primes_used:
					result[i] = primes_used.index(primes[p]) + 1
				else:
					primes_used.append(primes[p])
					colors_used += 1
					result[i] = colors_used
				break
	string_result = [str(num) for num in result]
	print(colors_used)
	print(' '.join(string_result))


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')

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()
	color = defaultdict(lambda : -1)
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	color_used = set()
	for i in range(n):
		for prime in range(11):
			if a[i] % primes[prime] == 0:
				color[a[i]] = prime + 1
				color_used.add(prime + 1)
				break
	ID = {}
	cur_color = 1
	for i in color_used:
		ID[i] = cur_color
		cur_color += 1
	color = {i: ID[color[i]] for i in color}
	print(len(color_used))
	for i in range(n):
		print(color[a[i]], end=' ')
	print()


simple = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def find_colour(x, used):
	for i in range(len(simple)):
		if x % simple[i] == 0:
			if i in used:
				return str(used[i])
			else:
				used[i] = len(used) + 1
				return str(used[i])

def solve():
	amount = int(input())
	nums = list(map(int, input().split()))
	ans = []
	used = dict()
	for num in nums:
		ans.append(find_colour(num, used))
	print(len(used))
	print(' '.join(ans))
n = int(input())
for i in range(n):
	solve()


def func():
	n = int(input())
	arr = [int(x) for x in input().split()]
	primes = [[2, False], [3, False], [5, False], [7, False], [11, False], [13, False], [17, False], [19, False], [23, False], [29, False], [31, False]]
	k = 0
	ans = []
	for i in arr:
		for j in range(len(primes)):
			if i % primes[j][0] == 0:
				if primes[j][1] == False:
					primes[j][1] = True
					k += 1
					primes[j].append(k)
					ans.append(primes[j][2])
				else:
					ans.append(primes[j][2])
				break
	print(k)
	[print('%d' % x, end=' ') for x in ans]
	print('')
t = int(input())
while t != 0:
	t -= 1
	func()


t = int(input())
for _ in range(t):
	n = int(input())
	items = list(map(int, input().split()))
	d = {}
	i = 0
	for item in items:
		for j in range(2, 1001):
			if item % j == 0:
				if j not in d:
					d[j] = [i]
				else:
					d[j] += [i]
				break
		i += 1
	print(len(d))
	res = [0] * n
	i = 1
	for item in list(d.values()):
		for index in item:
			res[index] = i
		i += 1
	for item in res:
		print(item, end=' ')
	print('')


import math
b = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
for tin in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = []
	for i in range(len(b)):
		d = []
		k = 0
		for _ in range(len(a)):
			if a[_] != -1:
				k = 1
				if a[_] % b[i] == 0:
					d.append(_)
					a[_] = -1
					k = 1
		if k == 1:
			c.append(d)
		else:
			break
	v = []
	for _ in range(n):
		v.append(0)
	while [] in c:
		c.remove([])
	for _ in range(len(c)):
		for i in range(len(c[_])):
			v[c[_][i]] = _ + 1
	print(len(list(set(v))))
	print(*v)


t = int(input())
pl = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	l = [int(i) for i in input().strip().split(' ')]
	o = []
	for i in l:
		for p in pl:
			if i % p == 0:
				o.append(p)
				break
	op = list(set(o))
	m = len(op)
	of = []
	for i in o:
		of.append(op.index(i) + 1)
	print(m)
	print(*of)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	d = {}
	chk = {}
	t = 1
	for i in range(len(a)):
		for j in range(len(l)):
			if a[i] % l[j] == 0:
				d[i] = j + 1
				if j + 1 not in chk:
					chk[j + 1] = t
					t += 1
				break
	print(len(chk))
	for i in range(n):
		print(chk[d[i]], end=' ')
	print()


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def getprime(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1
t = int(input())
for s in range(t):
	n = int(input())
	numbers = list(map(int, input().split()))
	used = [False for i in range(11)]
	clr = []
	for i in range(n):
		x = primes.index(getprime(numbers[i]))
		used[x] = True
		clr.append(x)
	cnt = 0
	num = []
	for i in range(11):
		num.append(cnt)
		if used[i]:
			cnt += 1
	print(cnt)
	for i in range(n):
		x = primes.index(getprime(numbers[i]))
		print(num[x] + 1, end=' ')
	print()


import sys
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():
	pp = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for _ in range(II()):
		n = II()
		aa = LI()
		ans = [-1] * n
		m = 1
		for p in pp:
			use = False
			for i in range(n):
				if ans[i] != -1 or aa[i] % p:
					continue
				use = True
				ans[i] = m
			if use:
				m += 1
		print(max(ans))
		print(*ans)
main()


t = int(input())
c = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	ans = {}
	res = []
	for i in a:
		for j in c:
			if i % j == 0:
				if j not in ans:
					count += 1
					ans[j] = count
				res.append(ans[j])
				break
	print(count)
	print(*res)


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')]

def primeFactors(n):
	l = []
	for j in range(2, int(n ** 0.5) + 1):
		if not n % j:
			l.append(j)
			while not n % j:
				n //= j
	if n > 1:
		l.append(n)
	return l
for _ in range(val()):
	m = val()
	l = li()
	ans = []
	d = defaultdict(int)
	curr = 1
	for i in l:
		facts = primeFactors(i)
		if d[facts[0]]:
			ans.append(d[facts[0]])
		elif len(facts) > 1 and d[facts[1]]:
			ans.append(d[facts[1]])
		else:
			d[facts[0]] = curr
			ans.append(curr)
			curr += 1
	print(len(Counter(ans)))
	print(*ans)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque
import bisect as bi

def I():
	return int(input())

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

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

def main():
	try:
		d = {2: 1, 3: 1, 5: 1, 7: 1, 11: 1, 13: 1, 17: 1, 19: 1, 23: 1, 29: 1, 31: 1, 37: 1, 41: 1, 43: 1, 47: 1, 53: 1, 59: 1, 61: 1, 67: 1, 71: 1, 73: 1, 79: 1, 83: 1, 89: 1, 97: 1, 101: 1, 103: 1, 107: 1, 109: 1, 113: 1, 127: 1, 131: 1, 137: 1, 139: 1, 149: 1, 151: 1, 157: 1, 163: 1, 167: 1, 173: 1, 179: 1, 181: 1, 191: 1, 193: 1, 197: 1, 199: 1, 211: 1, 223: 1, 227: 1, 229: 1, 233: 1, 239: 1, 241: 1, 251: 1, 257: 1, 263: 1, 269: 1, 271: 1, 277: 1, 281: 1, 283: 1, 293: 1, 307: 1, 311: 1, 313: 1, 317: 1, 331: 1, 337: 1, 347: 1, 349: 1, 353: 1, 359: 1, 367: 1, 373: 1, 379: 1, 383: 1, 389: 1, 397: 1, 401: 1, 409: 1, 419: 1, 421: 1, 431: 1, 433: 1, 439: 1, 443: 1, 449: 1, 457: 1, 461: 1, 463: 1, 467: 1, 479: 1, 487: 1, 491: 1, 499: 1, 503: 1, 509: 1, 521: 1, 523: 1, 541: 1, 547: 1, 557: 1, 563: 1, 569: 1, 571: 1, 577: 1, 587: 1, 593: 1, 599: 1, 601: 1, 607: 1, 613: 1, 617: 1, 619: 1, 631: 1, 641: 1, 643: 1, 647: 1, 653: 1, 659: 1, 661: 1, 673: 1, 677: 1, 683: 1, 691: 1, 701: 1, 709: 1, 719: 1, 727: 1, 733: 1, 739: 1, 743: 1, 751: 1, 757: 1, 761: 1, 769: 1, 773: 1, 787: 1, 797: 1, 809: 1, 811: 1, 821: 1, 823: 1, 827: 1, 829: 1, 839: 1, 853: 1, 857: 1, 859: 1, 863: 1, 877: 1, 881: 1, 883: 1, 887: 1, 907: 1, 911: 1, 919: 1, 929: 1, 937: 1, 941: 1, 947: 1, 953: 1, 967: 1, 971: 1, 977: 1, 983: 1, 991: 1, 997: 1}
		for _ in range(I()):
			amt = [0] * 1001
			n = I()
			l = list(In())
			ans = []
			an = 0
			j = 1
			for x in l:
				if d.get(x, 0) != 0:
					an += 1
					amt[x] = j
					j += 1
				else:
					ans.append(x)
			poty = [0] * len(ans)
			d1 = defaultdict(list)
			for i in range(2, 50):
				r = 0
				for x in range(len(ans)):
					if ans[x] % i == 0 and poty[x] == 0:
						d1[i].append(ans[x])
						amt[ans[x]] = j
						poty[x] = 1
						r = 1
				if r == 1:
					j += 1
			print(j - 1)
			for x in l:
				print(amt[x], end=' ')
			print()
	except:
		pass
M = 998244353
P = 1000000007
main()


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

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

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

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

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

def revn(n):
	return str(n)[::-1]

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

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

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
a = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(ii()):
	n = ii()
	arr = li()
	ans = [0] * n
	p = 1
	for i in range(11):
		c = 0
		for j in range(n):
			if arr[j] % a[i] == 0 and ans[j] == 0:
				ans[j] = p
				c += 1
		if c:
			p += 1
	print(p - 1)
	print(*ans)


t = int(input())
while t > 0:
	n = int(input())
	x = input().split(' ')
	c = 1
	l = []
	d = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
	for j in x:
		i = int(j)
		if i % 2 == 0:
			if d[0] == 0:
				d[0] = c
				c += 1
			l.append(d[0])
		elif i % 3 == 0:
			if d[1] == 0:
				d[1] = c
				c += 1
			l.append(d[1])
		elif i % 5 == 0:
			if d[2] == 0:
				d[2] = c
				c += 1
			l.append(d[2])
		elif i % 7 == 0:
			if d[3] == 0:
				d[3] = c
				c += 1
			l.append(d[3])
		elif i % 11 == 0:
			if d[4] == 0:
				d[4] = c
				c += 1
			l.append(d[4])
		elif i % 13 == 0:
			if d[5] == 0:
				d[5] = c
				c += 1
			l.append(d[5])
		elif i % 17 == 0:
			if d[6] == 0:
				d[6] = c
				c += 1
			l.append(d[6])
		elif i % 19 == 0:
			if d[7] == 0:
				d[7] = c
				c += 1
			l.append(d[7])
		elif i % 23 == 0:
			if d[8] == 0:
				d[8] = c
				c += 1
			l.append(d[8])
		elif i % 29 == 0:
			if d[9] == 0:
				d[9] = c
				c += 1
			l.append(d[9])
		elif i % 31 == 0:
			if d[10] == 0:
				d[10] = c
				c += 1
			l.append(d[10])
	print(c - 1)
	for i in l[:-1]:
		print(i, end=' ')
	print(l[-1])
	t -= 1


colors = [0 for i in range(1001)]
colors[0] = -1
colors[1] = -1

def isprime(n):
	for i in range(2, n):
		if n % i == 0:
			return False
	return True
for (c, i) in enumerate([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]):
	for j in range(1001):
		if j % i == 0:
			colors[j] = c + 1
for _ in range(int(input())):
	n = int(input())
	nums = [int(x) for x in input().split()]
	ans = [colors[i] for i in nums]
	setans = list(set(ans))
	ncol = len(setans)
	ansvoc = {c: i + 1 for (i, c) in enumerate(setans)}
	print(ncol)
	for n in ans:
		print(ansvoc[n], end=' ')
	print()


from sys import stdin
from math import gcd

def arr_inp(n):
	return [int(x) for x in stdin.readline().split()]

def count_prime(n):
	prim = [1] * (n + 1)
	prim[0] = prim[1] = 0
	i = 2
	while i * i <= n:
		if prim[i]:
			for j in range(i * 2, n + 1, i):
				prim[j] = 0
		i += 1
	yield 2
	yield 3
	for i in range(5, n - 1, 6):
		if prim[i]:
			yield i
		if prim[i + 2]:
			yield (i + 2)
primes = list(count_prime(32))[:11]
for i in range(int(input())):
	(n, a) = (int(input()), arr_inp(1))
	(ans, cur, flag) = ([0] * n, 1, 0)
	for p in range(1, 12):
		for j in range(n):
			if a[j] % primes[p - 1] == 0 and (not ans[j]):
				(ans[j], flag) = (cur, 1)
		if flag:
			cur += 1
			flag = 0
	print(len(set(ans)))
	print(*ans)


for _ in range(int(input())):
	dic = {2: 0, 3: 0, 5: 0, 7: 0, 11: 0, 13: 0, 17: 0, 19: 0, 23: 0, 29: 0, 31: 0}
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	n = int(input())
	lst = list(map(int, input().split()))
	temp = []
	col = 0
	for i in range(n):
		for a in range(11):
			if lst[i] % prime[a] == 0:
				if dic[prime[a]] == 0:
					col += 1
					dic[prime[a]] = col
				temp.append(dic[prime[a]])
				break
	print(col)
	print(*temp)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
for _ in range(get_int()):
	d = {2: 1, 3: 2, 5: 3, 7: 4, 11: 5, 13: 6, 17: 7, 19: 8, 23: 9, 29: 10, 31: 11}
	n = get_int()
	lst = get_int_list()
	for (i, v) in d.items():
		for j in range(n):
			if lst[j] % i == 0:
				lst[j] = v
	s = set(lst)
	t = {}
	l = 1
	for i in s:
		t[i] = l
		l += 1
	for i in range(n):
		lst[i] = t[lst[i]]
	print(len(s))
	print(*lst)


from collections import defaultdict

def read_nums():
	return [int(x) for x in input().split()]
primes = [2]

def is_prime(n):
	sqrt_n = int(n ** 0.5)
	for p in primes:
		if p > sqrt_n:
			break
		if n % p == 0:
			return False
	return True
for cand in range(3, int(1001 ** 0.5) + 1, 2):
	if is_prime(cand):
		primes.append(cand)

def get_prime_factors(n):
	for p in primes:
		if n % p == 0:
			yield p

def color_numbers(nums):
	colors = [None for _ in nums]
	divisor_to_elem_index = defaultdict(list)
	for (index, elem) in enumerate(nums):
		for divisor in set(get_prime_factors(elem)):
			divisor_to_elem_index[divisor].append(index)
	color_index = 0
	for (divisor, indices) in divisor_to_elem_index.items():
		increased = False
		for index in indices:
			if colors[index] is None:
				if not increased:
					increased = True
					color_index += 1
				colors[index] = color_index
	return (len(set(colors)), colors)

def print_coloring(nums):
	(n_colors, colors) = color_numbers(nums)
	print(n_colors)
	print(' '.join(map(str, colors)))

def main():
	(t,) = read_nums()
	for _ in range(t):
		(n,) = read_nums()
		nums = read_nums()
		print_coloring(nums)
main()


import sys
input = sys.stdin.readline
t = int(input())
ps = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def compress(init_val):
	t = sorted(set(init_val))
	d = dict([[t[i], i] for i in range(len(t))])
	res = [0] * len(init_val)
	for i in range(len(init_val)):
		res[i] = d[init_val[i]]
	return res
for _ in range(t):
	N = int(input())
	a = list(map(int, input().split()))
	res = [0] * N
	for i in range(N):
		for j in range(11):
			if a[i] % ps[j] == 0:
				res[i] = j + 1
				break
	res = compress(res)
	for i in range(N):
		res[i] += 1
	print(max(res))
	print(*res)


def get(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	a = list(map(lambda x: pr.index(get(int(x))), input().split()))
	used = [0] * 11
	for i in a:
		used[i] = 1
	cnt = 0
	num = []
	for i in range(11):
		num.append(cnt)
		if used[i]:
			cnt += 1
	print(cnt)
	print(*[num[i] + 1 for i in a])


from sys import stdout, stdin
input = stdin.readline
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = max(a)
	prime = [1 for i in range(b + 1)]
	i = 2
	while i * i <= b:
		if prime[i] == 1:
			for j in range(i * i, b + 1, i):
				if prime[j] == 1:
					prime[j] = i
		i += 1
	c = {}
	for i in range(n):
		if c.get(prime[a[i]]) == None:
			c[prime[a[i]]] = [i]
		else:
			c[prime[a[i]]].append(i)
	m = 0
	ans = [0 for i in range(n)]
	for i in c:
		m += 1
		for j in c[i]:
			ans[j] = m
	print(m)
	print(*ans)


import sys
input = sys.stdin.readline
for j in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	currCol = 1
	colorMap = {}
	ans = 1
	for x in primes:
		inc = False
		for m in a:
			if m % x == 0 and m not in colorMap:
				colorMap[m] = currCol
				ans = currCol
				inc = True
		if inc == True:
			currCol = currCol + 1
	print(ans)
	coloring = [str(colorMap[f]) for f in a]
	print(' '.join(coloring))


def program():
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	used = []
	n = int(input())
	l = list(map(int, input().split()))
	color = 1
	dic = dict()
	for x in l:
		for p in prime:
			if x % p == 0:
				add = prime.index(p) + 1
				used.append(add)
				if add not in dic.keys():
					dic[add] = color
					color += 1
				break
	print(len(dic))
	for x in used:
		print(dic[x], end=' ')
	print()
for i in range(int(input())):
	program()


import math
x = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for test in range(t):
	nt = [0 for i in range(11)]
	n = int(input())
	arr = list(map(int, input().split()))
	col = [0 for i in range(n)]
	for i in range(n):
		for j in range(11):
			if arr[i] % x[j] == 0:
				nt[j] = 1
				col[i] = j + 1
				break
	print(sum(nt))
	if sum(nt) == 11:
		print(*col)
		continue
	nus = []
	for i in range(11):
		if nt[i] == 0:
			nus.append(i + 1)
	for i in range(n):
		cnt = 0
		for j in range(len(nus)):
			if col[i] > nus[j]:
				cnt += 1
		col[i] -= cnt
	print(*col)


from sys import stdin, stdout
t = int(stdin.readline())
for query in range(t):
	n = int(stdin.readline())
	composites = stdin.readline().split()
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = []
	used = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
	counter = 0
	for x in range(n):
		ans.append(0)
		composites[x] = int(composites[x])
	for num in range(n):
		for prime in range(11):
			if composites[num] % primes[prime] == 0:
				ans[num] = prime + 1
				if used[prime] == 1:
					used[prime] = 0
				break
	if query == 0:
		stdout.write('\n')
	stdout.write(str(used.count(0)))
	stdout.write('\n')
	z = ans[:]
	for x in range(11):
		if used[x] == 1:
			for y in range(n):
				if z[y] > x + 1:
					ans[y] = ans[y] - 1
	for x in ans:
		stdout.write(str(x) + ' ')
	stdout.write('\n')


primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)

def algo(inp, n):
	result = []
	colors = [None] * 11
	for i in range(n):
		for j in range(11):
			if inp[i] % primes[j] == 0:
				result.append(j + 1)
				colors[j] = True
				break
	print(colors.count(True))
	print(*[i - colors[:i - 1].count(None) for i in result])
for _ in range(int(input())):
	n = int(input())
	inp = list(map(int, input().split()))
	algo(inp, n)


I = lambda : int(input())
M = lambda : map(int, input().split())
L = lambda : list(M())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(I()):
	n = I()
	a = L()
	li = []
	use = [False] * 11
	for i in range(n):
		for j in range(11):
			if a[i] % p[j] == 0:
				li.append(j)
				use[j] = True
				break
	cnt = 0
	num = []
	for i in range(11):
		num.append(cnt)
		if use[i]:
			cnt += 1
	print(cnt)
	for i in range(n):
		print(num[li[i]] + 1, end=' ')
	print()


for _ in range(int(input())):
	q = int(input())
	s = list(map(int, input().split()))
	colors = []
	ans = []
	for n in s:
		i = 0
		while i < len(colors) and n % colors[i]:
			i += 1
		if i < len(colors):
			ans.append(i + 1)
		else:
			i = 2
			while n % i:
				i += 1
			colors.append(i)
			ans.append(len(colors))
	print(len(colors))
	print(*ans)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def solve(nums, n):
	prime_dict = {p: [] for p in primes}
	colors = [0] * n
	largest_color = 0
	for (ind, num) in enumerate(nums):
		for p in primes:
			if num < p:
				break
			if num % p == 0:
				if prime_dict[p]:
					prime_dict[p].append(ind)
					colors[ind] = colors[prime_dict[p][0]]
				else:
					prime_dict[p].append(ind)
					largest_color += 1
					colors[ind] = largest_color
				break
	return (largest_color, colors)
t = int(input())
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	(m, result) = solve(nums, n)
	print(m)
	print(' '.join(map(str, result)))


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	cs = []
	c = 0
	p_to_c = {}
	for a in input().split():
		a = int(a)
		for (i, prime) in enumerate(primes):
			if a % prime == 0:
				if prime in p_to_c:
					cs.append(p_to_c[prime])
				else:
					c += 1
					cs.append(c)
					p_to_c[prime] = c
				break
	print(c)
	print(' '.join(map(str, cs)))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))[:n]
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	from collections import Counter
	from collections import defaultdict
	store = Counter(arr)
	color = defaultdict(int)
	count = n
	c = 1
	for p in prime:
		s = p
		flag = 0
		while s <= 1000:
			if store[s] >= 1 and color[s] == 0:
				flag = 1
				color[s] = c
				count -= store[s]
			s += p
			if count <= 0:
				break
		if count <= 0:
			break
		if flag == 1 and count > 0:
			c += 1
	print(min(11, c))
	for num in arr:
		print(color[num], end=' ')
	print()


import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	check = 1
	hihi = [0] * 1004
	ans = [0] * n
	for i in range(2, 1001):
		if hihi[i] == 0:
			dem = 0
			for j in range(n):
				if ans[j] == 0 and arr[j] % i == 0:
					ans[j] = check
					dem += 1
			if dem != 0:
				check += 1
			for j in range(i + i, 1003, i):
				hihi[j] = 1
	print(check - 1)
	for i in range(n):
		print(ans[i], end=' ')
	print()


from collections import defaultdict
t = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	col = [-1] * n
	for i in range(n):
		for j in range(len(p)):
			if arr[i] % p[j] == 0:
				col[i] = j
				break
	mi = min(col)
	for i in range(n):
		col[i] -= mi
		col[i] += 1
	ans = [-1] * n
	d = defaultdict(list)
	for i in range(n):
		d[col[i]] += [i]
	d2 = defaultdict(list)
	ind = 1
	for x in d:
		for y in d[x]:
			d2[ind] += [y]
		ind += 1
	ans = [0] * n
	for x in d2:
		for y in d2[x]:
			ans[y] = x
	print(len(d2))
	print(*ans)


pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for q in range(int(input())):
	cind = 0
	ind = [-1] * 11
	n = int(input())
	ans = [0] * n
	d = [int(i) for i in input().split()]
	for i in range(n):
		k = d[i]
		for j in range(11):
			if k % pr[j] == 0:
				if ind[j] == -1:
					cind += 1
					ind[j] = cind
				ans[i] = ind[j]
				break
	print(cind)
	print(*ans)


import math

def prime(n, d, k):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i in d:
				d[i].append([n, k])
			else:
				d[i] = [[n, k]]
			break
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	d = {}
	m = 1
	for i in range(len(a)):
		prime(a[i], d, i)
	for (key, value) in d.items():
		for i in range(len(d[key])):
			a[d[key][i][1]] = m
		m = m + 1
	print(m - 1)
	for i in range(len(a) - 1):
		print(a[i], end=' ')
	print(a[-1])


from collections import defaultdict

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * n
	d = defaultdict(list)
	for i in range(n):
		d[smallestDivisor(a[i])].append(i)
	m = 1
	for i in d:
		for j in d[i]:
			c[j] = m
		m += 1
	print(m - 1)
	print(*c)


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
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def min_div(n):
	for i in range(2, 32):
		if n % i == 0:
			return i

def solve():
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		clr = []
		last_c = 1
		dic = {}
		for i in arr:
			for j in primes:
				if i % j == 0:
					if j in dic:
						clr.append(dic[j])
					else:
						dic[j] = last_c
						last_c += 1
						clr.append(dic[j])
					break
		print(last_c - 1)
		print(*clr)
solve()


primes = set()
for i in range(2, 1001):
	j = 2
	isprime = True
	while j * j <= i:
		if i % j == 0:
			isprime = True
			break
		j += 1
	if isprime:
		primes.add(i)

def solve():
	unused_primes = set(primes)
	prime_to_c = {}
	c = 0
	n = int(input())
	arr = [int(v) for v in input().split()]
	ans = []
	for a in arr:
		found = False
		for (f, color) in prime_to_c.items():
			if a % f == 0:
				ans.append(str(color))
				found = True
				break
		if not found:
			remove_p = 0
			for p in unused_primes:
				if a % p == 0:
					remove_p = p
					c += 1
					prime_to_c[p] = c
					ans.append(str(c))
					break
			if remove_p:
				unused_primes.discard(remove_p)
	print(len(prime_to_c))
	print(' '.join(ans))
t = int(input())
for _ in range(t):
	solve()


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

def sieve(n):
	a = [0] * (n + 1)
	color = 1
	for i in range(2, n + 1):
		if a[i] == 0:
			k = 2 * i
			while k <= n:
				if a[k] == 0:
					a[k] = color
				k += i
			color += 1
	return a
s = sieve(1000)

def calculate_rank(vector):
	a = {}
	rank = 1
	for num in sorted(vector):
		if num not in a:
			a[num] = rank
			rank = rank + 1
	return [a[i] for i in vector]
for _ in range(t):
	n = int(input())
	a = list(R())
	z = [s[x] for x in a]
	z = calculate_rank(z)
	print(max(z))
	print(*z)


from itertools import accumulate
from bisect import bisect_left
import itertools
N = 1010
arr = [[] for i in range(N)]
for i in range(2, N):
	if arr[i] == []:
		arr[i] = [i]
		for v in range(2 * i, N, i):
			arr[v].append(i)
f = [*filter(lambda v: len(v) > 0 and min(v) > 37, arr)]
standard_input = '3\n3\n6 10 15\n2\n4 9\n23\n437 519 865 808 909 391 194 291 237 395 323 365 511 497 781 737 871 559 731 697 779 841 961\n'
clrs = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
t = int(input())

def solve():
	n = int(input())
	v = [*map(int, input().split(' '))]
	try:
		ans = [*map(lambda v: clrs.index(min(arr[v])), v)]
		clr = list(set(ans))
		print(len(clr))
		print(*map(lambda c: clr.index(c) + 1, ans))
	except Exception as E:
		print(E)
for i in range(t):
	solve()


def minprimefactor(x):
	if x % 2 == 0:
		return 2
	for i in range(3, x + 1, 2):
		if x % i == 0:
			return i

def tough(n, a):
	prime = []
	res = []
	v = 0
	for i in range(n):
		l = minprimefactor(a[i])
		if l in prime:
			res.append(prime.index(l) + 1)
		else:
			prime.append(l)
			v += 1
			res.append(v)
	print(len(prime))
	print(*res)
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	tough(n, a)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

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

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

def nu():
	return int(input())

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

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		n = nu()
		a = li()
		cc = 1
		col = [-1] * n
		for i in range(2, 1001):
			fl = False
			for j in range(n):
				if col[j] == -1:
					if a[j] % i == 0:
						col[j] = cc
						fl = True
			if fl:
				cc += 1
		print(cc - 1)
		print(*col)
solve()


import sys
from math import gcd
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = []
	[a.append([int(i), 0]) for i in input().split()]
	val = 1
	ans = 0
	for i in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
		ct = 0
		for j in range(n):
			if not a[j][0] % i and (not a[j][1]):
				a[j][1] = val
				ct += 1
		if ct:
			ans += 1
			val += 1
	print(ans)
	for i in a:
		print(i[1], end=' ')
	print()


import math
t = int(input())

def check(c, a, n):
	for i in range(n):
		for j in range(n):
			if c[i] == c[j] and math.gcd(a[i], a[j]) == 1:
				return False
	return True
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0 for i in range(n)]
	freq = [[0, i] for i in range(101)]
	need = max(0, n - 11)
	for j in range(2, 101):
		for i in range(n):
			if a[i] % j == 0:
				freq[j][0] += 1
	cur = 1
	if need > 0:
		for (frequency, num) in freq:
			if num <= 1:
				continue
			did = False
			for i in range(n):
				if a[i] % num == 0 and c[i] == 0:
					c[i] = cur
					did = True
			if did:
				cur += 1
			if all([i != 0 for i in c]):
				break
	for i in range(n):
		if c[i] == 0:
			c[i] = cur
			cur += 1
	print(max(c))
	print(*c)


import sys

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(a, b, x, x1, x2):
		if (a == -2 * b or x != x1 or x != x2 or (b == 0)) and x1 <= x - a + b <= x2:
			return True
		return False
	n = iinput()
	q = rlinput()
	w = dict()
	for i in range(n):
		for o in range(2, 1001):
			if q[i] % o == 0:
				if o in w:
					w[o].append(i)
				else:
					w[o] = [i]
				break
	m = 1
	res = [1] * n
	for i in w:
		for o in w[i]:
			res[o] = m
		m += 1
	print(m - 1)
	print(*res)
for i in range(iinput()):
	main()


a = int(input())
for _ in range(a):
	size = int(input())
	ar = list(map(int, input().split()))
	g = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)
	v = [0] * size
	z = [0] * 11
	u = 0
	for i in range(size):
		if ar[i] % 31 == 0:
			if z[0] == 0:
				u += 1
				z[0] = u
			v[i] = z[0]
		elif ar[i] % 29 == 0:
			if z[1] == 0:
				u += 1
				z[1] = u
			v[i] = z[1]
		elif ar[i] % 23 == 0:
			if z[2] == 0:
				u += 1
				z[2] = u
			v[i] = z[2]
		elif ar[i] % 19 == 0:
			if z[3] == 0:
				u += 1
				z[3] = u
			v[i] = z[3]
		elif ar[i] % 17 == 0:
			if z[4] == 0:
				u += 1
				z[4] = u
			v[i] = z[4]
		elif ar[i] % 13 == 0:
			if z[5] == 0:
				u += 1
				z[5] = u
			v[i] = z[5]
		elif ar[i] % 11 == 0:
			if z[6] == 0:
				u += 1
				z[6] = u
			v[i] = z[6]
		elif ar[i] % 7 == 0:
			if z[7] == 0:
				u += 1
				z[7] = u
			v[i] = z[7]
		elif ar[i] % 5 == 0:
			if z[8] == 0:
				u += 1
				z[8] = u
			v[i] = z[8]
		elif ar[i] % 3 == 0:
			if z[9] == 0:
				u += 1
				z[9] = u
			v[i] = z[9]
		elif ar[i] % 2 == 0:
			if z[10] == 0:
				u += 1
				z[10] = u
			v[i] = z[10]
	print(u)
	for i in range(size):
		print(v[i], end=' ')
	print()


t = int(input())
for rep in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	colarr = [0] * n
	m = 0
	for i in range(11):
		f = 0
		for j in range(n):
			if a[j] % primes[i] == 0 and colarr[j] == 0:
				colarr[j] = m + 1
				f = 1
		if f == 1:
			m += 1
	print(m)
	print(' '.join(list(map(str, colarr))))


import math

def pfacts(n):
	ans = []
	if n % 2 == 0:
		ans.append(2)
		while n % 2 == 0:
			n //= 2
	p = 3
	while n != 1:
		if n % p == 0:
			ans.append(p)
			while n % p == 0:
				n //= p
		p += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	nms = list(map(int, input().split()))
	mark = [0 for i in range(1001)]
	col = 1
	cp = list(sorted(nms, reverse=True))
	cols = [[] for i in range(12)]
	fs = []
	for i in range(n):
		fs.append(pfacts(cp[i]))
	for i in range(n):
		if mark[cp[i]] == 0:
			mark[cp[i]] = col
			cols[col].append(fs[i])
			for b in fs[i]:
				fnd = False
				for a in range(n):
					if mark[cp[a]] == 0:
						if b in fs[a]:
							mark[cp[a]] = col
							cols[col].append(fs[a])
							fnd = True
				if fnd:
					break
			col += 1
	ans = []
	for i in range(n):
		ans.append(str(mark[nms[i]]))
	print(col - 1)
	print(' '.join(ans))


stat = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547]
from collections import defaultdict
for _ in range(int(input())):
	index = defaultdict(lambda : 0)
	N = int(input())
	L = list(map(int, input().split()))
	Color = 1
	for i in stat:
		FLAG = 0
		for j in range(N):
			if index[j] == 0 and L[j] % i == 0:
				index[j] = Color
				FLAG = 1
		if FLAG == 1:
			Color += 1
	print(Color - 1)
	for i in range(N):
		print(index[i], end=' ')
	print()


import sys
import math
from collections import defaultdict

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

def fun(i, mark):
	op[i] = mark
	j = d[i][0]
	for k in d2[j]:
		if op[k] == 0:
			op[k] = mark
t = int(input())
for i in range(t):
	global d, d2, op
	n = int(input())
	a = list(map(int, sys.stdin.readline().strip().split()))
	d = defaultdict(list)
	d2 = defaultdict(list)
	for i in a:
		d[i] = primeFactors(i)
		for j in d[i]:
			d2[j].append(i)
	op = defaultdict(int)
	mark = 1
	for i in d:
		if op[i] == 0:
			fun(i, mark)
			mark += 1
	print(mark - 1)
	for i in a:
		print(op[i], end=' ')
	print()


z = int(input())
for i in range(z):
	n = int(input())
	mas = list(map(int, input().split()))
	numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89]
	colors = [0] * n
	k = 0
	ind = 0
	ind_true = 1
	r = 0
	while k < n:
		r = 0
		for i in range(n):
			if colors[i] == 0:
				if mas[i] % numbers[ind] == 0:
					colors[i] = ind_true
					k += 1
					r = 1
		ind += 1
		if r == 1:
			ind_true += 1
	if r == 1:
		ind_true -= 1
	print(ind_true)
	print(*colors)


import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = [0] * n
	c = 1
	color = {}
	for (i, el) in enumerate(a):
		for y in range(2, el + 1):
			if el % y == 0:
				if y not in color:
					color[y] = c
					c += 1
				ans[i] = str(color[y])
				break
	print(c - 1)
	print(' '.join(ans))


def sieve():
	plist = [2]
	for i in range(3, 500, 2):
		prime = True
		for p in plist:
			if i % p == 0:
				prime = False
				break
		if prime:
			plist.append(i)
	return plist

def pair(plist, lim=1000):
	plistcpy = list(plist)
	pairs = []
	while len(plistcpy) > 0:
		p1 = plistcpy[0]
		p2 = plistcpy[-1]
		while p1 * p2 > 1000 and len(plistcpy) > 0:
			plistcpy.pop()
			p2 = plistcpy[-1]
		if p1 * p2 <= 1000:
			pairs.append([p1, p2])
		plistcpy.pop(0)
	return pairs

def flatten(colors):
	unique = list(set(colors))
	number = len(unique)
	mapping = {c: n + 1 for (n, c) in enumerate(unique)}
	colors = [mapping[col] for col in colors]
	return (number, colors)
T = int(input())
plist = sieve()
pairs = pair(plist)
testprimes = [pair[0] for pair in pairs]
for test in range(T):
	N = int(input())
	Alist = list(map(int, input().split()))
	colors = [0 for a in Alist]
	for (n, a) in enumerate(Alist):
		for (i, p) in enumerate(testprimes):
			if a % p == 0:
				colors[n] = i + 1
				break
	(number, colors) = flatten(colors)
	print(number)
	for color in colors:
		print(color)


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

def SieveOfEratosthenes(n, a):
	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
	for p in range(2, n):
		if prime[p]:
			a[p - 1] = -1
	return a
for xoxo in range(1):
	a = [0] * 1000
	a[0] = -1
	a[1] = -1
	a[2] = -1
	a = SieveOfEratosthenes(1000, a)
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for _ in range(int(input())):
		n = int(input())
		b = list(map(int, input().split()))
		for i in range(1, 12):
			j = pr[i - 1]
			while j < 1001:
				if a[j - 1] == 0:
					a[j - 1] = i
				j += pr[i - 1]
		x = [0] * 11
		for i in range(len(b)):
			for j in range(11):
				if b[i] % pr[j] == 0:
					x[j] = 1
					break
		y = []
		for i in range(11):
			if x[i] == 1:
				y.append(pr[i])
		ans = [0] * n
		for i in range(len(b)):
			for j in range(len(y)):
				if b[i] % y[j] == 0:
					ans[i] = j + 1
					break
		print(len(y))
		print(*ans)


d = {2: 1, 3: 2, 5: 3, 7: 4, 11: 5, 13: 6, 17: 7, 19: 8, 23: 9, 29: 10, 31: 11, 37: 12}
for _ in range(int(input())):
	n = int(input())
	ans = [-1 for i in range(n)]
	l = list(map(int, input().split()))
	c = 1
	for i in d:
		f = 1
		for j in range(n):
			if l[j] % i == 0 and ans[j] == -1:
				ans[j] = c
				f = 0
		if f == 0:
			c += 1
	print(len(set(ans)))
	print(*ans)


from collections import defaultdict
import bisect
import sys
input = sys.stdin.readline
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def solve(n, aa, primes=primes):
	ans = []
	pdict = {}
	c = 1
	for a in aa:
		for p in primes:
			if a % p == 0:
				if not p in pdict.keys():
					pdict[p] = c
					c += 1
				ans.append(pdict[p])
				break
	m = max(ans)
	print(m)
	print(' '.join(map(str, ans)))

def main():
	t = int(input())
	for i in range(t):
		n = list(map(int, input().split()))
		aa = list(map(int, input().split()))
		solve(n, aa)
main()


from sys import stdin, stdout
s = ''
for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, stdin.readline().split()))
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = [0 for i in range(n)]
	mx = 0
	f = True
	for i in pr:
		for j in range(n):
			if ans[j] == 0:
				if ls[j] % i == 0:
					if f:
						mx += 1
						f = False
					ans[j] = mx
		f = True
	s += f'{mx}\n'
	for i in range(n):
		s += f'{ans[i]} '
	s += '\n'
stdout.write(s)


arr = [0] * 1000
A = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(0, 1000):
	j = 0
	while j < len(A):
		if (i + 1) % A[j] > 0:
			j = j + 1
		else:
			break
	arr[i] = j
	i = i + 1
n = int(input())
while n > 0:
	ans = []
	m = -int(input())
	quest = [int(i) for i in input().split()]
	while m < 0:
		ans += [arr[quest[m] - 1]]
		m = m + 1
	L = list(enumerate(set(ans)))
	dic = {y: x + 1 for (x, y) in L}
	R = [dic[x] for x in ans]
	print(max(R))
	print(' '.join([str(i) for i in R]))
	n = n - 1


def ndc(k):
	t = int(k ** 0.5)
	for i in range(2, t + 1):
		if k % i == 0:
			return i
	return k
kl = int(input())
for l in range(kl):
	rz = []
	s = set()
	A = {}
	nr = 0
	n = int(input())
	a = [int(i) for i in input().split()]
	for i in range(n):
		prd = ndc(a[i])
		if prd not in s:
			s.add(prd)
			nr += 1
			A[prd] = nr
		rz += [A[prd]]
	print(nr)
	print(*rz)


a = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	c = [0] * 11
	d = []
	k = 1
	for i in range(n):
		for j in range(11):
			if b[i] % a[j] == 0:
				if c[j] == 0:
					c[j] = k
					d.append(k)
					k += 1
				else:
					d.append(c[j])
				break
	print(k - 1)
	print(*d)


import math
(cc, prime) = ([1] * 2 + [0] * 499, [])
for i in range(2, int(math.sqrt(500)) + 1):
	if not cc[i]:
		for j in range(i * i, 501, i):
			cc[j] = 1
for i in range(2, 501):
	if not cc[i]:
		prime.append(i)
for t in range(int(input())):
	n = int(input())
	v = list(map(int, input().split()))
	kol = [0] * n
	(now, first) = (0, 0)
	for p in prime:
		first = 0
		for i in range(n):
			if kol[i] == 0 and v[i] % p == 0:
				if first == 0:
					now += 1
					first = 1
				kol[i] = now
	print(now)
	for x in kol:
		print(x, end=' ')
	print()


minPrimeDiv = [1 for i in range(0, 1001)]
for i in range(2, 1001):
	if minPrimeDiv[i] != 1:
		continue
	else:
		for j in range(i, 1001, i):
			if minPrimeDiv[j] == 1:
				minPrimeDiv[j] = i

def solve(l):
	col = {}
	ans = []
	for num in l:
		primeDiv = minPrimeDiv[num]
		if primeDiv not in col:
			tempSize = len(col)
			col[primeDiv] = str(tempSize + 1)
		ans.append(col[primeDiv])
	print(len(col))
	print(' '.join(ans))
t = int(input())
for i in range(0, t):
	input()
	inp = list(map(lambda x: int(x), input().split()))
	solve(inp)


import re
factors = [[] for _ in range(1001)]
for i in range(2, 1001):
	for j in range(i, 1001, i):
		factors[i].append(j)

def solve(n, A):
	s = dict()
	for x in A:
		s[x] = 0
	cnt = 1
	for i in range(2, 1001):
		added = 0
		for x in factors[i]:
			if x in s and (not s[x]):
				s[x] = cnt
				added = 1
		cnt += added
	return str(max(s.values())) + '\n' + ' '.join([str(s[x]) for x in A])
tests = int(input())
for test in range(1, tests + 1):
	n = int(input())
	A = list(map(int, input().split()))
	print(solve(n, A))


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

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

def main():

	def solve():
		n = int(input())
		aa = [int(a) for a in input().split()]
		primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
		used = [False] * 11
		cn = [-1] * n
		for (i, a) in enumerate(aa):
			for (j, p) in enumerate(primes):
				if a % p == 0:
					cn[i] = j
					used[j] = True
					break
		nc = 1
		cmap = [-1] * 11
		for (i, u) in enumerate(used):
			if u:
				cmap[i] = nc
				nc += 1
		res = map(lambda c: str(cmap[c]), cn)
		print(nc - 1)
		print(' '.join(res))
	q = int(input())
	for _ in range(q):
		solve()
main()


from sys import stdin
input = stdin.readline
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	l = [0] * 11
	ll = [0] * 11
	for x in a:
		for y in range(11):
			if x % p[y] == 0:
				l[y] += 1
				break
	xx = 1
	for x in range(11):
		if l[x] != 0:
			ll[x] = xx
			xx += 1
	print(xx - 1)
	for x in a:
		for y in range(11):
			if x % p[y] == 0:
				print(ll[y], end=' ')
				break
	print()


def solve(a):
	c = [0] * len(a)
	m = []
	for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
		for j in range(len(a)):
			if a[j] % p == 0 and c[j] == 0:
				if p not in m:
					m.append(p)
				c[j] = len(m)
	print(len(m))
	print(' '.join([str(e) for e in c]))
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	solve(a)


import math

def pd(n):
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				t1 = i
				break
			else:
				t1 = i
				break
		i = i + 1
	return t1
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	t2 = []
	for i in a:
		if pd(i) not in t2:
			t2 += [pd(i)]
	t2.sort()
	t3 = []
	for j in a:
		for i in range(len(t2)):
			if j % t2[i] == 0:
				t3 += [i + 1]
				break
	print(len(t2))
	for i in t3:
		print(i, end=' ')
	print()


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	colors = [0 for _ in range(n)]
	for i in range(n):
		for prime in primes:
			if a[i] % prime == 0:
				colors[i] = prime
	counter = 0
	color_to_counter = {}
	for i in range(n):
		if colors[i] in color_to_counter:
			colors[i] = color_to_counter[colors[i]]
		else:
			counter += 1
			color_to_counter[colors[i]] = counter
			colors[i] = counter
	print(counter)
	print(' '.join([str(item) for item in colors]))


for _ in range(int(input())):
	n = int(input())
	a = [0] * int(1000 ** 0.5 + 1)
	m = 0
	ans = []
	c = list(map(int, input().split()))
	for i in range(n):
		b = c[i]
		for i in range(2, int(b ** 0.5) + 1):
			if b % i == 0:
				if a[i] == 0:
					m += 1
					a[i] = m
				ans.append(a[i])
				break
	print(m)
	print(*ans)


t = int(input())
output = []
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * len(a)
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
	colors = {}
	n = 1
	for i in range(len(a)):
		for j in range(len(primes)):
			if a[i] % primes[j] == 0:
				if primes[j] not in colors:
					colors[primes[j]] = n
					n += 1
				b[i] = colors[primes[j]]
				break
	s = str(b[0])
	for i in range(1, len(b)):
		s += ' ' + str(b[i])
	output.append(str(max(b)))
	output.append(s)
for o in output:
	print(o)


import math
import collections
import functools
import sys
import os

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	dic = {}
	pre = 1
	res = []
	for item in a:
		m = item
		i = 2
		mnp = m
		while i * i <= item:
			if m % i == 0:
				mnp = i
				break
			i += 1
		if not mnp in dic:
			dic[mnp] = pre
			pre += 1
		res.append(dic[mnp])
	print(pre - 1)
	print(' '.join([str(i) for i in res]))

def main():
	T = 1
	T = int(input())
	while T:
		solve()
		T -= 1
main()


import math
isPrime = [1] * 32
isPrime[0] = 0
isPrime[1] = 0
prime = []
for i in range(2, 32):
	if isPrime[i]:
		prime.append(i)
		for j in range(i + i, 32, i):
			isPrime[j] = 0
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	color = [0] * n
	ct = 1
	for i in range(len(prime)):
		inLoop = 0
		for j in range(n):
			if color[j] == 0 and arr[j] % prime[i] == 0:
				color[j] = ct
				inLoop = 1
		ct += inLoop
	print(ct - 1)
	print(*color)


from math import sqrt
MAXN = 3005
spf = [0] * MAXN

def sieve():
	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, int(sqrt(MAXN)) + 1):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factors(x):
	while x != 1:
		yield spf[x]
		x //= spf[x]
sieve()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	cur = 1
	for i in range(2, 105 + 1):
		f = False
		for j in range(n):
			if not b[j]:
				if not a[j] % i:
					b[j] = cur
					f = 1
		if f:
			cur += 1
	print(max(b))
	print(*b)


import math
list3 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]
t = int(input())
while t != 0:
	n = int(input())
	list1 = list(map(int, input().split()))
	number = list1[0]
	list2 = list()
	for i in range(len(list1)):
		list2.append(-1)
	count = 1
	for i in range(len(list3)):
		f1 = 0
		for j in range(len(list1)):
			if list1[j] != -1 and list1[j] % list3[i] == 0:
				f1 = 1
				list2[j] = count
				list1[j] = -1
		if f1 == 1:
			count += 1
	print(len(set(list2)))
	for j in range(len(list2)):
		print(list2[j], end=' ')
	print()
	t -= 1


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	res = []
	used_colors = []
	for e in a:
		for (i, c) in enumerate(used_colors, start=1):
			if e % c == 0:
				res.append(i)
				break
		else:
			for c in primes:
				if e % c == 0:
					res.append(len(used_colors) + 1)
					used_colors.append(c)
					break
	print(len(used_colors))
	print(*res)


def NO():
	return print('NO')

def YES():
	return print('YES')

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

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

def STR():
	return input()

def MAP():
	return map(int, input().split())
import math
nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(INT()):
	s = INT()
	ans = []
	z = LIST()
	col = 1
	ans = [0 for i in range(len(z))]
	tam = [0 for i in range(11)]
	for i in range(len(nums)):
		for j in range(len(z)):
			if z[j] % nums[i] == 0:
				if ans[j] == 0:
					ans[j] = col
					tam[i] = 1
		if tam[i] == 1:
			col += 1
	x = tam.count(1)
	print(tam.count(1))
	for i in range(len(z)):
		for j in range(len(z)):
			if math.gcd(z[i], z[j]) == 1 and ans[i] == ans[j]:
				print(z[i], z[j])
	print(' '.join(map(str, ans)))


def factor(i):
	pr = []
	e = 2
	while e ** 2 <= i:
		if i % e == 0:
			pr.append(e)
			while i % e == 0:
				i = i // e
		e += 1
	if i > 1:
		pr.append(i)
	return pr

def solve():
	n = int(input())
	nums = list(map(int, input().split()))
	numf = list(map(factor, nums))
	colors = [0] * n
	primes = [i for i in range(2, 1001) if factor(i) == [i]]
	c = 0
	for p in primes:
		found = False
		for (i, n) in enumerate(nums):
			if colors[i] == 0 and p in numf[i]:
				if not found:
					found = True
					c += 1
				colors[i] = c
	print(c)
	print(*colors)
tt = int(input())
for _ in range(tt):
	solve()


from collections import defaultdict as dd
import math
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ans = [0] * len(lis)
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	dic = dd(list)
	for i in range(len(lis)):
		for j in prime:
			if math.gcd(lis[i], j) != 1:
				dic[j].append(i)
				break
	counter = 1
	for i in dic:
		for j in dic[i]:
			ans[j] = counter
		counter += 1
	print(counter - 1)
	print(*ans)


t = int(input())
while t:
	t += -1
	n = int(input())
	l = list(map(int, input().split()))
	x = 1
	col = [0] * 1005
	for i in range(2, 1002):
		if col[i]:
			continue
		for j in range(2, 1005):
			if j % i == 0:
				if col[j] == 0:
					col[j] = x
		x -= -1
	temp = []
	for i in l:
		temp.append(col[i])
	temp = list(set(temp))
	dic = {}
	x = 1
	for i in temp:
		dic[i] = x
		x -= -1
	print(len(set(temp)))
	for i in l:
		print(dic[col[i]], end=' ')
	print()


import sys
import math
from collections import defaultdict
import bisect
import random

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()

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 Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 1000000000 + 7
for _ in range(int(input())):
	N = int(input())
	A = alele()
	B = sorted(list(set(A)))
	c = 1
	maxi = 0
	mark = {}
	for i in B:
		mark[i] = 0
	for i in range(2, 1001):
		g = 0
		for j in B:
			if mark.get(j, -1) == 0:
				if j % i == 0:
					g = 1
					maxi = c
					mark[j] = c
		if g == 1:
			c += 1
	print(maxi)
	for i in A:
		print(mark[i], end=' ')
	print()


def primes(n):
	is_prime = [True] * (n + 1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(n ** 0.5) + 1):
		if not is_prime[i]:
			continue
		for j in range(i * 2, n + 1, i):
			is_prime[j] = False
	return [i for i in range(n + 1) if is_prime[i]]
primes = primes(int(1000 ** 0.5) + 1)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ret = [0] * n
	idx = 1
	for j in range(11):
		max_index = 0
		max_count = 0
		for k in range(len(primes)):
			count = sum((1 for i in range(n) if a[i] % primes[k] == 0 and ret[i] == 0))
			if count > max_count:
				max_index = k
				max_count = count
		if max_count == 0:
			break
		for i in range(n):
			if a[i] % primes[max_index] == 0 and ret[i] == 0:
				ret[i] = idx
		idx += 1
	print(idx - 1)
	print(*ret)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

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

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

def I():
	return int(stdin.readline())
P = 1000000007
fac = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
for t in range(I()):
	n = I()
	lis = L()
	arr = [0 for i in range(n)]
	for i in range(n):
		for j in fac:
			if lis[i] % j == 0:
				arr[i] = j
				break
	st = list(set(arr))
	print(len(st))
	for i in range(n):
		print(st.index(arr[i]) + 1, end=' ')
	print()


import math
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0] * n
	color = dict()
	counter = 0
	for i in range(n):
		number = arr[i]
		if number % 2 == 0:
			prime = 2
		else:
			for j in range(3, int(math.sqrt(number)) + 1, 2):
				if number % j == 0:
					prime = j
					break
		if prime in color:
			c = color[prime]
		else:
			counter += 1
			color[prime] = counter
			c = color[prime]
		ans[i] = c
	print(len(set(ans)))
	print(*ans)


t = int(input())
for j in range(t):
	n = int(input())
	vec = list(map(int, input().split()))
	vec2 = []
	prim = set()
	for i in vec:
		if i % 2 == 0:
			vec2.append(2)
			prim.add(2)
		elif i % 3 == 0:
			vec2.append(3)
			prim.add(3)
		elif i % 5 == 0:
			vec2.append(5)
			prim.add(5)
		elif i % 7 == 0:
			vec2.append(7)
			prim.add(7)
		elif i % 11 == 0:
			vec2.append(11)
			prim.add(11)
		elif i % 13 == 0:
			vec2.append(13)
			prim.add(13)
		elif i % 17 == 0:
			vec2.append(17)
			prim.add(17)
		elif i % 19 == 0:
			vec2.append(19)
			prim.add(19)
		elif i % 23 == 0:
			vec2.append(23)
			prim.add(23)
		elif i % 29 == 0:
			vec2.append(29)
			prim.add(29)
		elif i % 31 == 0:
			vec2.append(31)
			prim.add(31)
	m = len(prim)
	print(m)
	dicti = {}
	for i in vec2[:n - 1]:
		if i not in dicti:
			print(m, end=' ')
			dicti[i] = m
			m = m - 1
		else:
			print(dicti[i], end=' ')
	if vec2[-1] not in dicti:
		print(m)
		dicti[i] = m
		m = m - 1
	else:
		print(dicti[vec2[-1]])


from math import gcd
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = 11
	colours = [0] * n
	col = 0
	sieve = [0 for i in range(1002)]
	p = 2
	while p * p <= 1000:
		if sieve[p] == 0:
			col += 1
			sieve[p] = col
			for i in range(p * p, 1001, p):
				sieve[i] = col
		p += 1
	usedCol = defaultdict(int)
	for i in range(1, m):
		usedCol[i] = 0
	for i in range(n):
		colours[i] = sieve[arr[i]]
		usedCol[colours[i]] += 1
	neg = min(colours)
	neg -= 1
	for i in range(n):
		colours[i] -= neg
	usednum = set(colours)
	final = 0
	mapp = defaultdict(int)
	for i in colours:
		if i in usednum:
			final += 1
			mapp[i] = final
			usednum.remove(i)
	colours = [mapp[i] for i in colours]
	print(max(colours))
	print(*colours)


prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	ans = []
	for i in lis:
		for j in range(11):
			if i % prime[j] == 0:
				ans.append(j + 1)
				break
	k = set(ans)
	aa = len(k)
	print(aa)
	ans2 = [0] * n
	c = 1
	for i in k:
		for j in range(n):
			if ans[j] == i:
				ans2[j] = c
		c += 1
	print(*ans2)


t = int(input())

def sieve(n):
	ass = []
	is_prime = [True] * (n + 1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(n ** 0.5) + 1):
		if not is_prime[i]:
			continue
		for j in range(i * 2, n + 1, i):
			is_prime[j] = False
	for i in range(n + 1):
		if is_prime[i]:
			ass.append(i)
	return ass
P = sieve(1000)
P = P[0:11]
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ans = [0] * n
	c = 1
	for j in range(11):
		p = P[j]
		flag = False
		for i in range(n):
			if A[i] % p == 0 and ans[i] == 0:
				ans[i] = c
				flag = True
		if flag:
			c += 1
	m = len(set(ans))
	print(m)
	print(*ans)


P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
T = int(input())
for _ in range(T):
	N = int(input())
	A = [int(a) for a in input().split()]
	X = [-1] * N
	D = [-1] * 11
	for (i, a) in enumerate(A):
		for (j, p) in enumerate(P):
			if a % p == 0:
				X[i] = j
				if D[j] < 0:
					D[j] = max(D) + 1
				break
	print(max(D) + 1)
	print(*[D[x] + 1 for x in X])


c = set()
for i in range(1001):
	j = 2
	while j * j <= i:
		if i % j == 0:
			while i % j == 0:
				i = i // j
			c.add(j)
		j += 1
	if i != 1:
		c.add(i)
c = sorted(list(c))[1:12]
for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [[] for i in range(1001)]
	for i in range(n):
		j = 2
		while j * j <= a[i]:
			if a[i] % j == 0:
				while a[i] % j == 0:
					a[i] = a[i] // j
				b[j].append(i)
			j += 1
		if a[i] != 1:
			b[a[i]].append(i)
	used = [-1 for i in range(n)]
	cnt = 0
	now = 0
	for i in range(2, 1001):
		if cnt == n:
			break
		check = True
		for j in range(len(b[i])):
			if used[b[i][j]] == -1:
				if check:
					now += 1
					check = False
				used[b[i][j]] = now
	print(len(set(used)))
	for i in range(n):
		print(used[i], end=' ')
	print()


from math import sqrt

def primeSieve():
	n = 40
	isPrime = [1] * n
	for i in range(2, int(sqrt(n))):
		if isPrime[i] == 1:
			for j in range(i * i, n, i):
				isPrime[j] = 0
	primes = []
	for i in range(2, 40):
		if isPrime[i]:
			primes.append(i)
	return primes

def main():
	primes = primeSieve()
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		count = 0
		used = [0] * n
		color = 1
		for p in primes:
			flag = 0
			for i in range(n):
				if a[i] % p == 0:
					flag = 1
				if used[i] == 0 and a[i] % p == 0:
					a[i] = color
					used[i] = 1
					count += 1
			if count == n:
				break
			if flag == 1:
				color += 1
		print(color)
		print(*a, sep=' ')
main()


def simple_nums(n):
	lst = [True for x in range(n + 1)]
	lst[0] = False
	lst[1] = False
	for i in range(len(lst)):
		if lst[i]:
			for k in range(i * 2, len(lst), i):
				lst[k] = False
	lst2 = []
	for i in range(len(lst)):
		if lst[i]:
			lst2.append(i)
	return lst2

def main():
	lst1 = simple_nums(500)
	n = int(input())
	lst = list(map(int, input().split()))
	cols = [0 for _ in range(n)]
	used = set()
	for i in range(n):
		for k in range(11):
			if lst[i] % lst1[k] == 0:
				cols[i] = k + 1
				used.add(k + 1)
				break
	dct = dict()
	m = 1
	for i in used:
		dct[i] = m
		m += 1
	print(len(used))
	for i in cols:
		print(dct[i], end=' ')
	print()
t = int(input())
for i in range(t):
	main()


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for _ in range(t):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		color_count = 0
		used = [0] * 11
		mp = {}
		res = []
		for x in arr:
			for (i, div) in enumerate(prime):
				if x % div == 0:
					if used[i] == 0:
						color_count += 1
						used[i] = 1
						mp[div] = color_count
						res.append(mp[div])
						break
					else:
						res.append(mp[div])
						break
		stdout.write(str(color_count) + '\n')
		stdout.write(' '.join([str(x) for x in res]) + '\n')
main()


t = int(input())
p = [2, 3, 5, 7]
for i in range(10, 38):
	k = 2
	sqrt = i ** 0.5
	while k <= sqrt and i % k != 0:
		k += 1
	if k > sqrt:
		p.append(i)
ans = []
counter = 0
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	now = []
	for j in range(n):
		d = 0
		while nums[j] % p[d] != 0:
			d += 1
		if p[d] not in now:
			now.append(p[d])
		nums[j] = now.index(p[d]) + 1
	ans.append([len(now), nums])
for i in ans:
	print(i[0])
	print(*i[1])


import math
t = int(input())
for k in range(t):
	n = int(input())
	nums = list(map(int, input().rstrip().split()))
	prime_nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	result = [0] * n
	color = 1
	for j in range(len(prime_nums)):
		for k1 in range(len(nums)):
			if nums[k1] % prime_nums[j] == 0:
				if result[k1] == 0:
					result[k1] = color
		color = max(result) + 1
	print(max(result))
	print(*result)


from math import gcd

def getprime(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1
primesArr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
tt = int(input())
for qwerty in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	used = [False] * 11
	clr = []
	for i in range(n):
		x = primesArr.index(getprime(a[i]))
		used[x] = True
		clr.append(x)
	cnt = 0
	num = []
	for i in range(11):
		num.append(cnt)
		if used[i]:
			cnt += 1
	print(cnt)
	for i in range(n):
		x = primesArr.index(getprime(a[i]))
		print(num[x] + 1, end=' ')
	print()


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	elem = [0] * n
	check = [False] * 11
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in range(n):
		for j in range(11):
			if a[i] % primes[j] == 0:
				elem[i] = primes[j]
				check[j] = True
				break
	m = 0
	i = 0
	while i < len(primes):
		if not check[i]:
			primes.pop(i)
			check.pop(i)
		else:
			i = i + 1
	di = {}
	print(len(primes))
	for i in range(len(primes)):
		di[primes[i]] = i + 1
	for i in elem:
		print(di[i], end=' ')
	print()


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)))
t = int(input())
for i in range(t):
	l1 = []
	m1 = 0
	val = 1
	(n, l) = (int(input()), list(map(int, input().split())))
	l2 = [0] * n
	for j in l:
		f = factors(j)
		l1.append(f)
	for j in range(2, 32):
		m = 0
		for k in range(n):
			if j in l1[k]:
				l2[k] += val
				l1[k] = [0]
				m = 1
		if m == 1:
			val += 1
	print(max(l2))
	for j in l2:
		print(j, end=' ')
	print()


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

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

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

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

def invr():
	return map(int, input().rstrip().split())
prime_list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = inp()
for _ in range(t):
	n = inp()
	nums = inlt()
	ans = [0 for i in range(n)]
	used = dict()
	cnt = 0
	for (index, i) in enumerate(nums):
		for prime in range(len(prime_list)):
			if i % prime_list[prime] == 0:
				if prime_list[prime] not in used:
					cnt += 1
					ans[index] = cnt
					used[prime_list[prime]] = cnt
				else:
					ans[index] = used[prime_list[prime]]
				break
	print(cnt)
	print(*ans)


import math, sys
from collections import defaultdict, Counter, deque
from functools import reduce
INF = float('inf')
MOD = int(1000000000.0) + 7

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

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = defaultdict(int)
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors[i] += 1
			n //= i
		i += 1
	if n > 1:
		factors[n] += 1
	return factors

def main():
	n = int(input())
	arr = array()
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = [0 for i in range(n)]
	m = 1
	for p in primes:
		used = 0
		for i in range(n):
			if not ans[i] and arr[i] % p == 0:
				ans[i] = m
				used = 1
		if used:
			m += 1
	print(m - 1)
	print(*ans)

class DSU:

	def __init__(self, n):
		self.p = [i for i in range(n + 1)]
		self.size = [1 for i in range(n + 1)]
		self.minmax = [[i, i] for i in range(n + 1)]
		self.n = n

	def find(self, node):
		if self.p[node] != node:
			self.p[node] = self.find(self.p[node])
		return self.p[node]

	def union(self, source, dest):
		source = self.find(source)
		dest = self.find(dest)
		if source != dest:
			if self.size[source] < self.size[dest]:
				(source, dest) = (dest, source)
			self.p[dest] = source
			self.size[source] += self.size[dest]
			mini = min(self.minmax[source][0], self.minmax[dest][0])
			maxi = max(self.minmax[source][1], self.minmax[dest][1])
			self.minmax[source] = [mini, maxi]

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

def print(*args, sep=' ', end='\n'):
	first = True
	for arg in args:
		if not first:
			sys.stdout.write(sep)
		sys.stdout.write(str(arg))
		first = False
	sys.stdout.write(end)

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

def array():
	return list(map(int, input().split()))
t = 1
t = int(input())
for _ in range(t):
	main()


def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	list_of_color = []
	for i in a:
		list_of_color.append(smallestDivisor(i))
	list_of_color = list(set(list_of_color))
	string = ''
	for i in range(len(a)):
		for j in range(len(list_of_color)):
			if smallestDivisor(a[i]) == list_of_color[j]:
				string = string + str(j + 1) + ' '
	print(len(list_of_color))
	print(string)


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 sieve(n):
	primes = [-1] * 1101
	for j in range(2, 1100):
		if primes[j] == -1:
			for k in range(0, 1100, j):
				if primes[k] == -1:
					primes[k] = j
	return primes
from math import gcd
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = sieve(0)
	ans = [1] * n
	for i in range(n):
		ans[i] = s[a[i]]
	an = sorted(list(set(ans)))
	di = {}
	for i in range(len(an)):
		di[an[i]] = str(i + 1)
	print(len(an))
	print(' '.join((di[k] for k in ans)))


for _ in range(int(input())):
	n = int(input())
	a = [int(o) for o in input().split()]
	kk = 1
	ans = [0] * n
	i = 2
	while i <= 1000:
		flag = 0
		for j in range(n):
			if ans[j] == 0 and a[j] % i == 0:
				ans[j] = kk
				flag = 1
		if flag == 1:
			kk += 1
		i += 1
	kk -= 1
	print(kk)
	print(*ans)


def modifyarr(arr):
	for i in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
		j = i * i
		while j <= 1000:
			if arr[j] == 1:
				arr[j] = i
			j += i
arr = [1 for i in range(1001)]
modifyarr(arr)
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	arrdone = [0 for i in range(11)]
	for i in range(n):
		oi = arr[li[i]]
		if oi == 2:
			arrdone[0] = 1
		if oi == 3:
			arrdone[1] = 1
		if oi == 5:
			arrdone[2] = 1
		if oi == 7:
			arrdone[3] = 1
		if oi == 11:
			arrdone[4] = 1
		if oi == 13:
			arrdone[5] = 1
		if oi == 17:
			arrdone[6] = 1
		if oi == 19:
			arrdone[7] = 1
		if oi == 23:
			arrdone[8] = 1
		if oi == 29:
			arrdone[9] = 1
		if oi == 31:
			arrdone[10] = 1
	lused = []
	oip = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in range(11):
		if arrdone[i] == 1:
			lused.append(oip[i])
	m = len(lused)
	print(m)
	for i in range(n):
		x = arr[li[i]]
		for j in range(m):
			if lused[j] == x:
				print(j + 1, end=' ')
	print()


n = int(input())
l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for k in range(n):
	a = int(input())
	t = list(map(int, input().split()))
	ans = []
	count = 0
	l1 = [0]
	for i in t:
		check = False
		for j in range(1, len(l1)):
			if i % l1[j] == 0:
				ans.append(j)
				check = True
				break
		if check == False:
			for j in l:
				if i % j == 0:
					count += 1
					l1.append(j)
					ans.append(count)
					break
	print(count)
	print(*ans)


import math
l1 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for j in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = l
	d = {}
	d1 = {}
	k = max(l)
	c = 1
	d3 = {}
	for i in l1:
		if i > k:
			break
		for j in l:
			if j % i == 0:
				d[j] = i
	for i in d.values():
		if i not in d1:
			d1[i] = c
			c += 1
	print(c - 1)
	for i in ans:
		print(d1[d[i]], end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	temp = {2: 12, 3: 12, 5: 12, 7: 12, 11: 12, 13: 12, 17: 12, 19: 12, 23: 12, 29: 12, 31: 12}
	count = 1
	ans = []
	for i in c:
		for j in temp:
			if i % j == 0:
				if temp[j] == 12:
					temp[j] = count
					count += 1
				ans.append(temp[j])
				break
	print(count - 1)
	print(*ans, sep=' ')


t = int(input())
i = 0
while i < t:
	n = int(input())
	arr = list(map(int, input().split()))
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	temp = {2: 36, 3: 36, 5: 36, 7: 36, 11: 36, 13: 36, 17: 36, 19: 36, 23: 36, 29: 36, 31: 36}
	count = 1
	ans = []
	for x in arr:
		for y in prime:
			if x % y == 0:
				if temp[y] == 36:
					temp[y] = count
					count = count + 1
				ans.append(temp[y])
				break
	print(count - 1)
	print(*ans, sep=' ')
	i = i + 1
(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)


debug = 0
if debug:
	print('DEBUG MODE ON')
	f = None

	def new_input():
		global f
		if f == None:
			f = open('input.txt')
		return f.readline()
	input = new_input

def readrange():
	return range(int(input()))

def readint():
	return int(input())

def readarr():
	return [int(x) for x in input().split()]

def readmat(rows):
	return [readarr() for _ in range(rows)]
primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)
for _ in readrange():
	input()
	arr = readarr()
	for k in range(len(arr)):
		arr[k] = min((p for p in primes if arr[k] % p == 0))
	colors = tuple(set(arr))
	print(len(colors))
	print(*[colors.index(element) + 1 for element in arr])


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	A = [int(i) for i in input().split()]
	D = []
	for a in A:
		for p in P:
			if a % p == 0:
				D.append(p)
				break
	print(len(set(D)))
	DD = list(set(D))
	DDD = dict()
	cl = 1
	for dd in DD:
		DDD[dd] = cl
		cl += 1
	Ans = []
	for d in D:
		Ans.append(DDD[d])
	print(*Ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	p_associated = []
	dic = {}
	for i in a:
		for p in primes:
			if i % p == 0:
				p_associated.append(p)
				if p not in dic.keys():
					dic[p] = [i]
				else:
					dic[p].append(i)
				break
	print(len(dic.keys()))
	color = {}
	c = 1
	for p in dic.keys():
		color[p] = c
		c += 1
	for i in p_associated:
		print(color[i], end=' ')


from math import ceil

def is_prime(x):
	if x == 2:
		return True
	for i in range(2, ceil(x ** 0.5) + 1):
		if x % i == 0:
			return False
	return True
for t in range(int(input())):
	n = int(input())
	factors = {}
	ans = [0] * n
	arr = list(map(int, input().split()))
	for i in range(n):
		for j in range(2, ceil(arr[i] ** 0.5) + 1):
			if is_prime(j):
				if arr[i] % j == 0:
					try:
						if type(factors[j]) == list:
							factors[j].append(i)
					except:
						factors[j] = [i]
	done = {}
	for i in range(n):
		done[i] = -1
	m = 1
	for i in factors.keys():
		colored = False
		for j in factors[i]:
			if done[j] == -1:
				done[j] = m
				colored = True
		if colored:
			m += 1
	print(max(done.values()))
	print(*done.values())


from collections import defaultdict
ccnt = 0
for i in range(100000):
	ccnt += 2
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	laa = set(l)
	hash = defaultdict(int)
	cnt = 1
	for i in range(2, 1001):
		z = i
		k = 1
		flag = 0
		while z * k <= 1000:
			zaa = z * k
			k += 1
			if zaa in laa and hash[zaa] == 0:
				flag = 1
				hash[zaa] = cnt
		if flag:
			cnt += 1
	ans = []
	for i in l:
		ans.append(hash[i])
	print(len(set(ans)))
	print(*ans)


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write
for _ in range(int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	tmp = [False for _ in range(n)]
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	used = [False for _ in range(11)]
	s = set()
	for idx in range(n):
		for i in range(11):
			if k[idx] % prime[i] == 0:
				tmp[idx] = prime[i]
				used[i] = True
				break
	d = {}
	color = 1
	for i in range(11):
		if used[i]:
			d[prime[i]] = color
			color += 1
	print(f'{len(d)}\n')
	for i in tmp:
		print(f'{d[i]} ')
	print('\n')


import math
for _ in range(int(input())):
	n = int(input())
	arr = [int(s) for s in input().split()]
	freq = [[] for i in range(1001)]
	for i in range(len(arr)):
		x = arr[i]
		for j in range(2, int(math.sqrt(x)) + 1):
			if x % j == 0:
				freq[j].append(i)
			while x % j == 0:
				x = x // j
		if x > 1:
			freq[x].append(i)
	count = 1
	ans = [0] * n
	for i in freq:
		flag = False
		for j in i:
			if ans[j] == 0:
				flag = True
				ans[j] = count
		if flag:
			count += 1
	print(count - 1)
	for i in ans:
		print(i, end=' ')
	print()


num = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	dic = {}
	ans = []
	tot = 0
	for ele in l:
		for i in range(11):
			if ele % num[i] == 0:
				if i not in dic:
					tot += 1
					dic[i] = tot
				ans.append(dic[i])
				break
	print(tot)
	print(*ans)


def main():
	import sys
	input = sys.stdin.buffer.readline
	P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for _ in range(int(input())):
		N = int(input())
		A = list(map(int, input().split()))
		ans = [0] * N
		seen = {}
		k = 1
		for (i, a) in enumerate(A):
			for (j, p) in enumerate(P):
				if a % p == 0:
					if not p in seen:
						seen[p] = k
						ans[i] = k
						k += 1
					else:
						ans[i] = seen[p]
					break
		print(max(ans))
		print(*ans)
main()


import math

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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	c = 1
	colors = [-1] * n
	for (i, p_i) in enumerate([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]):
		used = False
		for (j, a_j) in enumerate(a):
			if colors[j] == -1 and a_j % p_i == 0:
				colors[j] = c
				used = True
		if used:
			c += 1
	print(c - 1)
	print(*colors)

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


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	col = 0
	ans = []
	di = {2: 0, 3: 0, 5: 0, 7: 0, 11: 0, 13: 0, 17: 0, 19: 0, 23: 0, 29: 0, 31: 0}
	for i in l:
		for j in di:
			if i % j == 0:
				if di[j] == 0:
					col += 1
					di[j] = col
				ans.append(di[j])
				break
	print(col)
	print(*ans)


from sys import stdin, stdout

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

def __main__():
	t = int(read())
	for t0 in range(t):
		n = int(read())
		A = [int(i) for i in read().split()]
		res = []
		d = {}
		ind = 0
		for a in A:
			if a % 2 == 0:
				if 2 not in d:
					ind += 1
					d.update({2: ind})
				res.append(d.get(2))
			elif a % 3 == 0:
				if 3 not in d:
					ind += 1
					d.update({3: ind})
				res.append(d.get(3))
			elif a % 5 == 0:
				if 5 not in d:
					ind += 1
					d.update({5: ind})
				res.append(d.get(5))
			elif a % 7 == 0:
				if 7 not in d:
					ind += 1
					d.update({7: ind})
				res.append(d.get(7))
			elif a % 11 == 0:
				if 11 not in d:
					ind += 1
					d.update({11: ind})
				res.append(d.get(11))
			elif a % 13 == 0:
				if 13 not in d:
					ind += 1
					d.update({13: ind})
				res.append(d.get(13))
			elif a % 17 == 0:
				if 17 not in d:
					ind += 1
					d.update({17: ind})
				res.append(d.get(17))
			elif a % 19 == 0:
				if 19 not in d:
					ind += 1
					d.update({19: ind})
				res.append(d.get(19))
			elif a % 23 == 0:
				if 23 not in d:
					ind += 1
					d.update({23: ind})
				res.append(d.get(23))
			elif a % 29 == 0:
				if 29 not in d:
					ind += 1
					d.update({29: ind})
				res.append(d.get(29))
			elif a % 31 == 0:
				if 31 not in d:
					ind += 1
					d.update({31: ind})
				res.append(d.get(31))
		r = [str(k) for k in res]
		r0 = ' '.join(r) + '\n'
		nx = str(max(res)) + '\n'
		stdout.write(nx)
		stdout.write(r0)
__main__()


T = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(T):
	(n, co) = (int(input()), list(map(int, input().split())))
	(color, vis) = ([0] * n, {})
	for i in range(n):
		for j in range(11):
			if co[i] % p[j] == 0:
				if j not in vis.keys():
					vis[j] = len(vis)
				color[i] = j
				break
	color = [vis[u] + 1 for u in color]
	print(len(vis))
	print(*color)


import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input().strip('\n'))
si = lambda : input()
dgl = lambda : list(map(int, input().strip('\n')))
f = lambda : map(int, input().strip('\n').split())
il = lambda : list(map(int, input().strip('\n').split()))
ls = lambda : list(input().strip('\n'))
let = 'abcdefghijklmnopqrstuvwxyz'
l = [0 for i in range(1001)]
for i in range(2, 1001):
	if l[i] == 0:
		for j in range(i * 2, 1001, i):
			l[j] = 1
lprime = [i for i in range(2, 1001) if l[i] == 0]
for _ in range(ii()):
	n = ii()
	l = il()
	d = dict()
	for i in range(n):
		for j in lprime:
			if l[i] % j == 0:
				if j in d:
					d[j].append(i)
				else:
					d[j] = [i]
				break
	it = 1
	for i in d:
		for j in d[i]:
			l[j] = it
		it += 1
	print(it - 1)
	print(*l)


def solve(ans1, ans2):
	n = int(input())
	li = [int(x) for x in input().split()]
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	d = {}
	clr = []
	colour = 1
	for ele in li:
		for i in range(11):
			if ele % primes[i] == 0:
				if primes[i] not in d:
					d[primes[i]] = colour
					colour += 1
				clr.append(d[primes[i]])
				break
	ans1.append(colour - 1)
	ans2.append(clr)
	return
n = int(input())
ans1 = []
ans2 = []
for i in range(n):
	solve(ans1, ans2)
for i in range(n):
	print(ans1[i])
	print(*ans2[i])


c = [0] * 1001
col = 1
for i in range(2, 1001):
	if c[i] == 0:
		for j in range(i * 2, 1001, i):
			if c[j] == 0:
				c[j] = col
		col += 1

def tc():
	n = int(input())
	a = [int(x) for x in input().split()]
	if n <= 11:
		print(n)
		print(' '.join(map(str, range(1, n + 1))))
		return
	ans = [c[x] for x in a]
	key = {k: v for (k, v) in zip(set(ans), range(1, 12))}
	ans = [key[x] for x in ans]
	print(len(key))
	print(' '.join(map(str, ans)))
T = int(input())
for _ in range(T):
	tc()


import math
t = int(input())
prime = [True for i in range(1001)]
prime[1] = False
parent = [i for i in range(1001)]
for i in range(2, int(math.sqrt(1001)) + 1):
	if prime[i]:
		k = i * i
		while k < 1001:
			prime[k] = False
			parent[k] = i
			k = k + i
for test in range(t):
	n = int(input())
	a = input().split(' ')
	for i in range(len(a)):
		a[i] = int(a[i])
	color = [-1 for i in range(1001)]
	visited = [False for i in range(1001)]
	cnt = 1
	for num in a:
		if not visited[parent[num]]:
			visited[parent[num]] = True
			color[parent[num]] = cnt
			cnt += 1
	ans = str(color[parent[a[0]]])
	for i in range(1, len(a)):
		ans = ans + ' ' + str(color[parent[a[i]]])
	print(cnt - 1)
	print(ans)


from math import *
from bisect import bisect_left, bisect_right
from sys import stdin, stdout, setrecursionlimit
from collections import Counter
input = lambda : stdin.readline().strip()
print = stdout.write
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	colors = []
	for i in ls:
		for j in range(len(primes)):
			if i % primes[j] == 0:
				colors.append(j + 1)
				break
	indices = sorted(list(set(colors)))
	d = {indices[i]: i for i in range(len(indices))}
	print(str(len(d)) + '\n')
	for i in colors:
		print(str(d[i] + 1) + ' ')
	print('\n')


Numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	Check = [0] * 11
	N = int(input())
	Color = 1
	X = list(map(int, input().split()))
	Answer = []
	for i in X:
		Index = 0
		for j in range(11):
			if i % Numbers[j] == 0:
				Index = j
				break
		if Check[Index] != 0:
			Answer.append(Check[Index])
		else:
			Answer.append(Color)
			Check[Index] = Color
			Color += 1
	print(max(Answer))
	print(*Answer)


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)))

def isPrime(n):
	if n <= 1:
		return False
	for i in range(2, n):
		if n % i == 0:
			return False
	return True
primes = []
for i in range(2, 1000 + 1):
	if isPrime(i):
		primes.append(i)
for _ in range(iinput()):
	n = iinput()
	a = rlinput()
	d = defaultdict(int)
	for i in a:
		d[i] = 0
	colors = [0] * n
	left = []
	color = 1
	for i in primes:
		j = 1
		found = False
		while j * i <= 1000:
			if j * i in d and d[j * i] == 0:
				d[j * i] = color
				found = True
			j += 1
		if found:
			color += 1
	for i in range(n):
		colors[i] = d[a[i]]
	print(max(colors))
	print(*colors)


def primeFacorize(x):
	p = [7, 11, 13, 17, 19, 23, 29, 31, 37]
	ans = []
	t = 0
	for i in p:
		if x % i == 0:
			t = i
			break
	return [t, x // t]
for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	count = [0, 0, 0]
	ansarray = []
	primes = {}
	maxV = 0
	for i in array:
		if i % 2 == 0:
			if count[0] == 0:
				maxV += 1
				count[0] = maxV
			ansarray.append(count[0])
		elif i % 3 == 0:
			if count[1] == 0:
				maxV += 1
				count[1] = maxV
			ansarray.append(count[1])
		elif i % 5 == 0:
			if count[2] == 0:
				maxV += 1
				count[2] = maxV
			ansarray.append(count[2])
		else:
			pk = primeFacorize(i)
			if pk[0] in primes:
				ansarray.append(primes[pk[0]])
			elif pk[1] in primes:
				ansarray.append(primes[pk[1]])
			else:
				maxV += 1
				primes[pk[0]] = maxV
				ansarray.append(maxV)
	print(maxV)
	print(*ansarray)


d = {i: 0 for i in range(1001)}
pos = 1
v = int(1001 ** 0.5) + 1
for i in range(2, v):
	if d[i] == 0:
		d[i] = i
		for j in range(i * i, 1001, i):
			if j % i == 0:
				d[j] = i
cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	pos = 0
	d1 = {}
	v = []
	for i in a:
		if d[i] not in d1:
			pos += 1
			d1[d[i]] = pos
		v.append(d1[d[i]])
	print(pos)
	print(*v)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
d = {i: 0 for i in range(1001)}
pos = 1
v = int(1001 ** 0.5) + 1
for i in range(2, v):
	if d[i] == 0:
		d[i] = i
		for j in range(i * i, 1001, i):
			if j % i == 0:
				d[j] = i
cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, input().split()))
	pos = 0
	d1 = {}
	v = []
	for i in a:
		if d[i] not in d1:
			pos += 1
			d1[d[i]] = pos
		v.append(d1[d[i]])
	print(pos)
	print(*v)


from math import sqrt

def delit(a, prost1):
	deli = []
	for i in range(2, int(sqrt(a)) + 1):
		if a % i == 0:
			deli.append(prost1[i])
			while a % i == 0:
				a //= i
	return deli
prost = dict(zip([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499], range(95)))
for ktirs in range(int(input())):
	n = int(input())
	nums = []
	for i in range(95):
		nums.append([])
	pos = -1
	for i in list(map(int, input().split())):
		pos += 1
		k = delit(i, prost)
		for j in k:
			nums[j].append(pos)
	ans = [0] * n
	num = 1
	for j in range(11):
		tr = False
		for i in nums[j]:
			if ans[i] == 0:
				ans[i] = num
				tr = True
		num += tr
	print(num - 1)
	print(*ans)


import sys
t = -1

def input():
	global t
	t += 1
	return d[t]
d = sys.stdin.readlines()
k = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(k):
	n = int(input())
	a = list(map(int, input().split()))
	answer = [-1] * n
	number = [-1] * 11
	count = 1
	for i in range(n):
		for j in range(11):
			if a[i] % p[j] == 0:
				if number[j] == -1:
					number[j] = count
					count += 1
				answer[i] = number[j]
				break
	print(count - 1)
	print(*answer)


primes = [False] * 1010
for i in range(2, 1010):
	n = 0
	while i * (i + n) < 1010:
		primes[i * (i + n)] = True
		n += 1
final = []
for i in range(len(primes)):
	if not primes[i]:
		final.append(i)
final.pop(0)
final.pop(0)
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(p) for p in input().split()]
	colors = [0] * n
	c = 0
	for i in final:
		cnt = 0
		for j in range(n):
			if colors[j]:
				continue
			if arr[j] % i == 0:
				cnt = 1
				colors[j] = c + 1
		if cnt:
			c += 1
	print(max(colors))
	print(*colors)


from math import *
for zz in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	cc = {}
	ci = 1
	ans = [0] * n
	for i in range(n):
		j = 2
		while j < a[i]:
			if a[i] % j == 0:
				break
			else:
				j += 1
		if j not in cc:
			cc[j] = ci
			ci += 1
		ans[i] = cc[j]
	print(ci - 1)
	print(*ans)


from sys import stdin
input = stdin.readline
q = int(input())
for rwerew in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	odp = []
	secik = set()
	for i in range(n):
		for j in range(11):
			if l[i] % pr[j] == 0:
				odp.append(j + 1)
				secik.add(j + 1)
				break
	print(len(secik))
	d = {}
	num = 1
	for i in secik:
		d[i] = num
		num += 1
	for i in range(n):
		if i < n - 1:
			print(d[odp[i]], end=' ')
		else:
			print(d[odp[i]])


t = int(input())
import math
delay = []
for _ in range(t):
	n = int(input())
	arr = map(int, input().split())
	color = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	colortf = [False for _ in range(11)]
	ans = [-1 for _ in range(n)]
	for (idx, ele) in enumerate(arr):
		for i in range(11):
			if math.gcd(color[i], ele) > 1:
				ans[idx] = i
				colortf[i] = True
	numdiff = 0
	for c in colortf:
		if c == True:
			numdiff += 1
	cnt = 1
	mapdic = {}
	new_ans = [-1 for _ in range(n)]
	for (i, a) in enumerate(ans):
		if a not in mapdic:
			mapdic[a] = cnt
			new_ans[i] = cnt
			cnt += 1
		else:
			val = mapdic[a]
			new_ans[i] = val
	an = cnt - 1
	print(an)
	print(' '.join([str(x) for x in new_ans]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	visited = [0] * n
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	t = 1
	for j in range(len(prime)):
		k = 0
		for i in range(n):
			if not visited[i]:
				if not a[i] % prime[j]:
					visited[i] = t
					k = 1
		if k:
			t += 1
	print(len(set(visited)))
	print(*visited)


primes = []
for i in range(2, 1001):
	flag = True
	for j in range(2, int(i ** 0.5) + 1):
		if i % j == 0:
			flag = False
	if flag:
		primes.append(i)
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	color = [0 for i in range(n)]
	m = 1
	for i in range(len(primes)):
		flag = False
		for j in range(n):
			if a[j] % primes[i] == 0 and color[j] == 0:
				color[j] = m
				flag = True
		if flag:
			m += 1
	print(m - 1)
	print(*color)
	t -= 1


def factor(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	colors = [0 for i in range(11)]
	current = 0
	ans = []
	for i in a:
		found = 0
		for j in range(current):
			if i % colors[j] == 0:
				ans.append(j + 1)
				found = 1
				break
		if not found:
			colors[current] = factor(i)
			ans.append(current + 1)
			current += 1
	print(len(set(ans)))
	print(*ans)


from math import gcd
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = [0] * n
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	m = 1
	for i in range(11):
		flag = 0
		for j in range(n):
			if a[j] % p[i] == 0 and ans[j] == 0:
				ans[j] = m
				flag = 1
		if flag:
			m += 1
	print(max(ans))
	print(*ans)


def colorize(n):
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for p in range(len(primes)):
		if n % primes[p] == 0:
			return p
t = int(input())
for test in range(t):
	n = int(input())
	lst = [int(i) for i in input().split()]
	ans = [colorize(i) for i in lst]
	conv = list(set(ans))
	print(len(conv))
	anticonv = [0 for i in range(12)]
	for it in range(len(conv)):
		anticonv[conv[it]] = it
	realans = [str(anticonv[i] + 1) for i in ans]
	print(' '.join(realans))


import math

def isprime(n):
	for i in range(2, int(math.sqrt(n) + 1)):
		if n % i == 0:
			return 0
	return 1
t = int(input())
for j in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	color = [0] * 12
	ans = [0] * 11
	ria = [0] * n
	i = 0
	k = 2
	while i < 11:
		if isprime(k):
			ans[i] = k
			k = k + 1
			i = i + 1
		else:
			k = k + 1
	m = 1
	c = 1
	for i in range(0, n):
		if color[1]:
			for k in range(1, c):
				if l[i] % color[k] == 0:
					ria[i] = int(k)
					m = 0
					break
		if m:
			for k in range(0, 11):
				if l[i] % ans[k] == 0:
					color[c] = ans[k]
					ria[i] = int(c)
					c = c + 1
					break
		m = 1
	print(c - 1)
	for i in range(0, n):
		print(ria[i], ' ', end='')


import os
import sys
from io import BytesIO, IOBase
import threading
from collections import Counter
mod = 998244353

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		clr = [-1] * n
		a = [-1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]
		c = 1
		for i in range(1, 12):
			b = False
			for j in range(n):
				if arr[j] % a[i] == 0 and clr[j] == -1:
					b = True
					clr[j] = c
			if b:
				c += 1
		print(max(clr))
		print(*clr)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import Counter
from collections import defaultdict
import math

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	l = []
	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 p in range(2, n):
		if prime[p]:
			l.append(p)
	return l
l = SieveOfEratosthenes(1001)
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	f = 1
	for j in l:
		ans = 0
		for i in range(0, n):
			if d[a[i]] == 0 and a[i] % j == 0:
				d[a[i]] = f
				ans = 1
		if ans == 1:
			f = f + 1
	ans = []
	mx = 0
	for i in range(0, n):
		ans.append(d[a[i]])
		mx = max(mx, d[a[i]])
	print(mx)
	print(*ans)


import sys
input = sys.stdin.readline
from math import *
mod = 10 ** 9 + 7

def bo(i):
	return ord(i) - ord('a')
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	p = {}
	for i in range(n):
		for j in range(len(prime)):
			if a[i] in p:
				continue
			if a[i] % prime[j] == 0:
				p[a[i]] = j
				break
	c = 0
	s = set()
	for i in p:
		s.add(p[i])
	print(len(list(s)))
	s = list(s)
	for i in range(n):
		print(s.index(p[a[i]]) + 1, end=' ')


t = int(input())
xx = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	aa = list(map(int, input().split()))
	x = [0 for i in range(n)]
	y = set()
	jj = 0
	for i in aa:
		k = 1
		for j in xx:
			if i % j == 0:
				ind = k
				y.add(k)
				break
			k += 1
		x[jj] = k
		jj += 1
	ss = {}
	l = 0
	for i in y:
		l += 1
		ss[i] = l
	print(len(y))
	for i in x:
		print(ss[i], end=' ')
	print()


def prime_list(n):
	sieve = [True] * n
	m = int(n ** 0.5)
	for i in range(2, m + 1):
		if sieve[i] == True:
			for j in range(i + i, n, i):
				sieve[j] = False
	return [i for i in range(2, n) if sieve[i] == True]

def answer(compositeIntegers):
	n = len(compositeIntegers)
	m = [i for i in range(12, 0, -1)]
	colors = [0] * n
	coloredElCount = 0
	primes = prime_list(999)
	colorId = m.pop()
	primeIndex = 0
	while coloredElCount != n:
		divider = primes[primeIndex]
		colorIsUsed = False
		for i in range(n):
			if colors[i] != 0:
				continue
			if compositeIntegers[i] % divider == 0:
				colors[i] = colorId
				coloredElCount += 1
				colorIsUsed = True
		primeIndex = primeIndex + 1
		if colorIsUsed is True:
			colorId = m.pop()
	return str(colorId - 1) + '\n' + ' '.join([str(c) for c in colors])
testCount = int(input())
for _ in range(testCount):
	n = input()
	compositeIntegers = list(map(int, input().split()))
	print(answer(compositeIntegers))


import math
import copy
T = int(input())

def gcdCheck(cL, i):
	for x in cL:
		if math.gcd(x, i) == 1:
			return False
	return True
while T:
	T -= 1
	n = int(input())
	A = [int(x) for x in input().split()]
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	colors = []
	m = {}
	for x in A:
		found = False
		for p in primes:
			found = x % p == 0
			if found:
				if p not in m.keys():
					m[p] = len(m.keys()) + 1
				colors.append(m[p])
				break
	print(len(m))
	print(*colors)


import math

def isPrime(x):
	for i in range(2, x // 2):
		if x % i == 0:
			return False
	return True
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())

def gcd(*arr):
	if len(arr) == 1:
		return arr[0]
	ret = math.gcd(arr[0], arr[1])
	for i in range(2, len(arr)):
		ret = math.gcd(arr[i], ret)
	return ret

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	c = [0 for i in range(n)]
	co = 1
	used = [False for i in range(11)]
	mapp = [i + 1 for i in range(11)]
	for i in range(11):
		for x in range(n):
			if a[x] % primes[i] == 0:
				if not c[x]:
					used[i] = True
					c[x] = i + 1
	m = min(c) - 1
	for (nn, i) in enumerate(used):
		if i:
			continue
		else:
			for i in range(nn, 11):
				mapp[i] -= 1
	for i in range(n):
		c[i] = mapp[c[i] - 1]
	print(max(c))
	for (n, i) in enumerate(c):
		print(i, end=' ')
	print()
for _ in range(t):
	solve()


def isPrime(n):
	i = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += 1
	return True
prime = [2]
for i in range(3, 1000, 2):
	if isPrime(i):
		prime.append(i)
l = [i for i in range(4, 1001) if i not in prime]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	col = -1
	cnt = 0
	for p in prime[:11]:
		flag = 0
		for i in range(n):
			if a[i] > 0:
				if a[i] % p == 0:
					a[i] = col
					cnt += 1
					flag = 1
		if cnt == n:
			break
		if flag:
			col -= 1
	if cnt < n:
		for i in range(n):
			if a[i] > 0:
				a[i] = col
				col -= 1
		col += 1
	col = abs(col)
	print(col)
	for i in range(n):
		a[i] = abs(a[i])
	print(*a)


t = int(input())
for i10 in range(t):
	k = 0
	s = 0
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	f = [0] * 11
	g = [0] * 11
	for i in range(n):
		if a[i] % 2 == 0:
			if f[0] == 1:
				b[i] = g[0]
			else:
				s += 1
				b[i] = s
				g[0] = s
			f[0] = 1
		elif a[i] % 3 == 0:
			if f[1] == 1:
				b[i] = g[1]
			else:
				s += 1
				b[i] = s
				g[1] = s
			f[1] = 1
		elif a[i] % 5 == 0:
			if f[2] == 1:
				b[i] = g[2]
			else:
				s += 1
				b[i] = s
				g[2] = s
			f[2] = 1
		elif a[i] % 7 == 0:
			if f[3] == 1:
				b[i] = g[3]
			else:
				s += 1
				b[i] = s
				g[3] = s
			f[3] = 1
		elif a[i] % 11 == 0:
			if f[4] == 1:
				b[i] = g[4]
			else:
				s += 1
				b[i] = s
				g[4] = s
			f[4] = 1
		elif a[i] % 13 == 0:
			if f[5] == 1:
				b[i] = g[5]
			else:
				s += 1
				b[i] = s
				g[5] = s
			f[5] = 1
		elif a[i] % 17 == 0:
			if f[6] == 1:
				b[i] = g[6]
			else:
				s += 1
				b[i] = s
				g[6] = s
			f[6] = 1
		elif a[i] % 19 == 0:
			if f[7] == 1:
				b[i] = g[7]
			else:
				s += 1
				b[i] = s
				g[7] = s
			f[7] = 1
		elif a[i] % 23 == 0:
			if f[8] == 1:
				b[i] = g[8]
			else:
				s += 1
				b[i] = s
				g[8] = s
			f[8] = 1
		elif a[i] % 29 == 0:
			if f[9] == 1:
				b[i] = g[9]
			else:
				s += 1
				b[i] = s
				g[9] = s
			f[9] = 1
		elif a[i] % 31 == 0:
			if f[10] == 1:
				b[i] = g[10]
			else:
				s += 1
				b[i] = s
				g[10] = s
			f[10] = 1
	print(max(b))
	print(*b)


t = int(input())
start = 2
end = 999
primes = []
for val in range(start, end + 1):
	if val > 1:
		for n in range(2, val):
			if val % n == 0:
				break
		else:
			primes.append(val)
for pp in range(0, t):
	n = int(input())
	ip = list(map(int, input().split()))
	visited = [0 for i in range(0, n)]
	mydict = {}
	count = 0
	f = 0
	for p in primes:
		for i in range(0, n):
			if visited[i] == 0 and ip[i] % p == 0:
				count = count + 1
				visited[i] = 1
				if p not in mydict:
					mydict[p] = [i]
				else:
					mydict[p].append(i)
				if count >= n:
					f = 1
					break
		if f == 1:
			break
	colour = [0 for i in range(0, n)]
	col = 1
	for i in mydict.keys():
		arr = mydict[i]
		for index in arr:
			colour[index] = col
		col = col + 1
	print(col - 1)
	for i in range(0, n - 1):
		print(colour[i], end=' ')
	print(colour[n - 1])


import math
t = int(input(''))
while t > 0:
	n = int(input(''))
	m = [0] * n
	count = 0
	l = list(map(int, input().split()))
	l1 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	d = {}
	flag = 0
	k = 0
	for i in range(0, 11):
		d[l1[i]] = i + 1
	for i in range(0, len(l1)):
		for j in range(0, len(l)):
			if l[j] % l1[i] == 0 and l[j] > 0:
				m[j] = k + 1
				l[j] = 0
				flag = 1
		if flag == 1:
			k += 1
			flag = 0
	print(k)
	print(*m, sep=' ')
	t = t - 1


from sys import stdin
import operator
from math import gcd
from collections import defaultdict
from itertools import permutations
lp = [0] * 1005
primes = []
for i in range(2, 1004):
	if lp[i] == 0:
		lp[i] = i
		primes.append(i)
	for p in primes:
		if i * p > 1004 or p > lp[i]:
			break
		lp[i * p] = p
prime_color = {}
color = 1
for i in primes:
	prime_color[i] = color
	color += 1
t = int(input())
for _ in range(t):
	(n,) = map(int, stdin.readline().split())
	comp = list(map(int, stdin.readline().split()))
	seen = defaultdict(lambda : 0)
	color = 0
	for i in range(len(comp)):
		if seen[prime_color[lp[comp[i]]]] == 0:
			color += 1
			seen[prime_color[lp[comp[i]]]] = color
		comp[i] = seen[prime_color[lp[comp[i]]]]
	print(max(comp))
	print(' '.join(map(str, comp)))


from sys import exit
from math import gcd

def i():
	return input()

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

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

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

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	n = ii()
	a = liis()
	ans = [0 for _ in range(n)]
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	color = 0
	for prime in primes:
		first = True
		for (idx, i) in enumerate(a):
			if ans[idx] == 0 and i % prime == 0:
				if first:
					color += 1
				ans[idx] = color
				first = False
	print(color)
	print_array(ans)


ea = 1001
prime_numbers = [True] * ea
for i in range(2, int(ea ** 0.5) + 1):
	if prime_numbers[i] == True:
		for j in range(i * 2, ea, i):
			prime_numbers[j] = False
prime = []
for i in range(2, int(ea ** 0.5) + 1):
	if prime_numbers[i] == True:
		prime.append(i)
composite_numbers = [0] * ea
color = 1
for p in prime:
	for i in range(p * 2, ea, p):
		composite_numbers[i] = color
	color += 1
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	c = list(map(int, input().split()))
	res = []
	for i in c:
		res.append(composite_numbers[i])
	color = 0
	for r in sorted(list(set(res))):
		color += 1
		for i in range(len(res)):
			if res[i] == r:
				res[i] = color
	print(color)
	print(*res)


lcd = [0 for k in range(1001)]
for k in range(1, 1001):
	for p in range(2, k + 1):
		if k % p == 0:
			lcd[k] = p
			break
for t in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	s = set()
	for k in range(n):
		s.add(lcd[ar[k]])
		ar[k] = lcd[ar[k]]
	print(len(s))
	s = list(s)
	s.sort()
	d = {}
	ctr = 1
	for k in s:
		d[k] = ctr
		ctr += 1
	for k in ar:
		print(d[k], end=' ')
	print()


l = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	ans = [-1] * n
	color = 1
	st = set()
	for j in range(12):
		p = 0
		for k in range(n):
			if ans[k] == -1:
				if s[k] % l[j] == 0:
					ans[k] = color
					st.add(j)
					p = 1
		if p:
			color += 1
	print(len(st))
	print(*ans)


cs = [-1 for i in range(1001)]
cnt = 0
for i in range(2, 1001):
	if cs[i] == -1:
		cnt += 1
		for j in range(2 * i, 1001, i):
			if cs[j] == -1:
				cs[j] = cnt
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	used = list(set([cs[v] for v in A]))
	idc = {}
	for i in range(len(used)):
		idc[used[i]] = i + 1
	A = list(map(lambda v: idc[cs[v]], A))
	print(len(used))
	print(' '.join(map(str, A)))


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()
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31]
	pri = []
	for i in a:
		for j in primes:
			if i % j == 0:
				pri.append(j)
				break
	print(len(set(pri)))
	c = 1
	d = defaultdict(int)
	for i in pri:
		if i in d:
			print(d[i], end=' ')
		else:
			d[i] = c
			c += 1
			print(d[i], end=' ')
	print()
for _ in range(int(input())):
	case()


primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)
T = int(input())
while T > 0:
	n = int(input())
	arr = map(int, input().split())
	ans = []
	mp = {}
	cnt = 1
	for num in arr:
		for p in primes:
			if num % p == 0:
				ans.append(p)
				if p not in mp:
					mp[p] = cnt
					cnt += 1
				break
	print(len(mp))
	for i in ans:
		print(mp[i], end=' ')
	print()
	T -= 1


import sys
input = sys.stdin.readline
inputi = lambda : map(int, input().split())
from math import *
from bisect import *
from functools import reduce, lru_cache
from collections import Counter, defaultdict
D = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

@lru_cache(1020)
def C(n):
	for (i, d) in enumerate(D, 1):
		if n % d == 0:
			return i
for _ in range(int(input())):
	n = inputi()
	l = list(inputi())
	i = 0
	t = [0] * 12
	res = []
	for c in l:
		c = C(c)
		if t[c] == 0:
			t[c] = i = i + 1
		res.append(t[c])
	print(i)
	print(*res)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	res = [0] * n
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	w = dict()
	for i in range(n):
		for j in range(11):
			if l[i] % pr[j] == 0:
				if j not in w:
					idx = len(w) + 1
					w[j] = idx
				res[i] = w[j]
				break
	print(len(w))
	print(*res)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499]
t = int(input())
for i in range(t):
	length = int(input())
	arr = [int(x) for x in input().split()]
	colored = [0 for x in range(length)]
	clr = 1
	ans = ''
	ps = colored.copy()
	for indp in range(len(primes)):
		flg = 0
		for indx in range(length):
			if colored[indx]:
				continue
			if arr[indx] % primes[indp] == 0:
				colored[indx] = clr
				ps[indx] = primes[indp]
				flg = 1
		if flg:
			clr += 1
	for ix in colored:
		ans += str(ix) + ' '
	print(len(set(colored)))
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = []
	d = {}
	ans = ''
	t = max(a)
	count = 0
	for i in range(n):
		for j in range(2, t + 1):
			if a[i] % j == 0:
				if j in d:
					ans += str(d[j]) + ' '
				else:
					count += 1
					d[j] = count
					ans += str(count) + ' '
				break
	print(count)
	print(ans)


t = int(input())
for i in range(0, t, 1):
	n = int(input())
	a = list(map(int, input().split()))
	b = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	c = [[], [], [], [], [], [], [], [], [], [], []]
	for j in range(0, len(a)):
		for q in range(0, 11, 1):
			if a[j] % b[q] == 0:
				c[q].append(j)
				break
	na = 1
	k = []
	for j in range(0, n):
		k.append(0)
	for j in range(0, 11, 1):
		if len(c[j]) > 0:
			for q in range(0, len(c[j]), 1):
				k[c[j][q]] = na
			na += 1
	print(na - 1)
	print(*k)


import sys
from functools import lru_cache
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

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

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

def outln(var):
	sys.stdout.write(str(var) + '\n')

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	arr = l()
	new = dd(set)
	for i in range(n):
		j = 2
		while j * j <= arr[i]:
			if arr[i] % j == 0:
				new[j].add(i)
				break
			j += 1
	answer = [0] * n
	color = 1
	for i in new.keys():
		for j in new[i]:
			answer[j] = color
		color += 1
	print(len(set(answer)))
	print(*answer)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mx = max(a)
	div = {i: [] for i in range(2, mx + 1)}
	vis = [0] * n
	for j in range(n):
		el = a[j]
		i = 2
		while i * i <= el:
			if el % i == 0:
				div[i].append(j)
				if el // i != i:
					div[el // i].append(j)
			i += 1
	m = 0
	for i in range(2, mx + 1):
		m += 1
		flag = True
		for el in div[i]:
			if vis[el] == 0:
				vis[el] = 1
				a[el] = m
				flag = False
		if flag:
			m -= 1
	print(m)
	for el in a:
		print(el, 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 = [0] * len(a)
	qw = 0
	qq = 1
	w = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in range(11):
		qw = 0
		for j in range(n):
			if q[j] == 0:
				if a[j] % w[i] == 0:
					q[j] = qq
					qw = 1
		if qw == 1:
			qq = qq + 1
	print(len(set(q)))
	print(*q)


from sys import stdin
input = iter(stdin.readlines()).__next__
spf = [i if i % 2 == 1 else 2 for i in range(0, 1001)]
for i in range(3, 32, 2):
	if spf[i] == i:
		for j in range(i * i, 1001, i):
			if spf[j] == j:
				spf[j] = i
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	spfs = list(map(lambda x: spf[x], a))
	m = list(set(spfs))
	c = list(map(lambda x: m.index(x) + 1, spfs))
	print(len(m))
	print(*c)


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for t in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ac = [0] * n
	pc = [0] * 11
	for i in range(n):
		for j in range(11):
			if a[i] % p[j] == 0:
				ac[i] = p[j]
				pc[j] += 1
				break
	total = 0
	for i in range(11):
		if pc[i] > 0:
			total += 1
			for j in range(n):
				if ac[j] == p[i]:
					ac[j] = total
	print(total)
	print(*ac)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	ans = []
	nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	am = set()
	check = []
	for i in s:
		for j in range(len(nums)):
			if i % nums[j] == 0:
				if j + 1 not in check:
					check.append(j + 1)
					ans.append(len(check))
				else:
					ans.append(check.index(j + 1) + 1)
				am.add(j + 1)
				break
	print(len(am))
	print(*ans)


t = int(input())
numbers = []
for i in range(1000):
	numbers.append(i + 1)
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
div = {}
for i in primes:
	for j in numbers:
		if j % i == 0:
			div[j] = i
			numbers.remove(j)
for i in range(t):
	group = []
	pairs = {}
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(n):
		v = pairs.get(div[a[j]], 0)
		if v == 0:
			pairs[div[a[j]]] = len(pairs) + 1
			v = len(pairs)
		group.append(v)
	output = ' '.join(map(str, group))
	print(len(set(group)))
	print(output)


import sys
primes = '2\t3\t5\t7\t11\t13\t17\t19\t23\t29\t31'.replace('\n', '\t').split('\t')
primes = [int(x) for x in primes]
queries = int(sys.stdin.readline())

def queryFindFences():
	colors = {}
	count = int(sys.stdin.readline())
	heights = sys.stdin.readline().strip().split()
	complexNeighbors = [0] * count
	drawed = [0] * count
	pos = 0
	last_color = 0
	for pos in range(count):
		height = int(heights[pos])
		for prime in primes:
			if height % prime == 0:
				break
		try:
			drawed[pos] = colors[prime]
		except:
			last_color += 1
			colors[prime] = str(last_color)
			drawed[pos] = colors[prime]
	print(last_color)
	print(' '.join(drawed))
for query in range(queries):
	queryFindFences()


import math
prime = list((1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31))
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = 1
	res = list()
	check = dict()
	for x in a:
		for pid in range(1, len(prime)):
			if x % prime[pid] == 0:
				if pid not in check:
					check[pid] = ans
					ans += 1
				res.append(check[pid])
				break
	print(len(set(res)))
	res = map(str, res)
	print(' '.join(res))


pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	for i in range(11):
		for j in range(n):
			if b[j] == 0 and a[j] % pr[i] == 0:
				b[j] = i + 1
	r = max(b)
	for i in range(1, r + 1):
		r = max(b)
		while i not in b and i < r:
			for j in range(n):
				if b[j] > i:
					b[j] -= 1
	print(max(b))
	print(*b)


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

def factorize(num: int) -> dict:
	from math import sqrt
	from collections import Counter
	d = Counter()
	for i in range(2, int(sqrt(num)) + 1):
		while num % i == 0:
			num //= i
			d[i] += 1
		if num == 1:
			break
	if num != 1:
		d[num] += 1
	return d
for _ in range(INT()):
	N = INT()
	A = LIST()
	C = []
	for a in A:
		C.append(factorize(a))
	S = set()
	for c in C:
		S.add(min(c))
	ans = [0] * N
	used = [False] * len(S)
	idx = 0
	for (i, p) in enumerate(S):
		for (j, c) in enumerate(C):
			if ans[j] != 0:
				continue
			if p in c:
				if not used[i]:
					idx += 1
					used[i] = True
				ans[j] = idx
	print(idx)
	print(*ans)


from math import gcd

def color_brute(n, a):
	group = {}
	index = {}
	colCount = 1
	res = []
	for i in range(n):
		res.append(0)
	for i in range(n):
		val = a[i]
		index[val] = i
		flag = True
		if len(group) == 0:
			group[colCount] = [val]
		else:
			for cols in group:
				cols = group[cols]
				if all([gcd(col, val) != 1 for col in cols]):
					cols.append(val)
					flag = False
			if flag:
				colCount += 1
				group[colCount] = [val]
	for cols in group:
		for col in group[cols]:
			res[index[col]] = cols
	return (colCount, res)

def color(n, a):
	group = {}
	count = 0
	colCount = 1
	res = []
	for i in range(n):
		res.append(0)
	for (count, i) in enumerate(a):
		for j in range(2, i):
			if i % j == 0 and isPrime(j):
				if not group:
					group[j] = colCount
					newC = colCount
				elif j in group:
					newC = group[j]
				else:
					colCount += 1
					group[j] = colCount
					newC = colCount
				res[count] = newC
				break
	return (len(group), res)

def isPrime(n):
	for p in range(2, int(n ** 0.5 + 1)):
		if n % p == 0:
			return False
	return True

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = input()
		a = [int(i) for i in a.split()]
		ans = color(n, a)
		print(ans[0])
		for j in ans[1]:
			print(j, end=' ')
		print('')
main()


import math
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	d = {}
	color = 1
	B = sorted(list(set(A)))
	mai = 0
	for i in A:
		d[i] = 0
	for i in range(2, 1001):
		t = 0
		for j in B:
			if d.get(j, -1) == 0:
				if j % i == 0:
					t = 1
					mai = color
					d[j] = color
		if t == 1:
			color += 1
	print(mai)
	for i in A:
		print(d[i], end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	m = 0
	color = 32 * [0]
	for j in range(n):
		for k in range(2, 32):
			if num[j] % k == 0:
				if color[k]:
					break
				else:
					m += 1
					color[k] = m
					break
	print(m)
	for j in range(n):
		for k in range(2, 32):
			if num[j] % k == 0:
				print(color[k], end=' ')
				break
	print()


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	is_coloured = list([0] * n)
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for pp in primes:
		col = max(is_coloured) + 1
		for i in range(n):
			if is_coloured[i] == 0 and a[i] % pp == 0:
				is_coloured[i] = col
	print(max(is_coloured))
	s = ''
	for x in is_coloured:
		s += str(x)
		s += ' '
	print(s)


t = int(input())
for hdsajgbiejka in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	b = []
	for i in a:
		for j in primes:
			if i % j == 0:
				b.append(j)
				break
	a = dict()
	cc = 1
	for i in b:
		try:
			a[i] = a[i]
		except KeyError:
			a[i] = cc
			cc += 1
	print(cc - 1)
	print(*[a[i] for i in b])


def divides(a, b):
	if b % a == 0:
		return True
	return False

def primeDivide(a):
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in primes:
		if divides(i, a):
			return i

def coloring(seq):
	colors = {}
	ret = ''
	m = 0
	for i in seq:
		poop = primeDivide(i)
		if poop in colors:
			ret = ret + str(colors[poop]) + ' '
		else:
			m += 1
			colors[poop] = m
			ret = ret + str(m) + ' '
	return (ret[0:-1], m)
trials = input('')
output = []
for j in range(int(trials)):
	input('')
	(a, b) = coloring([int(i) for i in input('').split(' ')])
	output.append(b)
	output.append(a)
for i in output:
	print(i)


t = int(input())
h = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = []
	m = set()
	g = []
	for i in a:
		for j in range(11):
			if i % h[j] == 0:
				d.append(j + 1)
				m.add(h[j])
				break
	m = list(m)
	print(len(m))
	k = 0
	for i in range(11):
		if h[i] in m:
			g.append(k)
		else:
			k += 1
			g.append(k)
	for i in range(n):
		d[i] -= g[d[i] - 1]
	print(*d)


import math

def prime(n):
	a = []
	while n % 2 == 0:
		return 2
	k = int(math.sqrt(n)) + 1
	for i in range(3, k, 2):
		while n % i == 0:
			return i
	if n > 2:
		return n
t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	c = []
	k = {}
	l = 0
	for i in b:
		d = prime(i)
		if d in k:
			c.append(k[d])
		else:
			l += 1
			k[d] = l
			c.append(k[d])
	print(max(c))
	print(*c)


import sys
input = sys.stdin.readline
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
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:
	ans = []
	Nums = {}
	for a in A:
		for (i, p) in enumerate(primes):
			if a % p == 0:
				if not p in Nums:
					Nums[p] = len(Nums) + 1
				ans.append(Nums[p])
				break
	print(len(Nums))
	print(*ans)


def getpos(li, e):
	s = len(li)
	for i in range(s):
		if li[i] == e:
			return i + 1
a = [1] * 33
a[0] = a[1] = 0
for i in range(2, 6):
	if a[i] == 1:
		for j in range(i * i, 33, i):
			a[j] = 0
prime = []
for i in range(33):
	if a[i] == 1:
		prime.append(i)
t = int(input())
for l in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	an = [0] * n
	for j in range(0, len(prime)):
		for i in range(n):
			if li[i] % prime[j] == 0 and an[i] == 0:
				an[i] = j + 1
	us = len(set(an))
	tl = list(set(an))
	print(us)
	for e in an:
		print(getpos(tl, e), end=' ')
	print()


def primes(n):
	is_prime = [True] * (n + 1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(n ** 0.5) + 1):
		if not is_prime[i]:
			continue
		for j in range(i * 2, n + 1, i):
			is_prime[j] = False
	return [i for i in range(n + 1) if is_prime[i]]

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
div_lis = primes(int(1000 ** 0.5))
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	memo = [[] for i in range(11)]
	for i in range(n):
		divisors = make_divisors(a[i])
		for j in range(11):
			if div_lis[j] == divisors[1]:
				memo[j].append(i)
	color = [0] * n
	cnt = 0
	for i in range(11):
		if len(memo[i]) > 0:
			cnt += 1
		for j in memo[i]:
			color[j] = cnt
	print(max(color))
	print(*color)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	x = [2, 3, 5, 7, 11]
	d = {}
	y = [1, 4, 6, 8, 9, 10]
	z = [13, 17, 19, 23, 29, 31]
	ans = []
	k = 1
	for i in range(n):
		for j in range(5):
			if a[i] % x[j] == 0:
				if x[j] not in d:
					d[x[j]] = k
					k += 1
				ans.append(d[x[j]])
				break
		else:
			for j in range(6):
				if a[i] % z[j] == 0:
					if z[j] not in d:
						d[z[j]] = k
						k += 1
					ans.append(d[z[j]])
					break
	print(max(ans))
	print(*ans)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))
prime = [True] * 32
p = []
for i in range(2, 32):
	if prime[i]:
		p += [i]
		for j in range(i * 2, 32, i):
			prime[j] = False
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	a = mp()
	color = [0] * n
	m = 0
	for i in range(11):
		f = 0
		for j in range(n):
			if color[j]:
				continue
			elif not a[j] % p[i]:
				if not f:
					f = 1
					m += 1
				color[j] = m
	cout(str(m) + '\n')
	for val in color:
		cout(str(val) + ' ')
	cout('\n')


t = int(input())
for j in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	b1 = [0] * 11
	s = 0
	c = [0] * n
	for i in range(n):
		y = 0
		while a[i] % b[y] != 0:
			y += 1
		if b1[y] == 0:
			s += 1
			b1[y] = s
		c[i] = b1[y]
	print(s)
	for i in range(n - 1):
		print(c[i], end=' ')
	print(c[n - 1])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	color = [0] * n
	for i in range(n):
		for j in range(2, 32):
			if l[i] % j == 0:
				color[i] = j
				break
	dic = {}
	count = 1
	for i in range(n):
		if dic.get(color[i]) == None:
			dic[color[i]] = count
			color[i] = count
			count += 1
		else:
			color[i] = dic[color[i]]
	print(len(dic))
	print(*color, sep=' ')


import os
import heapq
import sys, threading
import math as mt
import operator
from copy import copy
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

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

def inpt():
	return [int(k) for k in input().split()]

def main():
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for _ in range(int(input())):
		n = int(input())
		ar = inpt()
		for i in range(n):
			for j in prime:
				if ar[i] % j == 0:
					ar[i] = j
					break
		k = 1
		visited = [0] * n
		for i in prime:
			ok = False
			for j in range(n):
				if ar[j] == i and visited[j] == 0:
					ar[j] = k
					ok = True
					visited[j] = 1
			if ok:
				k += 1
		print(len(set(ar)))
		print(*ar)
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())
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	color_scheme = [0 for i in range(len(a))]
	color = {}
	c = 0
	for y in range(len(a)):
		if a[y] in color.keys():
			color_scheme[y] = color[a[y]]
		else:
			for z in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
				if a[y] % z == 0:
					if z in color.keys():
						color_scheme[y] = color[z]
					else:
						c += 1
						color[z] = c
						color_scheme[y] = c
					break
	print(c)
	print(*color_scheme)


import sys
input = sys.stdin.buffer.readline
first11Primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def getSmallestPrimeFactor(x):
	for p in first11Primes:
		if x % p == 0:
			return p
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = [-1 for __ in range(n)]
	mapp = dict()
	j = 1
	for i in range(n):
		p = getSmallestPrimeFactor(a[i])
		if p not in mapp.keys():
			mapp[p] = j
			j += 1
		ans[i] = mapp[p]
	print(j - 1)
	print(' '.join([str(x) for x in ans]))


from sys import stdin

def solve(n, a):
	k = 0
	c = [0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	h = [0] * n
	d = {}
	for i in range(1, 12):
		for j in range(n):
			if a[j] == -1:
				continue
			if a[j] % c[i] == 0:
				if c[i] not in d:
					d[c[i]] = 1
					k += 1
				h[j] = k
				a[j] = -1
	print(k)
	for i in h:
		print(i, end=' ')
	print()

def main():
	input = stdin.readline
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		solve(n, a)
main()


import os
import sys
from io import BytesIO, IOBase
from math import sqrt
from collections import defaultdict

def solution(arr, n):
	color = defaultdict(list)
	primes = set()
	for x in arr:
		for k in range(2, int(sqrt(x)) + 1):
			if x % k == 0:
				color[x].append(k)
				primes.add(k)
				break
	m = 1
	for p in primes:
		for x in arr:
			if color[x][0] == p:
				color[x].append(m)
		m += 1
	write(len(primes))
	write(*(color[x][-1] for x in arr))

def main():
	for _ in range(r_int()):
		n = r_int()
		arr = r_array()
		solution(arr, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


from math import gcd

def getprime(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
T = int(input())
for _ in range(0, T):
	N = int(input())
	A = list(map(int, input().split()))
	C = [0] * 11
	M = list()
	for i in range(N):
		x = P.index(getprime(A[i]))
		C[x] = 1
		M.append(x)
	c = 0
	X = list()
	for i in range(0, 11):
		X.append(c)
		if C[i]:
			c += 1
	print(c)
	for i in range(0, N):
		x = P.index(getprime(A[i]))
		print(X[x] + 1, end=' ')
	print()


import math
T = int(input())
for _ in range(0, T):
	n = int(input())
	s = [int(x) for x in input().split()]
	pos = [0] * 11
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	c = 1
	ans = [0] * len(s)
	for i in range(0, len(s)):
		tt = s[i]
		p = []
		if tt % 2 == 0:
			p.append(2)
			while tt % 2 == 0:
				tt = tt // 2
		for j in range(3, int(math.sqrt(tt)) + 1, 2):
			if tt % j == 0:
				p.append(j)
				while tt % j == 0:
					tt = tt // j
		if tt > 2:
			p.append(tt)
		for j in range(0, len(pr)):
			if pr[j] == p[0]:
				if pos[j] == 0:
					pos[j] = c
					c += 1
				ans[i] = pos[j]
				break
	print(c - 1)
	print(*ans)


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	color = [0 for i in range(n)]
	for i in range(n):
		for j in range(len(p)):
			if arr[i] % p[j] == 0:
				color[i] = j + 1
	print(len(set(color)))
	e = {}
	cnt = 1
	for i in list(set(color)):
		e[i] = cnt
		cnt += 1
	for i in color:
		print(e[i], end=' ')
	print()


t = int(input())
for _ in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	s = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	z = []
	f = []
	maxi = 1
	for i in l:
		for (k, j) in enumerate(s):
			if i % j == 0:
				if not j in f:
					f.append(j)
				z.append(f.index(j) + 1)
				break
	print(len(f))
	for i in z:
		print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	for j in range(n):
		a[j] = int(a[j])
	s = []
	s.append(2)
	s.append(3)
	s.append(5)
	s.append(7)
	s.append(11)
	s.append(13)
	s.append(17)
	s.append(19)
	s.append(23)
	s.append(29)
	s.append(31)
	c = []
	for j in range(11):
		c.append(0)
	f = []
	for j in range(n):
		for k in range(11):
			if a[j] % s[k] == 0:
				c[k] += 1
				break
	m = 0
	p = []
	for j in range(11):
		if c[j] != 0:
			p.append(s[j])
			m += 1
	for j in range(n):
		for k in range(m):
			if a[j] % p[k] == 0:
				f.append(k + 1)
				break
	print(m)
	for j in range(n):
		print(f[j], end=' ')


from collections import *
from math import *
from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [-1] * n
	co = 1
	for i in range(2, int(sqrt(1000)) + 1):
		ch = 0
		for j in range(n):
			if a[j] % i == 0 and b[j] == -1:
				b[j] = co
				ch = 1
		co += ch
	d = defaultdict(lambda : 0)
	s = []
	for i in range(n):
		if b[i] == -1:
			for j in s:
				if a[i] % j == 0 or j % a[i] == 0:
					b[i] = d[j]
					break
			else:
				b[i] = co
				d[a[i]] = co
				co += 1
	stdout.write(str(co - 1) + '\n')
	for i in range(n):
		stdout.write(str(b[i]) + ' ')
	print()


import math

def getprime(x):
	for i in range(2, math.ceil(math.sqrt(x)) + 1):
		if x % i == 0:
			return i
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	used = [False for i in range(11)]
	color = []
	for i in range(n):
		x = primes.index(getprime(a[i]))
		used[x] = True
		color.append(x)
	count = 0
	num = []
	for i in range(11):
		num.append(count)
		if used[i]:
			count += 1
	print(count)
	for i in range(n):
		x = primes.index(getprime(a[i]))
		print(num[x] + 1, end=' ')
	print()


import math, sys
import heapq
from fractions import Fraction
from collections import Counter, defaultdict

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

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

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

def dic(x):
	return defaultdict(lambda : x)

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

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

def LCM(a, b):
	return a * b / gcd(a, b)

def binarySearch(arr, x):
	(l, r) = (0, len(arr) - 1)
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return True
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return False
t = ii()
for _ in range(t):
	n = int(input())
	a = li()
	dic = {}
	count = 1
	aa = 0
	ans = []
	for x in a:
		p = smallestDivisor(x)
		if p in dic:
			ans.append(dic[p])
		else:
			dic[p] = count
			ans.append(dic[p])
			aa = count
			count += 1
	print(aa)
	print(*ans)


t = int(input())
for case in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	used = [0] * 11
	counter = 0
	for i in range(len(A)):
		for (x, p) in enumerate([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]):
			if A[i] % p == 0:
				if used[x] == 0:
					counter += 1
					used[x] = counter
				A[i] = used[x]
				break
	print(counter)
	print(' '.join([str(y) for y in A]))


def primes(c):
	primes = []
	p = 2
	while c >= p * p:
		if c % p == 0:
			primes.append(p)
			c = c // p
		elif p == 2:
			p += 1
		else:
			p += 2
	if c != 1:
		primes.append(c)
	return primes

def pick(map, c):
	if not c in map:
		map[c] = len(map) + 1
	return map[c]
T = int(input())
for _ in range(T):
	N = int(input())
	numbers = list(map(int, input().split()))
	solution = []
	colors = {}
	for num in numbers:
		pms = primes(num)
		if 2 in pms:
			solution.append(pick(colors, 1))
		elif 3 in pms:
			solution.append(pick(colors, 2))
		elif 5 in pms:
			solution.append(pick(colors, 3))
		elif 7 in pms:
			solution.append(pick(colors, 4))
		elif 11 in pms:
			solution.append(pick(colors, 5))
		elif 13 in pms:
			solution.append(pick(colors, 6))
		elif 17 in pms:
			solution.append(pick(colors, 7))
		elif 19 in pms:
			solution.append(pick(colors, 8))
		elif 23 in pms:
			solution.append(pick(colors, 9))
		elif 29 in pms:
			solution.append(pick(colors, 10))
		elif 31 in pms:
			solution.append(pick(colors, 11))
	print(len(colors))
	print(' '.join(map(str, solution)))


from math import sqrt
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	f = [None for _ in range(n)]
	color = [None for _ in range(n)]
	for i in range(n):
		for j in range(2, a[i]):
			if a[i] % j == 0:
				f[i] = j
				break
	m = 1
	for i in range(n):
		if color[i] == None:
			color[i] = m
			m = m + 1
		for j in range(i + 1, n):
			if f[i] == f[j]:
				color[j] = color[i]
	print(max(color))
	print(*color)


from sys import stdin, stdout
t = int(stdin.readline().strip())
P = {a: 0 for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]}
for _ in range(t):
	n = int(stdin.readline().strip())
	alist = list(map(int, stdin.readline().split()))
	for p in P:
		P[p] = 0
	used = 0
	ans = []
	for a in alist:
		for p in P:
			if a % p == 0 or p == 31:
				if P[p] == 0:
					used += 1
					P[p] = used
				ans.append(p)
				break
	ans = ' '.join([str(P[a]) for a in ans])
	stdout.write('{}\n{}\n'.format(used, ans))


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())
	comps = list(map(int, input().split()))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	dict1 = {}
	for s in range(len(comps)):
		for k in primes:
			if comps[s] % k == 0:
				if k in dict1:
					dict1[k].append(s)
				else:
					dict1[k] = [s]
				break
	counter = 1
	for b in dict1:
		for l in dict1[b]:
			comps[l] = str(counter)
		counter += 1
	print(counter - 1)
	print(' '.join(comps))


def f(A):
	n = len(A)
	C = [0] * n
	B = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	a = 1
	for j in range(11):
		r = 0
		for i in range(n):
			if A[i] % B[j] == 0 and C[i] == 0:
				C[i] = a
				r = 1
		if r > 0:
			a += 1
	print(a - 1)
	return C
t = int(input())
while t > 0:
	n = int(input())
	A = list(map(int, input().split()))
	T = f(A)
	for i in T:
		print(i, end=' ')
	t -= 1


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	narr = [0 for _ in range(n)]
	for (i, x) in enumerate(arr):
		for (j, p) in enumerate(primes):
			if not x % p:
				narr[i] = j + 1
				break
	snr = set(narr)
	dct = {}
	i = 1
	for s in snr:
		dct[s] = i
		i += 1
	print(len(snr))
	print(*map(lambda x: dct[x], narr))


t = int(input())
while t != 0:
	n = int(input())
	A = list(map(int, input().split()))
	d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	res = [0] * n
	i = 0
	while i < 11:
		j = 0
		while j < n:
			if A[j] % d[i] == 0:
				res[j] = i + 1
			j += 1
		i += 1
	x = len(set(res))
	B = [1]
	l = 1
	k = 1
	while k < n:
		if res[k] not in res[:k]:
			l += 1
			B.append(l)
		else:
			B.append(B[res.index(res[k])])
		k += 1
	print(x)
	print(*B)
	t -= 1


from math import gcd
from sys import stdin, stdout
from collections import defaultdict as dd
input = stdin.readline
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	d = dd(list)
	l = list(map(int, input().split()))
	for i in range(n):
		for j in range(11):
			if l[i] % prime[j] == 0:
				d[l[i]] = prime[j]
				break
	lm = list(set(d.values()))
	di = {}
	m = 1
	for i in lm:
		di[i] = m
		m += 1
	for i in d:
		d[i] = di[d[i]]
	print(m - 1)
	for i in range(n):
		print(d[l[i]], end=' ')
	print()


def sieve(n):
	a = [1] * (n + 1)
	a[0] = a[1] = 0
	i = 2
	while i * i <= n:
		if a[i]:
			j = i * i
			while j <= n:
				a[j] = 0
				j += i
		i += 1
	return a
for _ in range(int(input())):
	p = sieve(40)
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for x in a:
		for i in range(2, 41):
			if x % i == 0:
				b.append(i)
				p[i] += 1
				break
	m = 1
	for i in range(41):
		if p[i] > 1:
			p[i] = m
			m += 1
	b = [p[x] for x in b]
	print(m - 1)
	print(*b)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	k = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	r = []
	for i in range(n):
		for j in range(11):
			if l[i] % k[j] == 0:
				r.append(j + 1)
				break
	p = set(r)
	print(len(p))
	d = {x: y for (y, x) in enumerate(p, 1)}
	for i in r:
		print(d[i], end=' ')
	print()


from math import gcd
prm = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def process():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0] * n
	color = 1
	for p in prm:
		flag = False
		for i in range(n):
			if ans[i] != 0:
				continue
			if arr[i] % p:
				continue
			flag = True
			ans[i] = color
		if flag:
			color += 1
	print(color - 1)
	print(*ans)
for _ in range(int(input())):
	process()


d = {}
primel = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(4, 1001):
	for j in primel:
		if i % j == 0:
			d[i] = j
			break
for t in range(int(input())):
	n = int(input())
	l = [d[i] for i in map(int, input().split())]
	s = list(set(l))
	print(len(s))
	print(*[s.index(i) + 1 for i in l])


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ans = [-1] * n
	mark = 1
	for i in range(len(prime)):
		flg = 0
		for j in range(n):
			if ans[j] == -1:
				if arr[j] % prime[i] == 0:
					ans[j] = mark
					flg = 1
		if flg == 1:
			mark += 1
	print(max(ans))
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	(result, colors, deviders, c_dict) = ([0] * n, 1, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31], {})
	for (i_elem, elem) in enumerate(array):
		for (i_devider, devider) in enumerate(deviders):
			if elem % devider == 0:
				if devider not in c_dict:
					c_dict[devider] = colors
					result[i_elem] += colors
					colors += 1
				else:
					result[i_elem] += c_dict[devider]
				break
	print(colors - 1)
	print(' '.join(list(map(str, result))))


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	l = [[] for _ in range(11)]
	arr = list(map(int, stdin.readline().split()))
	ans = [0] * n
	for x in range(n):
		for d in range(11):
			if arr[x] % pr[d] == 0:
				l[d].append(x)
				break
	j = 1
	for x in range(11):
		for d in l[x]:
			ans[d] = j
		if len(l[x]):
			j += 1
	print(max(ans))
	for r in ans:
		print(r, end=' ')
	print('')


t = int(input())
for iii in range(t):
	n = int(input())
	m = list(map(int, input().split()))
	ans = [0] * n
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	cv = []
	for i in range(11):
		cv.append([])
	for i in range(n):
		for j in range(11):
			if m[i] % pr[j] == 0:
				cv[j].append(i)
				break
	v = []
	for i in cv:
		if len(i) > 0:
			v.append(i)
	for i in range(len(v)):
		for j in v[i]:
			ans[j] = i + 1
	ansk = max(ans)
	print(ansk)
	print(*ans)


t = int(input())
for i in range(t):
	(n, s, p, q, d, k) = (int(input()), input().split(), [0] * 11, [], dict(), 0)
	for i in range(n):
		if int(s[i]) % 2 == 0:
			q.append(1)
			p[0] = 1
		elif int(s[i]) % 3 == 0:
			p[1] = 1
			q.append(2)
		elif int(s[i]) % 5 == 0:
			p[2] = 1
			q.append(3)
		elif int(s[i]) % 7 == 0:
			p[3] = 1
			q.append(4)
		elif int(s[i]) % 11 == 0:
			p[4] = 1
			q.append(5)
		elif int(s[i]) % 13 == 0:
			p[5] = 1
			q.append(6)
		elif int(s[i]) % 17 == 0:
			p[6] = 1
			q.append(7)
		elif int(s[i]) % 19 == 0:
			p[7] = 1
			q.append(8)
		elif int(s[i]) % 23 == 0:
			p[8] = 1
			q.append(9)
		elif int(s[i]) % 29 == 0:
			p[9] = 1
			q.append(10)
		elif int(s[i]) % 31 == 0:
			p[10] = 1
			q.append(11)
	for i in range(11):
		if p[i] == 1:
			d[i + 1] = k + 1
			k = k + 1
	for i in range(n):
		q[i] = d[q[i]]
	print(k)
	print(' '.join((str(i) for i in q)))


import sys

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

def N():
	return int(input())
from math import gcd
from collections import defaultdict
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(N()):
	n = N()
	arr = list(RL())
	res = [0] * n
	for i in range(n):
		for j in range(11):
			if arr[i] % p[j] == 0:
				res[i] = j
	dic = {}
	now = 1
	for i in range(n):
		if res[i] not in dic:
			dic[res[i]] = now
			now += 1
		res[i] = dic[res[i]]
	print(now - 1)
	print(*res)


t = int(input())
for __ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	groups = [[] for i in range(11)]
	ans = [0] * n
	calc = 1
	fwasnt = 1
	gigs = {2: 1, 3: 2, 5: 3, 7: 4, 11: 5, 13: 6, 17: 7, 19: 8, 23: 9, 29: 10, 31: 11}
	for i in range(len(A)):
		for key in gigs:
			if not A[i] % key:
				ans[i] = gigs[key]
				break
	was = 0
	true = 1
	for i in range(1, 12):
		for j in range(n):
			if ans[j] == i:
				was = 1
				ans[j] = true
		true += was
		was = 0
	print(max(ans))
	print(*ans)


import math
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())

def s(a):
	print(' '.join(list(map(str, a))))
t = I()
x = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(t):
	n = I()
	a = L()
	l = []
	for i in a:
		for j in range(11):
			if i % x[j] == 0:
				l.append(j + 1)
				break
	t = sorted(set(l))
	d = {}
	c = 1
	for i in t:
		d[i] = c
		c += 1
	l = [d[i] for i in l]
	print(len(t))
	s(l)


kount = int(input())
for _ in range(kount):
	ans = []
	smth = {}
	garbage = int(input())
	arr = list(map(int, input().split()))
	now_counter = 0

	def find_min_del(x: int):
		i = 1
		while i <= x:
			i += 1
			if x % i == 0:
				return i
	for i in range(0, len(arr)):
		min_del_now = find_min_del(arr[i])
		if min_del_now not in smth:
			now_counter += 1
			smth[min_del_now] = now_counter
		ans.append(smth[min_del_now])
	print(len(smth))
	for i in range(len(ans)):
		print(ans[i], end=' ')
	print('\n')


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	ans = []
	for c in a:
		for i in range(11):
			if c % primes[i] == 0:
				ans.append(i + 1)
				break
	m = len(set(ans))
	print(m)
	for i in range(1, m + 1):
		if i not in ans:
			z = max(ans)
			ans = [j + int(j == z) * (i - j) for j in ans]
	print(*ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = [0 for _ in range(n)]
	r = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	m = 1
	for s in r:
		a = False
		for i in range(n):
			if l[i] % s == 0 and d[i] == 0:
				d[i] = m
				a = True
		if a:
			m = m + 1
	print(max(d))
	print(*d)


ans = []
for _ in range(int(input())):
	n = int(input())
	u = list(map(int, input().split()))
	a = [0] * n
	pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	dct = dict()
	ind = 1
	for i in range(n):
		for j in range(11):
			if u[i] % pr[j] == 0:
				if j in dct.keys():
					a[i] = dct[j]
				else:
					a[i] = ind
					dct[j] = ind
					ind += 1
					break
	ans.append(str(max(a)))
	ans.append(' '.join(map(str, a)))
print('\n'.join(ans))


from math import gcd
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	count = 1
	color = [0] * n
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	used = [0] * 11
	count = [0] * 11
	cnt = 1
	for i in range(len(a)):
		for j in range(len(primes)):
			if a[i] % primes[j] == 0:
				if used[j] == 0:
					used[j] = 1
					count[j] = cnt
					cnt += 1
				color[i] = count[j]
				break
	print(used.count(1))
	print(*color)


def some(n, delims, answer, count, table):
	for delimIdx in range(len(delims)):
		if n % int(delims[delimIdx]) == 0:
			if delims[delimIdx] not in table:
				table[delims[delimIdx]] = str(count)
				count += 1
			answer.append(table[delims[delimIdx]])
			return count
	return count
t = int(input())
for i in range(1, t + 1):
	W = int(input())
	N = [int(x) for x in input().split()]
	answer = []
	count = 1
	table = {}
	delims = ['2', '3', '5', '7', '11', '13', '17', '19', '23', '29', '31']
	for n in N:
		count = some(n, delims, answer, count, table)
	print(len(set(answer)))
	print(' '.join(answer))


t = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for case_num in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	used = set()
	color = []
	for i in a:
		for prime in primes:
			if i % prime == 0:
				color.append(prime)
				used.add(prime)
				break
	lookup = dict()
	idx = 1
	for c in used:
		lookup[c] = idx
		idx += 1
	print(len(used))
	print(' '.join(map(str, [lookup[i] for i in color])))


def SieveOfEratosthenes(n):
	arr = []
	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
	for p in range(n + 1):
		if prime[p]:
			arr.append(p)
	return arr
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	prime = SieveOfEratosthenes(max(arr))
	color = 1
	visited = [0] * n
	counter = 0
	for p in prime:
		if counter == n:
			break
		flag = False
		for i in range(n):
			if arr[i] % p == 0 and visited[i] == 0:
				visited[i] = color
				flag = True
				counter += 1
		if flag:
			color += 1
	print(color - 1)
	for i in visited:
		print(i, end=' ')
	print()


prime = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)
t = int(input())
for _ in range(t):
	n = int(input())
	a = tuple(map(int, input().split()))
	out = [1] * n
	c = [0] * 11
	d = 0
	for i in range(n):
		for j in range(11):
			if a[i] % prime[j] == 0:
				if c[j] == 0:
					d += 1
					c[j] = d
				out[i] = c[j]
				break
	print(d)
	print(*out)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(item) for item in input().split()]
	d = dict()
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	group = [[] for _ in range(11)]
	for (i, item) in enumerate(a):
		ok = False
		for (j, p) in enumerate(primes):
			if item % p == 0:
				group[j].append(i)
				ok = True
				break
		if ok:
			continue
	ans = [0] * len(a)
	color = 1
	for g in group:
		if not g:
			continue
		for item in g:
			ans[item] = color
		color += 1
	print(color - 1)
	print(*ans)


from math import gcd
from collections import defaultdict

def return_smallest_divisor(n):
	for i in range(2, n + 1):
		if n % i == 0:
			return i
cases = int(input())
for _ in range(cases):
	n = int(input())
	c = list(map(int, input().split()))
	q = []
	for i in range(len(c)):
		q.append(return_smallest_divisor(c[i]))
	m = min(q) - 1
	w = []
	index = 1
	for i in range(len(q)):
		w.append(q[i] - m)
	r = sorted(list(set(w)))
	d = defaultdict(list)
	index = 1
	for i in range(len(r)):
		d[r[i]] = index
		index += 1
	ww = []
	for i in range(len(w)):
		ww.append(d[w[i]])
	print(max(ww))
	print(*ww)


import collections
from math import gcd
from math import sqrt

class Solution:

	def solve(self, n, arr):
		colors = [0 for _ in range(n)]
		sqrtN = int(sqrt(1000)) + 1
		primes = [True for _ in range(sqrtN)]
		i = 2
		while i < sqrtN:
			if primes[i]:
				for j in range(i * i, sqrtN, i):
					primes[j] = False
			i += 1
		color = 1
		for i in range(2, sqrtN):
			isAssigned = False
			for j in range(n):
				if colors[j] != 0:
					continue
				if arr[j] % i != 0:
					continue
				colors[j] = color
				isAssigned = True
			if isAssigned:
				color += 1
		return '\n'.join(map(str, [color - 1, ' '.join(map(str, colors))]))
sol = Solution()
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	print(sol.solve(n, arr))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	l = list(map(int, sys.stdin.readline().split()))
	k = 1
	ans = [0] * n
	for i in range(2, 1001):
		flag = False
		for j in range(n):
			if l[j] % i == 0 and ans[j] == 0:
				ans[j] = k
				flag = True
		if flag:
			k += 1
	print(k - 1)
	print(*ans)


id = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31)
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	f = [0] * 32
	(res, t) = ([], 1)
	for x in a:
		for i in id:
			if x % i == 0:
				if f[i] == 0:
					f[i] = t
					res.append(f[i])
					t += 1
				else:
					res.append(f[i])
				break
	print(t - 1)
	print(*res)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
n = int(input())
for i in range(n):
	r = int(input())
	s = [int(x) for x in input().split()]
	ans = []
	yes = [0 for i in range(11)]
	for m in range(len(s)):
		for j in range(11):
			if s[m] % primes[j] == 0:
				ans.append(j)
				yes[j] = 1
				break
	yesthen = [0 for k in range(11)]
	yesthen[0] = yes[0]
	for k in range(10):
		yesthen[k + 1] = yes[k + 1] + yesthen[k]
	print(yesthen[10])
	for m in range(len(s)):
		print(yesthen[ans[m]], end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = [0] * n
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ss = set()
	m = 0
	for k in range(len(p)):
		flag = True
		for i in range(n):
			if ans[i] == 0:
				if a[i] % p[k] == 0:
					if flag:
						m += 1
						flag = False
					ans[i] = m
	print(m)
	print(*ans)


from sys import stdin, stdout
from collections import defaultdict, Counter
from functools import lru_cache
from math import gcd, floor, ceil
import math

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

def iint():
	return int(stdin.readline().strip())

def istr():
	return stdin.readline().strip()
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def factor(x):
	for i in range(2, x):
		if x % i == 0:
			return primes.index(i)
	return -1
t = iint()
for _x in range(t):
	(n, m) = (iint(), 1)
	arr = ilist()
	res = []
	hmap = defaultdict(int)
	used = [0] * 11
	for x in arr:
		used[factor(x)] = 1
	for i in range(11):
		if used[i]:
			hmap[i] = m
			m += 1
	print(m - 1)
	for x in arr:
		print(hmap[factor(x)], end=' ')
	print()


def solve(L):
	sol = [0] * len(L)
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in range(len(L)):
		for j in range(11):
			if L[i] % p[j] == 0:
				sol[i] = j + 1
				break
	return sol
for i in ' ' * int(input()):
	n = int(input())
	L = list(map(int, input().split()))
	sol = solve(L)
	count = [0] * 11
	for i in sol:
		count[i - 1] += 1
	newc = []
	for i in range(11):
		if count[i]:
			newc.append(i + 1)
	d = dict()
	for i in range(len(newc)):
		d[newc[i]] = i + 1
	for i in range(n):
		sol[i] = d[sol[i]]
	print(max(sol))
	for i in sol:
		print(i, end=' ')
	print()


MOD = 998244353
T = 1
T = int(input())
for t in range(1, T + 1):
	n = int(input())
	a = list(map(int, input().split()))
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	colour = {i: [] for i in range(1, 12)}
	for i in range(n):
		for j in range(11):
			if a[i] % p[j] == 0:
				colour[j + 1].append(i)
				break
	c = [0 for i in range(n)]
	x = 1
	for i in range(1, 12):
		if colour[i] == []:
			continue
		for j in colour[i]:
			c[j] = x
		x += 1
	print(x - 1)
	print(*c)


t = int(input())
for _ in range(t):
	n = int(input())
	As = list(map(int, input().split()))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	colors = []
	pcolors = {}
	nextval = 1
	for a in As:
		for (i, p) in enumerate(primes):
			if a % p == 0:
				if not p in pcolors:
					pcolors[p] = nextval
					nextval += 1
				colors.append(pcolors[p])
				break
	m = len(set(colors))
	print(m)
	print(' '.join(map(str, colors)))


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

def primeFactors(n):
	assert n >= 1
	factors = Counter()
	while n % 2 == 0:
		factors[2] += 1
		n //= 2
	x = 3
	while x * x <= n:
		while n % x == 0:
			factors[x] += 1
			n //= x
		x += 2
	if n != 1:
		factors[n] += 1
	return factors

def solve(N, A):
	indexToPrime = {}
	for (i, x) in enumerate(A):
		for p in primeFactors(x).keys():
			indexToPrime[i] = p
			break
	primeToId = {}
	ans = []
	for (i, p) in indexToPrime.items():
		if p not in primeToId:
			primeToId[p] = len(primeToId) + 1
		ans.append(str(primeToId[p]))
	return str(len(primeToId)) + '\n' + ' '.join(ans)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


t = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	(ans, used, num) = ([0] * 1002, [0] * 12, [0] * 12)
	v = []
	for i in x:
		for i2 in range(11):
			if i % p[i2] == 0:
				ans[i] = i2 + 1
				used[i2 + 1] = 1
				break
	count = 1
	for i in range(1, 12):
		if used[i] == 1:
			num[i] = count
			count += 1
	print(count - 1)
	for i in x:
		print(num[ans[i]], end=' ')
	print('')


for ttt in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	res = [0] * n
	count = 1
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	for i in range(len(prime)):
		ok = 0
		for j in range(n):
			if arr[j] % prime[i] == 0:
				if res[j] == 0:
					res[j] = count
					ok = 1
		if ok:
			count += 1
	print(count - 1)
	print(*res)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

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

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

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

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	for _ in range(ii()):
		n = ii()
		arr = li()
		m = 1
		col = [0] * n
		for i in range(2, int(1000 ** 0.5) + 1):
			if isPrime(i):
				flag = 0
				for j in range(n):
					if col[j] == 0 and arr[j] % i == 0:
						col[j] = m
						flag = 1
				if flag:
					m += 1
		print(max(col))
		print(*col)
main()


import collections
import itertools
from functools import lru_cache
import sys
import math

def getPrimes():
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
	return primes

def factors(num):
	n = num
	primes = getPrimes()
	factors = []
	for prime in primes:
		if prime > num:
			break
		if n % prime == 0:
			factors.append(prime)
		while n % prime == 0:
			n = n / prime
	if n == num:
		factors.append(num)
	return factors

def solve():
	n = int(input())
	arr = list(map(int, input().split(' ')))
	facts = {}
	for num in arr:
		facts[num] = factors(num)
	ans = {}
	for i in range(n):
		prime = facts[arr[i]][0]
		if prime in ans.keys():
			ans[prime].append(i)
		else:
			ans[prime] = [i]
	res = [0 for i in range(n)]
	print(len(ans.keys()))
	i = 1
	for key in ans:
		for index in ans[key]:
			res[index] = i
		i += 1
	for e in res:
		print(e, end=' ')
	print()
t = int(input())
for _ in range(t):
	solve()
	pass


t = int(input())
for i in range(t):
	n = int(input())
	mass = [int(x) for x in input().split()]
	answer = [0] * n
	ch = 1
	count = n
	for j in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
		f = False
		for o in range(n):
			if mass[o] % j == 0 and (not answer[o]):
				answer[o] = ch
				f = True
				count -= 1
		if f:
			ch += 1
		if count == 0:
			break
	print(ch - 1)
	print(*answer)


import math, collections, sys
input = sys.stdin.readline
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 27, 29, 31]

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	spf = []
	for i in a:
		for j in primes:
			if i % j == 0:
				spf.append(j)
				break
	s = set(spf)
	color = 1
	d = collections.defaultdict(int)
	for i in s:
		d[i] = color
		color += 1
	print(color - 1)
	for i in range(n):
		spf[i] = d[spf[i]]
	print(*spf)
for _ in range(int(input())):
	solve()


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(k) for k in input().split()]
	divBy = [0] * 1001
	divBy[1] = 1
	for i in range(2, 1001):
		if divBy[i] == 0:
			for j in range(i, 1001, i):
				if divBy[j] == 0:
					divBy[j] = i
	if n <= 11:
		print(n)
		print(*[i for i in range(1, n + 1)])
	else:
		divisor = {}
		for (i, num) in enumerate(a):
			if divBy[num] in divisor:
				divisor[divBy[num]].append(i)
			else:
				divisor[divBy[num]] = [i]
		ans = [0] * 1001
		temp = 1
		for templist in divisor.values():
			for numIndex in templist:
				ans[numIndex] = temp
			temp += 1
		print(temp - 1)
		print(*ans[:n])


for h in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	div = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	colours = [0] * n
	for i in range(n):
		for j in div:
			if a[i] % j == 0:
				colours[i] = j
				break
	cnt = [0] * 11
	for i in colours:
		cnt[div.index(i)] = 1
	cur = 0
	for j in range(11):
		if cnt[j] == 1:
			cur += 1
		for i in range(n):
			if colours[i] == div[j]:
				colours[i] = cur
	print(max(colours))
	print(*colours)


from sys import stdin, stdout
import math

def least(n):
	k = 2
	while k <= math.sqrt(n):
		if n % k == 0:
			return k
		k += 1
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	arr = [int(x) for x in stdin.readline().split()]
	ans = [0] * n
	h = {}
	m = 1
	h[m] = least(arr[0])
	ans[0] = m
	for i in range(1, n):
		l = least(arr[i])
		j = 0
		found = False
		while j < m:
			if h[j + 1] == l:
				ans[i] = j + 1
				found = True
				break
			j += 1
		if not found:
			m += 1
			h[m] = l
			ans[i] = m
	print(m)
	print(' '.join(map(str, ans)))


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	an = 0
	ans = []
	tw = 0
	tr = 0
	sem = 0
	p = 0
	od = 0
	trin = 0
	dev = 0
	dvtr = 0
	dvd = 0
	tro = 0
	trse = 0
	semnad = 0
	for i in a:
		if i % 2 == 0:
			if tw == 0:
				tw = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(tw)
		elif i % 3 == 0:
			if tr == 0:
				tr = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(tr)
		elif i % 5 == 0:
			if p == 0:
				p = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(p)
		elif i % 7 == 0:
			if sem == 0:
				sem = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(sem)
		elif i % 11 == 0:
			if od == 0:
				od = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(od)
		elif i % 13 == 0:
			if trin == 0:
				trin = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(trin)
		elif i % 19 == 0:
			if dev == 0:
				dev = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(dev)
		elif i % 23 == 0:
			if dvtr == 0:
				dvtr = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(dvtr)
		elif i % 29 == 0:
			if dvd == 0:
				dvd = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(dvd)
		elif i % 31 == 0:
			if tro == 0:
				tro = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(tro)
		elif i % 17 == 0:
			if semnad == 0:
				semnad = max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse) + 1
			ans.append(semnad)
	print(max(semnad, sem, p, tr, tw, od, trin, dev, dvtr, dvd, tro, trse))
	print(*ans)


def get_primes(k):
	p = [True] * (k + 1)
	p[0] = False
	p[1] = False
	for i in range(1, k + 1):
		if p[i]:
			for j in range(2, k // i + 1):
				p[i * j] = False
	pr = []
	for i in range(k + 1):
		if p[i]:
			pr.append(i)
	return pr
p = get_primes(1001)
t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [None] * n
	k = 1
	flag = False
	for x in p:
		for z in range(n):
			if b[z] is None and a[z] % x == 0:
				b[z] = k
				flag = True
		if flag:
			k += 1
		flag = False
	print(k - 1)
	for x in b:
		print(x, end=' ')
	print()


L2 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
L3 = [101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
L4 = [211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293]
L5 = [307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397]
L6 = [401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499]
L7 = [503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691]
L8 = [701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887]
L9 = [907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
L2 = L2 + L3 + L4 + L5 + L6 + L7 + L7 + L9
t = int(input())
for i in range(t):
	n = int(input())
	ch = input()
	k = 1
	L = [int(i) for i in ch.split()]
	d = dict()
	for i in range(len(L2)):
		d[L2[i]] = -1
	L3 = [0] * n
	for w in range(n):
		for j in range(25):
			if L[w] % L2[j] == 0:
				if d[L2[j]] == -1:
					d[L2[j]] = k
					k += 1
				L3[w] = d[L2[j]]
				break
	s = ''
	for w in range(n):
		s += str(L3[w]) + ' '
	print(max(L3))
	print(s)


def SieveOfErathosthenes(n=1000):
	prime = [1] * (n + 1)
	res = [[] for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p]:
			for i in range(2 * p, n + 1, p):
				prime[i] = 0
				res[i].append(p)
		p += 1
	return res

def solve(a):
	c = [0] * len(a)
	m = set()
	for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]:
		for j in range(len(a)):
			if a[j] % p == 0 and c[j] == 0:
				if p not in m:
					m.add(p)
				c[j] = len(list(m))
	print(len(list(m)))
	print(' '.join([str(e) for e in c]))
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	solve(a)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	colors = ''
	used = [0] * 11
	count = 0
	for ai in a:
		for i in range(11):
			if ai % primes[i] is 0:
				if used[i] is 0:
					count += 1
					used[i] = count
				colors += str(used[i]) + ' '
				break
	print('{0}\n{1}'.format(count, colors))


t = int(input())
primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	colors = [0 for x in range(n)]
	for p in primes:
		for (ind, item) in enumerate(arr):
			if not colors[ind] and item % p == 0:
				colors[ind] = p
	clrs = list(set(colors))
	print(len(clrs))
	for item in colors:
		print(clrs.index(item) + 1, end=' ')
	print()


import sys
import math

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

def idata():
	return [int(x) for x in ii().split()]

def binary_search(array, x):
	(left, right) = (-1, len(array))
	while left + 1 != right:
		middle = (left + right) // 2
		if array[middle] >= x:
			right = middle
		elif array[middle] < x:
			left = middle
	return right

def c_mod(n1, k1, mod1):
	num = den = 1
	for i in range(n1 - k1):
		num = num * (n1 - i) % mod1
		den = den * (i + 1) % mod1
	return num * pow(den, mod1 - 2, mod1) % mod1

def c_k(n1, k1):
	num = den = 1
	for i in range(n1 - k1):
		num = num * (n1 - i)
		den = den * (i + 1)
	return num // den

def v_sistemu(x, k):
	x = int(x)
	z = ''
	while x:
		z += str(x % k)
		x //= k
	return z[::-1]

def iz_sistemi(x, k):
	x = str(x)[::-1]
	ans = 0
	for i in range(len(x)):
		ans += int(x[i]) * pow(k, i)
	return ans

def solve_of_problem():
	de = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	n = int(ii())
	data = idata()
	colours = [-1] * 11
	numbers = [0] * n
	num = 0
	for i in range(n):
		for j in range(11):
			if data[i] % de[j] == 0:
				if colours[j] == -1:
					num += 1
					colours[j] = num
				numbers[i] = colours[j]
				break
	print(num)
	print(*numbers)
	return
for ____ in range(int(ii())):
	solve_of_problem()


import sys
input = lambda : sys.stdin.readline().rstrip()

def I():
	return [int(iI) for iI in input().split()]

def II():
	return int(input())

def SI():
	return [i for i in input()]
for _ in range(II()):
	n = II()
	a = I()
	k = 1
	ans = [0] * len(a)
	for i in range(2, 32):
		flag = 0
		for j in range(len(a)):
			if a[j] % i == 0:
				ans[j] = k
				flag = 1
				a[j] = 1
		if flag == 1:
			k += 1
	print(len(set(ans)))
	print(*ans)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in [0] * int(input()):
	n = int(input())
	(*A,) = map(int, input().split())
	factor = [0] * n
	k = 0
	used = [False] * 32
	factor_to_c = {}
	for (i, a) in enumerate(A):
		for p in primes:
			if a % p == 0:
				if not used[p]:
					used[p] = True
					k += 1
					factor_to_c[p] = k
				factor[i] = p
				break
	print(k)
	print(*[factor_to_c[p] for p in factor])


d = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	answer = []
	for i in range(n):
		for j in range(11):
			if a[i] % d[j] == 0:
				answer.append(j + 1)
				break
	st = list(set(answer))
	st.sort()
	print(len(st))
	for i in range(n):
		print(st.index(answer[i]) + 1, end=' ')
	print()


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(input())

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

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

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

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

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def eratosthenes(n):
	p = []
	t = [True] * n
	for i in range(2, int(math.ceil(math.sqrt(n)))):
		if t[i]:
			p.append(i)
			for j in range(2 * i, n, i):
				t[j] = False
	for j in range(i + 1, n):
		if t[j]:
			p.append(j)
	return p

class UnionFind:

	def __init__(self):
		self.__table = {}
		self.__size = defaultdict(lambda : 1)
		self.__rank = defaultdict(lambda : 1)

	def root(self, x):
		return self.__root(x)

	def __root(self, x):
		if x not in self.__table:
			self.__table[x] = x
		elif x != self.__table[x]:
			self.__table[x] = self.__root(self.__table[x])
		return self.__table[x]

	def same(self, x, y):
		return self.__root(x) == self.__root(y)

	def union(self, x, y):
		x = self.__root(x)
		y = self.__root(y)
		if x == y:
			return
		if self.__rank[x] < self.__rank[y]:
			self.__table[x] = y
			self.__size[y] += self.__size[x]
		else:
			self.__table[y] = x
			self.__size[x] += self.__size[y]
			if self.__rank[x] == self.__rank[y]:
				self.__rank[x] += 1

	def size(self, x):
		return self.__size[self.__root(x)]

	def num_of_group(self):
		g = 0
		for (k, v) in self.__table.items():
			if k == v:
				g += 1
		return g
P = eratosthenes(32)

def slv(N, A):
	ans = []
	for a in A:
		for (i, p) in enumerate(P):
			if a % p == 0:
				ans.append(i + 1)
				break
	b = list(set(ans))
	b.sort()
	c = {a: i + 1 for (i, a) in enumerate(b)}
	ans = [c[a] for a in ans]
	print(len(set(ans)))
	print(*ans)

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		A = read_int_n()
		slv(N, A)
main()


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	checked = [0] * n
	col = 1
	cnt = 0
	for p in primes:
		if cnt > 0:
			col += 1
		cnt = 0
		for j in range(n):
			if not checked[j]:
				if l[j] % p == 0:
					cnt += 1
					checked[j] = col
	print(max(checked))
	print(*checked)


for _ in range(int(input())):
	l = {2: 0, 3: 0, 5: 0, 7: 0, 11: 0, 13: 0, 17: 0, 19: 0, 23: 0, 29: 0, 31: 0}
	n = int(input())
	m = [int(x) for x in input().split()]
	x = 1
	for i in range(n):
		for j in l:
			if m[i] % j == 0:
				if l[j] == 0:
					l[j] = x
					x += 1
				m[i] = l[j]
				break
	print(x - 1)
	for i in range(n):
		print(m[i], end=' ')
	print()


def getPrimes(n):
	count = 0
	primes = [True] * (n + 1)
	primes[0] = primes[1] = False
	for i in range(2, n + 1):
		if primes[i]:
			count += 1
			j = 2
			while i * j <= n:
				primes[i * j] = False
				j += 1
	return primes

def solve(arr, primes, ans):
	colors = [0] * len(arr)
	m = 1
	for i in range(2, len(primes)):
		if primes[i]:
			indices = []
			for j in range(len(arr)):
				if arr[j] % i == 0 and colors[j] == 0:
					indices.append(j)
			if indices:
				for j in indices:
					colors[j] = m
				m += 1
	ans.append([m - 1])
	ans.append(colors)

def main():
	primes = getPrimes(10 ** 3)
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, primes, ans)
	for i in ans:
		for j in i:
			print(j, end=' ')
		print()
main()


N = int(input())
pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
Ans = ''
for i in range(N):
	n = int(input())
	q = list(map(int, input().split()))
	c = [0 for p in range(n)]
	l = 0
	ans = ''
	h = 1
	while 0 in c:
		flag = 0
		for i in range(n):
			if q[i] % pr[l] == 0 and c[i] == 0:
				c[i] = h
				flag = 1
		if flag:
			h += 1
		l += 1
	for r in range(len(c)):
		ans += str(c[r]) + ' '
	Ans += str(h - 1) + '\n' + ans + '\n'
print(Ans)


import sys

def input():
	return sys.stdin.readline()[:-1]
t = int(input())
divs = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	cur = 1
	used = [0 for _ in range(11)]
	for x in a:
		for (i, d) in enumerate(divs):
			if x % d == 0:
				if used[i] == 0:
					b.append(cur)
					used[i] = cur
					cur += 1
				else:
					b.append(used[i])
				break
	print(cur - 1)
	print(*b)


t = int(input())
cases = []
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	cases.append(a)
p = [None for _ in range(1001)]
for i in range(2, 1001):
	for j in range(2, 1001):
		if i % j == 0:
			p[i] = j
			break
for c in cases:
	colors = 0
	s = {}
	ans = [None for _ in range(len(c))]
	for (i, el) in enumerate(c):
		d = p[el]
		if s.get(d) is None:
			colors += 1
			s[d] = colors
		ans[i] = s[d]
	print(colors)
	print(' '.join([str(i) for i in 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():
	primes = SieveOfEratosthenes(100)
	for _ in range(int(sin())):
		n = int(sin())
		a = ain()
		m = 1
		res = []
		used = {}
		for num in a:
			for p in primes:
				if num % p == 0:
					if p in used:
						res.append(used.get(p))
					else:
						res.append(m)
						used[p] = m
						m += 1
					break
		print(m - 1)
		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()


for i in range(int(input())):
	n = int(input())
	primes = {2: 0, 3: 0, 5: 0, 7: 0, 11: 0, 13: 0, 17: 0, 19: 0, 23: 0, 29: 0, 31: 0}
	l = list(map(int, input().split()))
	for j in primes:
		l1 = []
		for k in range(n):
			if l[k] % j == 0:
				l1.append((l[k], k))
		primes[j] = l1
	d = {}
	for k in range(n):
		d[k] = 0
	index = 1
	for j in primes:
		check = 0
		for k in range(len(primes[j])):
			if d[primes[j][k][1]] == 0:
				check = 1
				d[primes[j][k][1]] = index
		if check == 1:
			index += 1
	max = 0
	for j in d:
		if max < d[j]:
			max = d[j]
	print(max)
	for j in d:
		print(d[j], end=' ')
	print()


T = int(input())
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	color = [0] * n
	m = 0
	setup = set()

	def run(x):
		global m
		for i in range(n):
			if not color[i] and a[i] % x == 0:
				color[i] = m + 1
				setup.add(x)
		if x in setup:
			m += 1
	for d in range(2, 32):
		run(d)
	for i in range(n):
		if color[i] == 0:
			color[i] = m + 1
			m += 1
	print(m)
	print(' '.join(map(str, color)))


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def first_factor(x):
	for p in primes:
		if x % p == 0:
			return p
	return 0
t = int(input())
output = ''
for i in range(t):
	m = 0
	factors = []
	tuples = []
	res = ''
	n = int(input())
	A = [int(x) for x in input().split(' ')]
	for j in range(n):
		p = first_factor(A[j])
		if p not in factors:
			factors.append(p)
			m += 1
			res += str(m) + ' '
		else:
			res += str(factors.index(p) + 1) + ' '
	output += str(m) + '\n' + res + '\n'
print(output)


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

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	d = {2: [], 3: [], 5: [], 7: [], 11: [], 13: [], 17: [], 19: [], 23: [], 29: [], 31: []}
	for i in range(n):
		d[smallestDivisor(a[i])].append(i)
	cur = 1
	ans = [0] * n
	for key in d:
		if len(d[key]) != 0:
			for j in range(len(d[key])):
				ans[d[key][j]] = cur
			cur += 1
	print(cur - 1)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	cold = {}
	vis = {}
	col = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
	for i in range(n):
		if a[i] % 2 == 0:
			if 2 in vis:
				d[i] = vis[2]
			else:
				d[i] = col[0]
				vis[2] = col[0]
				col.pop(0)
		elif a[i] % 3 == 0:
			if 3 in vis:
				d[i] = vis[3]
			else:
				d[i] = col[0]
				vis[3] = col[0]
				col.pop(0)
		elif a[i] % 5 == 0:
			if 5 in vis:
				d[i] = vis[5]
			else:
				d[i] = col[0]
				vis[5] = col[0]
				col.pop(0)
		elif a[i] % 7 == 0:
			if 7 in vis:
				d[i] = vis[7]
			else:
				d[i] = col[0]
				vis[7] = col[0]
				col.pop(0)
		elif a[i] % 11 == 0:
			if 11 in vis:
				d[i] = vis[11]
			else:
				d[i] = col[0]
				vis[11] = col[0]
				col.pop(0)
		elif a[i] % 13 == 0:
			if 13 in vis:
				d[i] = vis[13]
			else:
				d[i] = col[0]
				vis[13] = col[0]
				col.pop(0)
		elif a[i] % 17 == 0:
			if 17 in vis:
				d[i] = vis[17]
			else:
				d[i] = col[0]
				vis[17] = col[0]
				col.pop(0)
		elif a[i] % 19 == 0:
			if 19 in vis:
				d[i] = vis[19]
			else:
				d[i] = col[0]
				vis[19] = col[0]
				col.pop(0)
		elif a[i] % 23 == 0:
			if 23 in vis:
				d[i] = vis[23]
			else:
				d[i] = col[0]
				vis[23] = col[0]
				col.pop(0)
		elif a[i] % 29 == 0:
			if 29 in vis:
				d[i] = vis[29]
			else:
				d[i] = col[0]
				vis[29] = col[0]
				col.pop(0)
		elif a[i] % 31 == 0:
			if 31 in vis:
				d[i] = vis[31]
			else:
				d[i] = col[0]
				vis[31] = col[0]
				col.pop(0)
	maxi = max(d.values())
	print(maxi)
	for i in d.values():
		print(i, end=' ')
	print()


from math import gcd

def sieve(n):
	s = [True for _ in range(n + 1)]
	i = 2
	while i * i <= n:
		for j in range(2 * i, n, i):
			s[j] = False
		i += 1
	primes = []
	for i in range(2, len(s)):
		if s[i]:
			primes.append(i)
	return primes
primes = sieve(1000)
t = int(input())
for tc in range(t):
	els = int(input())
	a = [int(kek) for kek in input().split()]
	colors = [0 for i in range(els)]
	cnt = 1
	howMany = 0
	for p in primes:
		dirty = False
		for i in range(els):
			if colors[i] == 0 and a[i] % p == 0:
				colors[i] = cnt
				dirty = True
				howMany += 1
		if howMany == els:
			break
		if dirty == True:
			cnt += 1
	print(cnt)
	for col in colors:
		print(col, end=' ')
	print('')


from collections import Counter, defaultdict, deque, namedtuple
from math import gcd
import sys

def read_ints():
	return [int(token) for token in input().split()]

def read_tokens():
	return input().split()
PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def main():
	T = read_ints()[0]
	for case_no in range(1, T + 1):
		n = read_ints()[0]
		A = read_ints()
		colors = [-1] * n
		used = dict()
		for (i, a) in enumerate(A):
			j = 0
			while j < len(PRIMES) and a % PRIMES[j] != 0:
				j += 1
			if j + 1 not in used:
				sz = len(used)
				used[j + 1] = 1 + sz
			colors[i] = used[j + 1]
		print(len(used))
		print(' '.join((str(c) for c in colors)))
main()


pr = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
q = int(input())
while q != 0:
	q -= 1
	all_col = dict()
	n = int(input())
	lt = [int(x) for x in input().split()]
	used = 1
	for i in range(n):
		k = lt[i]
		j = 0
		while k % pr[j] != 0:
			j += 1
		if pr[j] in all_col:
			lt[i] = all_col[pr[j]]
		else:
			lt[i] = used
			all_col[pr[j]] = used
			used += 1
	print(len(list(set(lt))))
	print(*lt)


import math
for nt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [-1] * n
	color = 1
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
	for i in range(12):
		flag = False
		for j in range(n):
			if ans[j] == -1:
				if l[j] % primes[i] == 0:
					ans[j] = color
					flag = True
		if flag:
			color += 1
	print(len(set(ans)))
	print(*ans)


import sys
import os
from io import BytesIO, IOBase

def cel(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 defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(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')
from collections import defaultdict
from math import gcd
for _ in range(ii()):
	n = ii()
	a = li()
	num = 1
	res = [0 for i in range(n)]
	for i in range(2, 32):
		f = 0
		for j in range(n):
			if a[j] % i == 0:
				res[j] = num
				f = 1
				a[j] = 1
		if f == 1:
			num += 1
	print(len(set(res)))
	print(*res)


from sys import stdin
from collections import defaultdict
nums = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	op = []
	arr = list(map(int, stdin.readline().rstrip().split(' ')))
	for ele in arr:
		for z in nums:
			if ele % z == 0:
				op.append(z)
				break
	op3 = list(set(op))
	op2 = {}
	for i in range(len(op3)):
		op2[op3[i]] = i + 1
	op4 = []
	for i in op:
		op4.append(op2[i])
	print(len(op3))
	print(*op4)


import sys
import math

def IO():
	sys.stdin = open('pyinput.txt', 'r')
	sys.stdout = open('pyoutput.txt', 'w')

def GCD(a, b):
	if b == 0:
		return a
	else:
		return GCD(b, a % b)

def LCM(a, b):
	return a * (b // GCD(a, b))

def scan(TYPE_1, TYPE_2=0):
	if TYPE_1 == int:
		return map(int, sys.stdin.readline().strip().split())
	elif TYPE_1 == float:
		return map(float, sys.stdin.readline().strip().split())
	elif TYPE_1 == list and TYPE_2 == float:
		return list(map(float, sys.stdin.readline().strip().split()))
	elif TYPE_1 == list and TYPE_2 == int:
		return list(map(int, sys.stdin.readline().strip().split()))
	elif TYPE_1 == str:
		return sys.stdin.readline().strip()
	else:
		print('ERROR!!!!')

def main():
	t = int(scan(str))
	while t > 0:
		t -= 1
		n = int(scan(str))
		a = scan(list, int)
		prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
		ans = [0 for i in range(32)]
		mark = [0 for i in range(1001)]
		tp = 1
		for i in prime:
			for p in range(i, 1001, i):
				if mark[p] == 0:
					mark[p] = i
		for i in range(n):
			if ans[mark[a[i]]] == 0:
				ans[mark[a[i]]] = tp
				tp += 1
			a[i] = ans[mark[a[i]]]
		print(tp - 1, '\n', *a)
main()


import io, os
R = lambda : map(int, input().split())
prim = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	vc = [[] for _ in range(12)]
	n = int(input())
	a = list(R())
	for i in range(n):
		for j in range(11):
			if a[i] % prim[j] == 0:
				vc[j].append(a[i])
				break
	tot = 0
	ans = {}
	for i in range(11):
		if len(vc[i]) == 0:
			continue
		tot += 1
		for j in vc[i]:
			ans[j] = tot
	print(tot)
	print(*[ans[a[x]] for x in range(n)])


from collections import Counter
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')
from bisect import bisect_right
import math
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ls = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
	ans = [-1] * n
	cnt = 0
	c = 1
	for j in range(12):
		f = 0
		for i in range(n):
			if arr[i] % ls[j] == 0 and ans[i] == -1:
				ans[i] = c
				f = 1
		if f == 1:
			c += 1
	print(len(list(set(ans))))
	print(*ans)


kek = {2: 1, 3: 2, 5: 3, 7: 4, 11: 5, 13: 6, 17: 7, 19: 8, 23: 9, 29: 10, 31: 11}
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	res = []
	used_col = set()
	for el in a:
		for k in sorted(kek):
			if el % k == 0:
				res.append(kek[k])
				used_col.add(kek[k])
				break
	print(len(used_col))
	d = {col: i + 1 for (i, col) in enumerate(used_col)}
	for i in res:
		print(d[i], end=' ')
	print()


f11 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
import random
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ind = 0
	ans = [None for i in range(n)]
	cov = [1 for i in range(11)]
	for i in range(n):
		count = 0
		for ind in range(11):
			if a[i] % f11[ind] == 0:
				cov[ind] = 0
				ans[i] = ind + 1
				break
	prefix = [0 for i in range(11)]
	pre = 0
	for i in range(11):
		pre += cov[i]
		prefix[i] = pre
	for i in range(n):
		ans[i] -= prefix[ans[i] - 1]
	print(11 - prefix[-1])
	print(*ans)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for i in range(t):
	n = int(input())
	ls = [int(a) for a in input().split()]
	an = []
	for j in range(n):
		an.append(0)
	ctr = 1
	for p in range(len(primes)):
		nx = False
		for j in range(n):
			if ls[j] % primes[p] == 0 and an[j] == 0:
				an[j] = ctr
				nx = True
		if nx == True:
			ctr += 1
	s = ''
	for a in an:
		s += str(a) + ' '
	print(ctr - 1)
	print(s)


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	d = []
	len_d = 0
	for k in range(0, n):
		flag = 0
		if k == 0:
			for p in range(0, 11):
				if a[k] % primes[p] == 0:
					d.append(primes[p])
					len_d = len_d + 1
					ans.append(len_d)
					break
		else:
			for j in range(0, len_d):
				if a[k] % d[j] == 0:
					ans.append(j + 1)
					flag = 1
					break
			if flag == 0:
				for p in range(0, 11):
					if a[k] % primes[p] == 0:
						d.append(primes[p])
						len_d = len_d + 1
						ans.append(len_d)
						break
	ll = len(ans)
	print(len_d)
	for k in range(0, ll):
		if k == ll - 1:
			print(ans[k])
		else:
			print(ans[k], end=' ')


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
l = []
lst = []
for i in range(int(input())):
	input()
	for (i1, j) in enumerate(map(int, input().split())):
		for n in p:
			if j % n == 0:
				if n in l:
					lst.append(l.index(n) + 1)
					break
				else:
					l.append(n)
					lst.append(l.index(n) + 1)
					break
	s = set(lst)
	print(len(s))
	print(*lst)
	lst.clear()
	l.clear()


import math
for h in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
	ans = [0 for i in range(n)]
	col = 1
	dicti = {}
	for i in range(n):
		for j in primes:
			if arr[i] % j == 0:
				if j in dicti:
					ans[i] = dicti[j]
				else:
					ans[i] = col
					dicti[j] = col
					col += 1
				break
	print(max(ans))
	print(*ans)


for x in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	lis = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	ali = []
	ma = {}
	ans = 0
	for i in li:
		for j in lis:
			if i % j == 0:
				try:
					ali.append(ma[j])
					break
				except:
					ma[j] = ans + 1
					ans = ans + 1
					ali.append(ma[j])
					break
	print(ans)
	print(*ali, sep=' ')


import sys
t = int(input())
inp = [line.strip().split() for line in reversed(sys.stdin.readlines())]
ans = []
markers = []
simple_numbers = []
for i in range(2, 100):
	flag = True
	j = 2
	while j * j <= i:
		if i % j == 0:
			flag = False
			break
		j += 1
	if flag:
		simple_numbers.append(i)
while t:
	n = int(inp[-1][0])
	a = [int(i) for i in inp[-2]]
	markers = [0] * n
	used_count = 1
	prev_used = False
	for simp in simple_numbers:
		if not all(markers):
			if prev_used:
				used_count += 1
			numbers_colored = 0
			for (ind_an, an) in enumerate(a):
				if an % simp == 0 and markers[ind_an] == 0:
					markers[ind_an] = used_count
					prev_used = True
					numbers_colored += 1
			if numbers_colored == 0:
				prev_used = False
		else:
			break
	print(used_count)
	print(*markers)
	inp.pop()
	inp.pop()
	t -= 1


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for _ in range(t):
	n = int(input())
	mapped = {p: [] for p in primes}
	arr = list(map(int, input().split()))
	for i in range(n):
		for p in primes:
			if arr[i] % p == 0:
				mapped[p].append(i)
	id_color = 0
	colored = [0] * n
	for (p, idxs) in mapped.items():
		if len(idxs) > 0:
			id_color += 1
			is_used = False
			for idx in idxs:
				if colored[idx] == 0:
					is_used = True
					colored[idx] = id_color
			if not is_used:
				id_color -= 1
	print(max(colored))
	for i in range(n):
		if i != n - 1:
			print(colored[i], end=' ')
		else:
			print(colored[i])


P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]

def gp(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	D = [0 for i in range(11)]
	for i in range(n):
		x = P.index(gp(A[i]))
		D[x] = 1
	c = 0
	num = []
	for i in range(11):
		num.append(c)
		if D[i]:
			c += 1
	print(c)
	for i in range(n):
		x = P.index(gp(A[i]))
		print(num[x] + 1, end=' ')
	print()


def answer(n, A):
	dp = [1] * 32
	dp[0] = dp[1] = 0
	for i in range(2, 32):
		if dp[i] == 1:
			p = 2 * i
			while p <= 31:
				if dp[p] == 1:
					dp[p] = 0
				p += i
	count = 1
	res = [0] * n
	for i in range(2, 32):
		if dp[i] == 1:
			flag = 0
			for j in range(n):
				if res[j] == 0 and A[j] % i == 0:
					flag = 1
					res[j] = count
			if flag == 1:
				count += 1
	return (count, res)
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	(a, b) = answer(n, arr)
	print(a - 1)
	print(*b)


def solve(arr):
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	res = []
	for i in arr:
		for p in primes:
			if i % p == 0:
				res.append(p)
				break
	d = {}
	index = 1
	for i in range(len(res)):
		if res[i] not in d:
			d[res[i]] = index
			index += 1
		res[i] = d[res[i]]
	print(index - 1)
	print(' '.join(map(str, res)))
T = int(input())
for ti in range(1, T + 1):
	N = int(input())
	arr = list(map(int, input().split(' ')))
	solve(arr)


t = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
while t:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	d = {}
	c = 0
	ans = []
	for i in range(n):
		flag = 0
		temp = -1
		for j in p:
			if a[i] % j == 0:
				if j in d.keys():
					ans += [d[j]]
					flag = 1
					break
				else:
					temp = j
					break
		if flag == 0:
			c += 1
			d[temp] = c
			ans += [c]
	print(c)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	res = [-1 for _ in range(n)]
	current_color = 1
	if len(arr) <= 11:
		print(n)
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	else:
		for p in prime:
			ok = False
			for j in range(n):
				if res[j] != -1:
					continue
				if arr[j] % p:
					continue
				ok = True
				res[j] = current_color
			if ok:
				current_color += 1
		print(current_color - 1)
		for s in range(n):
			print(res[s], end=' ')
		print()


I = lambda : list(map(int, input().split()))
p = [0] * 501
pr = []
for i in range(2, 501):
	n = i
	for j in range(2, int(n ** 0.5) + 1):
		if n % j == 0:
			break
	else:
		p[i] = 1
		pr.append(i)
for _ in range(int(input())):
	(n,) = I()
	l = I()
	c = [0] * n
	ck = [0] * 11
	k = 1
	for i in range(n):
		if l[i]:
			for x in range(11):
				if l[i] % pr[x] == 0:
					if ck[x] == 0:
						ck[x] = k
						k += 1
					c[i] = ck[x]
					break
	print(max(c))
	print(*c)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dic = []
	for i in range(15):
		dic.append([])
	bic = {}
	if n <= 11:
		print(n)
		for i in range(n):
			print(i + 1, end=' ')
		print()
	else:
		bic = {}
		ft = {}
		ar = []
		for i in a:
			ft[i] = False
		for i in range(11):
			ar.append([])
		m = 1
		ans = 0
		for i in range(2, 1001):
			x = 0
			for j in a:
				if ft[j] == False:
					if j % i == 0:
						x = 1
						bic[j] = m
						ft[j] = True
						ans = m
			if x == 1:
				m += 1
		print(ans)
		for i in a:
			print(bic[i], end=' ')
		print()


import sys

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		fout = open('output.txt', 'w')
		sys.stdin = fin
		sys.stdout = fout
set_debug(False)
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for i in range(int(input())):
	input()
	a = [min((i + 1 for i in range(11) if a % p[i] == 0), default=10 ** 4) for a in map(int, input().split())]
	sa = sorted(set(a))
	print(len(sa))
	print(*[sa.index(x) + 1 for x in a])


from sys import stderr
import math
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]

def get_prime_factors(x):
	factors = []
	for p in primes:
		if x % p == 0:
			factors.append(p)
		while x % p == 0:
			x //= p
	if x != 1:
		factors.append(x)
	return tuple(factors)

def find_coloring(xs):
	xs_by_factor = {}
	ix_by_factor = {}
	for (i, x) in enumerate(xs):
		for p in get_prime_factors(x):
			if p not in xs_by_factor:
				xs_by_factor[p] = set((x,))
				ix_by_factor[p] = set((i,))
			else:
				xs_by_factor[p].add(x)
				ix_by_factor[p].add(i)
	color = 0
	colors_by_x = {}
	while len(xs_by_factor) != 0:
		(p, _xs) = max(xs_by_factor.items(), key=lambda x: len(x[1]))
		for x in _xs:
			colors_by_x[x] = color
			for (q, ys) in xs_by_factor.items():
				if q == p:
					continue
				ys.discard(x)
		del xs_by_factor[p]
		for q in tuple(xs_by_factor.keys()):
			if len(xs_by_factor[q]) == 0:
				del xs_by_factor[q]
		color += 1
	print(color)
	print(*(colors_by_x[x] + 1 for x in xs))
	for (p, xs) in xs_by_factor.items():
		print(p, xs, file=stderr)
for _ in range(int(input())):
	input()
	xs = list(map(int, input().split(' ')))
	find_coloring(xs)


p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(int(input())):
	n = int(input())
	m = 0
	a = []
	c = {}
	for x in map(int, input().split()):
		for (i, d) in enumerate(p):
			if 0 == x % d:
				a += (i,)
				c[i] = 0
				break
	for (i, x) in enumerate(c):
		c[x] = i + 1
	print(len(c))
	a = [c[x] for x in a]
	print(*a)


import sys
import math as m
input = sys.stdin.readline
p = [i for i in range(2, 33) if all((i % j for j in range(2, i)))]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	col = {}
	for i in range(n):
		for (j, k) in enumerate(p):
			if a[i] % k == 0:
				ans.append(col.setdefault(j, len(col) + 1))
				break
	print(len(col))
	print(*ans)


t = int(input())
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for x in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = []
	for i in range(n):
		for g in range(len(p)):
			if len(k) == i and a[i] % p[g] == 0:
				k.append(p[g])
	dif = []
	for i in range(n):
		if not k[i] in dif:
			dif.append(k[i])
	print(len(dif))
	q = ''
	for i in range(n):
		for g in range(len(dif)):
			if k[i] == dif[g]:
				q = q + str(g + 1) + ' '
	print(q[:-1])


t = int(input())

def primes(n):
	odds = range(3, n + 1, 2)
	sieve = set(sum([list(range(q * q, n + 1, q + q)) for q in odds], []))
	return [2] + [p for p in odds if p not in sieve]
for _ in range(t):
	input()
	arr = list(map(int, input().split()))
	s = set(arr)
	coloring = dict()
	color = 0
	for prime in primes(1000):
		colored = False
		for v in list(s):
			if v % prime == 0:
				coloring[v] = color + 1
				s.remove(v)
				colored = True
		if colored:
			color += 1
	print(color)
	print(*[coloring[x] for x in arr])


def gcd(a, b):
	if a < b:
		return gcd(b, a)
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
isp = [1] * 1010
p = []
for i in range(2, 1000):
	if isp[i]:
		p += [i]
		for j in range(i + i, 1000, i):
			isp[j] = 0
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	c = [0] * n
	for i in range(n):
		if c[i] == 0:
			k += 1
			x = -1
			for pp in p:
				if a[i] % pp == 0:
					x = pp
					break
			for j in range(i, n):
				if a[j] % x == 0:
					c[j] = k
	print(k)
	print(*c)


import sys
from heapq import *
from collections import defaultdict as dd
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n,) = inp()
	a = inp()
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	res = [0] * 11
	ans = [0] * n
	count = 1
	for i in range(n):
		for j in range(11):
			if a[i] % p[j] == 0:
				if res[j] == 0:
					res[j] = count
					count += 1
				ans[i] = res[j]
				break
	print(11 - res.count(0))
	print(*ans)


import sys
input = sys.stdin.readline
P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ANS = []
	for a in A:
		for i in range(11):
			if a % P[i] == 0:
				ANS.append(i + 1)
				break
	compression_dict = {a: ind + 1 for (ind, a) in enumerate(sorted(set(ANS)))}
	ANS = [compression_dict[a] for a in ANS]
	print(max(ANS))
	print(*ANS)


t = int(input())
primes = list(range(2, 1003))
for i in range(2, int(1002 ** 0.5) + 1):
	if i in primes:
		j = i * i
		while j <= 1002:
			try:
				primes.remove(j)
			except:
				pass
			j += i
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * n
	track = 1
	for i in primes:
		flag = 0
		for j in range(n):
			if a[j] % i == 0:
				if b[j] == 0:
					b[j] = track
					flag = 1
		if flag:
			track += 1
		if b.count(0) == 0:
			break
	print(len(list(set(b))))
	print(*b)


import sys
import math
readLine = lambda : sys.stdin.readline()
readInt = lambda : int(sys.stdin.readline())
readInts = lambda : [int(x) for x in sys.stdin.readline().split(' ')]

def main():
	solns = []
	primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	factorToColor = {p: i + 1 for (i, p) in enumerate(primes)}
	t = readInt()
	for _ in range(t):
		n = readInt()
		a = readInts()
		out = []
		found = set()
		for e in a:
			for p in primes:
				if math.gcd(e, p) == p:
					out.append(p)
					if p not in found:
						found.add(p)
					break
		found = list(found)
		found.sort()
		out = [found.index(p) + 1 for p in out]
		solns.append(f'{len(found)}\n' + ' '.join((str(x) for x in out)))
	print('\n'.join(solns))
main()


def getLowestMultiple(i):
	c = 2
	while True:
		if i % c == 0:
			return c
		if c * c > i:
			return None
		c += 1
cases = int(input())
for i in range(cases):
	arrayLength = len(input())
	numbers = [int(x) for x in input().split(' ')]
	numberset = set(sorted(numbers))
	colours = []
	for o in numberset:
		lowestMultiple = getLowestMultiple(o)
		if lowestMultiple not in colours:
			colours.append(lowestMultiple)
	print(len(colours))
	print(' '.join([str(colours.index(getLowestMultiple(x)) + 1) for x in numbers]))


t = int(input())
for i in range(t):
	n = int(input())
	lis = list(map(int, input().split()))
	clr_map = [0 for i in range(n)]
	maxi = max(lis)
	j = 2
	clr = 1
	while j * j <= maxi:
		look = False
		for k in range(n):
			if lis[k] % j == 0:
				if clr_map[k] == 0:
					clr_map[k] = clr
					look = True
		j += 1
		if look:
			clr += 1
	if clr > 12:
		print('-1')
	else:
		print(clr - 1)
		for j in clr_map:
			print(j, end=' ')
		print()


def is_used(prime):
	for i in range(len(used)):
		if prime == used[i]:
			return i
	return -1
T = int(input())
for _ in range(T):
	p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
	used = []
	n = int(input())
	c = 0
	arr = [int(x) for x in input().split()]
	for i in range(n):
		for j in range(11):
			if arr[i] % p[j] == 0:
				ind = is_used(p[j])
				if ind < 0:
					c += 1
					arr[i] = c
					used.append(p[j])
					break
				else:
					arr[i] = ind + 1
					break
	print(c)
	for x in arr:
		print(x, end=' ')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	prime = []
	c = 0
	res = [0] * n
	col = {}
	for i in range(n):
		for j in range(2, int(pow(a[i], 0.5)) + 1):
			if a[i] % j == 0:
				if j not in prime:
					prime.append(j)
					c += 1
					col[j] = c
					res[i] = col[j]
					break
				else:
					res[i] = col[j]
					break
	print(c)
	for i in range(n):
		print(res[i], end=' ')
	print()


from math import *
from copy import *
from string import *
from random import *
from bisect import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
from collections import defaultdict

def Sieve(x):
	checkPrime = [1 for i in range(x + 1)]
	zz = 2
	L = []
	while zz ** 2 <= x:
		if checkPrime[zz] == 1:
			for i in range(zz * 2, x + 1, zz):
				checkPrime[i] = 0
		zz += 1
	for i in range(2, x):
		if checkPrime[i] == 1:
			L.append(i)
	return checkPrime
primes = Sieve(1001)

def solve(l):
	global primes
	n = len(l)
	maxx = 1
	if n < 12:
		print(n)
		return [i for i in range(1, n + 1)]
	else:
		pFactor = [[] for i in range(1001)]
		for i in range(n):
			for j in range(2, int(sqrt(l[i])) + 1):
				if l[i] % j == 0:
					if primes[j]:
						pFactor[j].append(i)
					if primes[l[i] // j]:
						pFactor[l[i] // j].append(i)
		colors = [0] * n
		start = 1
		tillNow = 1
		for i in range(len(pFactor)):
			nn = len(pFactor[i])
			if nn > 0:
				f = 0
				for j in range(nn):
					zz = pFactor[i][j]
					if colors[zz] == 0:
						f = 1
						colors[zz] = start
						tillNow = start
				if f:
					start += 1
			if start > 11:
				start = 1
		dd = defaultdict(list)
		for i in range(n):
			dd[colors[i]].append(l[i])
		for i in dd:
			ll = []
			for j in range(len(dd[i])):
				for k in range(j + 1, len(dd[i])):
					ll.append(gcd(dd[i][j], dd[i][k]))
		print(len(set(colors)))
		return colors
T = int(input())
for _ in range(T):
	N = int(stdin.readline())
	l = list(map(int, stdin.readline().rstrip().split()))
	print(*solve(l))


def getPrime(x):
	for i in range(2, x):
		if x % i == 0:
			return i
	return -1
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for T in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	used = [False for x in range(11)]
	for i in range(n):
		x = primes.index(getPrime(a[i]))
		used[x] = True
	cnt = 0
	num = []
	for i in range(11):
		num.append(cnt)
		if used[i]:
			cnt += 1
	print(cnt)
	for i in range(n):
		x = primes.index(getPrime(a[i]))
		print(num[x] + 1, end=' ')
	print()


from collections import defaultdict as dd
from math import sqrt
d = {2: 1, 3: 2, 5: 3, 7: 4, 11: 5, 13: 6, 17: 7, 19: 8, 23: 9, 29: 10, 31: 11}
for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	t = 1
	d = dd(lambda : 0)
	v = []
	for i in b:
		if i % 2 == 0:
			d[i] = 2
			continue
		for j in range(3, 102, 2):
			if i % j == 0:
				d[i] = j
				break
	p = dd(lambda : -1)
	k = sorted(set(d.values()))
	for i in range(1, len(k) + 1):
		p[k[i - 1]] = i
	print(len(p))
	for i in b:
		print(p[d[i]], end=' ')
	print()


primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
colors = [-1] * 10001
for i in range(len(primes)):
	p = primes[i]
	for j in range(0, 10001, p):
		colors[j] = i
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = set({})
	for i in a:
		s.add(colors[i])
	s = list(s)
	mapping = {}
	for i in range(len(s)):
		mapping[s[i]] = i + 1
	print(len(s))
	for i in a:
		print(mapping[colors[i]], end=' ')


import sys
input = sys.stdin.readline
T = int(input())
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	used = [False] * 11
	Ans = []
	for a in A:
		for (idx_primes, p) in enumerate(primes):
			if a % p == 0:
				Ans.append(idx_primes)
				used[idx_primes] = True
				break
		else:
			assert False
	M = [-1] * 11
	cnt = 0
	for (i, m) in enumerate(used):
		if m:
			cnt += 1
			M[i] = cnt
	print(cnt)
	print(' '.join([str(M[a]) for a in Ans]))


import sys
import math
input = sys.stdin.readline

def isPrime(n):
	if n <= 1:
		return False
	for i in range(2, n):
		if n % i == 0:
			return False
	return True
prime = []
for i in range(2, 1001):
	if isPrime(i):
		prime.append(i)
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = [0] * n
	d = {}
	maxi = max(l[:]) + 1
	index = {}
	for i in prime:
		d[i] = []
	for i in range(n):
		index[i] = 1
	for i in prime:
		for j in range(n):
			if l[j] % i == 0:
				d[i].append(j)
	m = 1
	for i in d:
		ch = 0
		for j in range(len(d[i])):
			if index.get(d[i][j], -1) != -1:
				ch = 1
				c[d[i][j]] = m
				del index[d[i][j]]
		if ch == 1:
			m += 1
	print(m - 1)
	for i in range(n):
		print(c[i], end=' ')
	print()