#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}
int a[1005];
int g[15];
int c[1005];
bool flag = false;
int T, n, m;

void dfs(int st)
{
    if (st == n) flag = true;
    if (flag) return;
    for (int i = 1; i <= 11; i++)
    {
        if (g[i] == 0) g[i] = a[st], m = i;
        if (gcd(g[i], a[st]) == 1) continue;
        int p = g[i];
        g[i] = gcd(g[i], a[st]);
        c[st] = i;
        dfs(st + 1);
        if (flag) return;
        g[i] = p;
    }
}
int primes[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43};
int mp[15];
int main()
{
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &n);
        for (int i = 0; i < n; i++) scanf("%d", a + i);
        for (int i = 0; i < n; i++)
            for (int j = 1; j <= 11; j++)
                if (a[i] % primes[j] == 0)
                    c[i] = j;
        memset(mp, 0, sizeof(mp));
        int a = 0;
        for (int i = 0; i < n; i++)
        {
            if (mp[c[i]] == 0) mp[c[i]] = ++a;
            c[i] = mp[c[i]];
        }
        printf("%d\n", a);
        for (int i = 0; i < n; i++) printf("%d%c", c[i], " \n"[i == n - 1]);
    }
    return 0;
}