← Home
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

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

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)

		colors := make([]int, n)
		colorMap := make(map[int]int)
		currentColor := 0

		for j := 0; j < n; j++ {
			var a int
			fmt.Fscan(in, &a)

			for _, p := range primes {
				if a%p == 0 {
					if colorMap[p] == 0 {
						currentColor++
						colorMap[p] = currentColor
					}
					colors[j] = colorMap[p]
					break
				}
			}
		}

		fmt.Fprintln(out, currentColor)
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Fprint(out, " ")
			}
			fmt.Fprint(out, colors[j])
		}
		fmt.Fprintln(out)
	}
}