/*
	*	Created By: 'Present_Sir'
	*	Created On: Saturday 25 July 2020 10:19:17 AM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << " " << to_string(H);
	debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define db(...)  cout << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define db(...)
#endif

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    vector<int> co(n,-1);
    int k = 0;
    for(int i=0; i<n; i++){
        if(co[i] == -1) co[i] = k+1;
        else continue;
        for(int j=i+1; j<n; j++){
            if(__gcd(v[i],v[j]) > 1){
                co[j] = co[i];
                db(v[i],v[j],__gcd(v[i],v[j]));
            }
            k = max(k,co[i]);
        }
            k = max(k,co[i]);
    }
    cout<<k<<endl;
    for(int i=0; i<n; i++){
        cout<<co[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Saturday 25 July 2020 10:19:17 AM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << " " << to_string(H);
	debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define db(...)  cout << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define db(...)
#endif

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    vector<int> co(n,-1);
    int k = 0;
    for(int i=0; i<n; i++){
        if(co[i] == -1) co[i] = k+1;
        else continue;
        for(int j=i+1; j<n; j++){
            if(__gcd(v[i],v[j]) > 1){
                co[j] = co[i];
                db(v[i],v[j],__gcd(v[i],v[j]));
            }
            k = max(k,co[j]);
        }
    }
    cout<<k<<endl;
    for(int i=0; i<n; i++){
        cout<<co[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Sunday 26 July 2020 10:42:52 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> color(n);
    vector<int> co[11];
    int ar[] = {2,3,5,7,11,13,17,19,23,29,31};
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        for(int j=0; j<11; j++){
            if(x%ar[j]){
                co[j].push_back(i);
                break;
            }
        }
    }
    int k=1;
    for(int i=0; i<11; i++){
        if(co[i].size()){
            for(auto x: co[i]){
                color[x]=k;
            }
            ++k;
        }
    }
    cout<<k-1<<endl;
    for(int i=0; i<n; i++){
        cout<<color[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Sunday 26 July 2020 10:42:52 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> color(n,12);
    vector<int> co[11];
    int ar[] = {2,3,5,7,11,13,17,19,23,29,31};
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        for(int j=0; j<11; j++){
            if(x%ar[j] == 0){
                co[j].push_back(i);
                break;
            }
        }
    }
    int k=1;
    for(int i=0; i<11; i++){
        if(co[i].size()){
            for(auto x: co[i]){
                color[x]=k;
            }
            ++k;
        }
    }
    cout<<k-1<<endl;
    for(int i=0; i<n; i++){
        cout<<color[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Sunday 26 July 2020 10:42:52 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> color(n,12);
    vector<int> co[11];
    int ar[] = {2,3,5,7,11,13,17,19,23,29,31};
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        for(int j=0; j<11; j++){
            if(x%ar[j] == 0){
                co[j].push_back(i);
                break;
            }
        }
    }
    int k=1;
    for(int i=0; i<11; i++){
        if(co[i].size()){
            cout<<i<<" "<<co[i].size()<<" "<<endl;
            for(auto x: co[i]){
                color[x]=k;
            }
            ++k;
        }
    }
    cout<<k-1<<endl;
    for(int i=0; i<n; i++){
        cout<<color[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Saturday 25 July 2020 10:19:17 AM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << " " << to_string(H);
	debug_out(T...);
}
#ifndef ONLINE_JUDGE
#define db(...)  cout << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define db(...)
#endif

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    vector<int> co(n,-1);
    int k = 0;
    for(int i=0; i<n; i++){
        if(co[i] == -1) co[i] = k+1;
        else continue;
        for(int j=0; j<n; j++){
            if(__gcd(v[i],v[j]) > 1){
                co[j] = co[i];
            }
            k = max(k,co[i]);
        }
            k = max(k,co[i]);
    }
    cout<<k<<endl;
    for(int i=0; i<n; i++){
        cout<<co[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Saturday 25 July 2020 10:19:17 AM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    vector<int> co(n,-1);
    co[0] = 1;
    int k = 1;
    for(int i=0; i<n; i++){
        if(co[i] == -1) co[i] = k+1;
        else continue;
        for(int j=i+1; j<n; j++){
            if(__gcd(v[i],v[j]) > 1){
                    co[j] = co[i];
            }
            k = max(k,co[j]);
        }
    }
    cout<<k<<endl;
    for(int i=0; i<n; i++){
        cout<<co[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


/*
	*	Created By: 'Present_Sir'
	*	Created On: Saturday 25 July 2020 10:19:17 AM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    vector<int> co(n,-1);
    co[0] = 1;
    int k = 1;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(__gcd(v[i],v[j]) == 1){
                    co[j] = co[i]+1;
            }else{
                co[j] = co[i];
            }
            k = max(k,co[j]);
        }
    }
    cout<<k<<endl;
    for(int i=0; i<n; i++){
        cout<<co[i]<<" ";
    }
    cout<<endl;
}

int32_t main(){
    IOS;
    int t; cin>>t; while(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
vector<int>prime = {2,3,5,7,11,13,17,19,23,29,31};
bool solve()
{
	int n;cin>>n;vector<int>a(n+2),ans(n+2,-1);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int p = 1;
	for (int i = 0; i < 11; ++i)
	{
		bool used = false;
		for (int j = 0; j < n; ++j)
		{
			if(a[j]%prime[i]==0 && ans[j]==-1)
			{
				ans[j] = p;
				used = true;
			}
		}
		if(used) p++;
	}
	cout<<p-1<<endl;
	for(int i = 0;i <n;++i)cout<<ans[i]<<" ";cout<<endl;
}
 int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int t;cin>>t;
	while(t--)
	{
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        vector<ll>ans(n,0);
        vector<ll>vis(12,0);
        vector<ll>g={2,3,5,7,11,13,17,19,23,29,31};
        for(ll i=0;i<n;i++)
          cin>>a[i];
          k=1;
        for(ll i=0;i<11;i++)
        {
            ll s=0;
            for(ll j=0;j<n;j++)
            {
             if(a[j]!=-1 && a[j]%g[i]==0)
             {
                 s=1;
                 a[j]=-1;
                 ans[j]=k;
             }
            }
            if(s)
            k++;
        }
            cout<<k-1<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
unordered_map<ll,ll>m;
void calculate()
{
    for(ll i=4;i<=1000;i++)
    {
        if(i%2==0)
        m[i]=2;
        else if(i%3==0)
        m[i]=3;
        else if(i%5==0)
        m[i]=5;
        else if(i%7==0)
        m[i]=7;
        else if(i%11==0)
        m[i]=11;
        else if(i%13==0)
        m[i]=4;
        else if(i%17==0)
        m[i]=6;
        else if(i%19==0)
        m[i]=8;
        else if(i%23==0)
        m[i]=9;
        else if(i%29==0)
        m[i]=10;
        else if(i%31==0)
        m[i]=1;
    }
}
int main()
{
    calculate();
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        vector<ll>ans(n,0);
        vector<ll>vis(12,0);
        for(ll i=0;i<n;i++)
        {
          cin>>a[i];
          ans[i]=m[a[i]];
        }
            k=0;
            for(ll i=0;i<n;i++)
            {
              if(!vis[ans[i]])
              vis[ans[i]]=1;
            }
            for(int i=1;i<=11;i++)
            if(vis[i])
            k++;
            cout<<k<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
unordered_map<int,int>m;
void calculate()
{
    for(ll i=4;i<=1000;i++)
    {
        if(i%2==0)
        m[i]=2;
        else if(i%3==0)
        m[i]=3;
        else if(i%5==0)
        m[i]=5;
        else if(i%7==0)
        m[i]=7;
        else if(i%11==0)
        m[i]=11;
        else if(i%13==0)
        m[i]=4;
        else if(i%17==0)
        m[i]=6;
        else if(i%19==0)
        m[i]=8;
        else if(i%23==0)
        m[i]=9;
        else if(i%29==0)
        m[i]=10;
        else if(i%31==0)
        m[i]=1;
    }
}
int main()
{
    calculate();
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        vector<ll>ans(n,0);
        int vis[11]={0};
        for(ll i=0;i<n;i++)
        {
          cin>>a[i];
          ans[i]=m[a[i]];
        }
            k=0;
            for(ll i=0;i<n;i++)
            {
              if(!vis[ans[i]-1])
              vis[ans[i]-1]=1;
            }
            for(int i=0;i<11;i++)
            if(vis[i])
            k++;
            cout<<k<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
unordered_map<ll,ll>m;
void calculate()
{
    for(ll i=4;i<=1000;i++)
    {
        if(i%2==0)
        m[i]=1;
        else if(i%3==0)
        m[i]=2;
        else if(i%5==0)
        m[i]=3;
        else if(i%7==0)
        m[i]=4;
        else if(i%11==0)
        m[i]=5;
        else if(i%13==0)
        m[i]=6;
        else if(i%17==0)
        m[i]=7;
        else if(i%19==0)
        m[i]=8;
        else if(i%23==0)
        m[i]=9;
        else if(i%29==0)
        m[i]=10;
        else if(i%31==0)
        m[i]=11;
    }
}
int main()
{
    calculate();
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        vector<ll>ans(n,0);
        vector<ll>vis(12,0);
        for(ll i=0;i<n;i++)
        {
          cin>>a[i];
          ans[i]=m[a[i]];
        }
            k=0;
            for(ll i=0;i<n;i++)
            {
              if(!vis[ans[i]])
              vis[ans[i]]=1;
            }
            for(int i=1;i<=11;i++)
            if(vis[i])
            k++;
            cout<<k<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        if(n<=11)
        p=11;
        vector<ll>ans(n,0);
        for(ll i=0;i<n;i++)
        {
         cin>>a[i];
         if(p)
         ans[i]=i+1;
        }
        if(n<=11)
        {
            cout<<n<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        }
        else
        {
          //  cout<<11<<endl;
            k=1;
            for(ll i=0;i<n;i++)
            {
                if(!ans[i])
                {
                ans[i]=k;
                for(ll j=i+1;j<n;j++)
                {
                    if(!ans[j] && __gcd(a[i],a[j])>1)
                    ans[j]=k;
                }
            //    cout<<"k: "<<k<<"i: "<<i<<"\t";
                k++;
                }
            }
            cout<<k-1<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        if(n<=11)
        p=11;
        vector<ll>ans(n,0);
        for(ll i=0;i<n;i++)
        {
         cin>>a[i];
         if(p)
         ans[i]=i+1;
        }
        if(n<=11)
        {
            cout<<n<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        }
        else
        {
            cout<<11<<endl;
            k=1;
            for(ll i=0;i<n;i++)
            {
                if(!ans[i])
                {
                ans[i]=k;
                for(ll j=i+1;j<n;j++)
                {
                    if(!ans[j] && __gcd(a[i],a[j])>1)
                    ans[j]=k;
                }
            //    cout<<"k: "<<k<<"i: "<<i<<"\t";
                k++;
                }
            }
            cout<<k-1<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        if(n<=11)
        p=11;
        vector<ll>ans(n,0);
        for(ll i=0;i<n;i++)
        {
         cin>>a[i];
         if(p)
         ans[i]=i+1;
        }
        if(n<=11)
        {
            cout<<n<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        }
        else
        {
            cout<<11<<endl;
            k=1;
            for(ll i=0;i<n;i++)
            {
                if(!ans[i])
                {
                ans[i]=k;
                for(ll j=i+1;j<n;j++)
                {
                    if(__gcd(a[i],a[j])>1)
                    ans[j]=k;
                }
            //    cout<<"k: "<<k<<"i: "<<i<<"\t";
                k++;
                }
            }
            cout<<k-1<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        }
        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
unordered_map<int,int>m;
void calculate()
{
    for(ll i=4;i<=1000;i++)
    {
        if(i%2==0)
        m[i]=2;
        else if(i%3==0)
        m[i]=3;
        else if(i%5==0)
        m[i]=5;
        else if(i%7==0)
        m[i]=7;
        else if(i%11==0)
        m[i]=11;
        else if(i%13==0)
        m[i]=4;
        else if(i%17==0)
        m[i]=6;
        else if(i%19==0)
        m[i]=8;
        else if(i%23==0)
        m[i]=9;
        else if(i%29==0)
        m[i]=10;
        else if(i%31==0)
        m[i]=1;
    }
}
int main()
{
    calculate();
    ll t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll p=0,a[n],k;
        vector<ll>ans(n,0);
        int vis[11]={0};
        for(ll i=0;i<n;i++)
        {
          cin>>a[i];
          ans[i]=m[a[i]];
        }
            k=0;
            for(ll i=0;i<n;i++)
            {
              if(!vis[ans[i]])
              vis[ans[i]-1]=1;
            }
            for(int i=0;i<11;i++)
            if(vis[i])
            k++;
            cout<<k<<endl;
            for(ll i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
    }
}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    map<ll,ll>mp;
    mp[2] = 1;
    mp[3] = 2;
    mp[5] = 3;
    mp[7] = 4;
    mp[11] = 5;
    mp[13] = 6;
    mp[17] = 7;
    mp[19] = 8;
    mp[23] = 9;
    mp[29] = 10;
    mp[31] = 11;
 //   vector<ll>prime;
    ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        set<ll>S,notUSED;
        vector<ll>X;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            for(i = 0;i < 11;++i)
            {
                if(tmp % prime[i] == 0)
                    break;
            }

            X.pb(mp[prime[i]]);
            S.I(mp[prime[i]]);
        }
        ll val = S.size();

        cout << val << "\n";

        // for(i = 0;i  < X.size();++i)
        //     cout << X[i] << " ";
        // cout << "\n";
        for(i = 1;i <= 11;++i)
        {
           // ll tmp = i;
            for( j = 0;j < X.size();++j)
            {
                if(i == X[j])
                    break;
            }
            if(j == X.size())
                notUSED.I(i);
        }

//         for(auto it : notUSED)
//             cout << it << " ";
        for(i = 0;i < X.size();++i)
        {
            if(X[i] > S.size())
            {
                X[i] = *notUSED.begin();
                notUSED.erase(notUSED.begin());
            }
            cout << X[i] << " ";
        }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // unordered_map<ll,ll>mp;
    // mp[2] = 1;
    // mp[3] = 2;
    // mp[5] = 3;
    // mp[7] = 4;
    // mp[11] = 5;
    // mp[13] = 6;
    // mp[17] = 7;
    // mp[19] = 8;
    // mp[23] = 9;
    // mp[29] = 10;
    // mp[31] = 11;
 //   vector<ll>prime;
  //  ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        set<ll>S;
        vector<ll>notUSED;
        unordered_map<ll,ll>mp;
       vector< pair<ll,ll> >X,Y;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            ll val = smallestDivisor(tmp);
            X.pb({tmp,val});
            S.I(val);
        }
        ll val = S.size();
        i = 1;
        cout << val << "\n";
        for(auto it : S)
        {
             mp[it] = i;
             ++i;
        }

        for(i = 0;i < X.size();++i)
        {
            cout << mp[X[i].second] << " ";
        }

//         sort(Y.begin(),Y.end());

//         for(i = 1;i <= 11;++i)
//         {
//            // ll tmp = i;
//             if(binary_search(Y.begin(),Y.end(),i))
//                {

//                }
//            else
//                 notUSED.pb(i);
//         }
//         j = 0;
//          k = notUSED.size();
//         for(i = 0;i < X.size() - k;++i)
//         {
//             cout << X[i] << " ";
//         }
//          for(i = 0;i < notUSED.size();++i)
//         {
//             cout << notUSED[i] << " ";
//         }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unordered_map<ll,ll>mp;
    mp[2] = 1;
    mp[3] = 2;
    mp[5] = 3;
    mp[7] = 4;
    mp[11] = 5;
    mp[13] = 6;
    mp[17] = 7;
    mp[19] = 8;
    mp[23] = 9;
    mp[29] = 10;
    mp[31] = 11;
 //   vector<ll>prime;
  //  ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        unordered_set<ll>S;
        set<ll>notUSED;
        vector<ll>X;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            ll val = smallestDivisor(tmp);

            X.pb(mp[val]);
            S.I(mp[val]);
        }
        ll val = S.size();

        cout << val << "\n";

        for(i = 1;i <= 11;++i)
        {
           // ll tmp = i;
            for( j = 0;j < X.size();++j)
            {
                if(i == X[j])
                    break;
            }
            if(j == X.size())
                notUSED.I(i);
        }

        for(i = 0;i < X.size();++i)
        {
            if(X[i] > S.size())
            {
                X[i] = *notUSED.begin();
                notUSED.erase(notUSED.begin());
            }
            cout << X[i] << " ";
        }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    map<ll,ll>mp;
    mp[2] = 1;
    mp[3] = 2;
    mp[5] = 3;
    mp[7] = 4;
    mp[11] = 5;
    mp[13] = 6;
    mp[17] = 7;
    mp[19] = 8;
    mp[23] = 9;
    mp[29] = 10;
    mp[31] = 11;
 //   vector<ll>prime;
    ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
       ain;
        set<ll>S;
        vector<ll>X;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            for(i = 0;i < 11;++i)
            {
                if(tmp % prime[i] == 0)
                    break;
            }

            X.pb(mp[prime[i]]);
            S.I(mp[prime[i]]);
        }

        cout << S.size() << "\n";
        for(i = 0;i < X.size();++i)
            cout << X[i] << " ";
        cout << "\n";

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unordered_map<ll,ll>mp;
    mp[2] = 1;
    mp[3] = 2;
    mp[5] = 3;
    mp[7] = 4;
    mp[11] = 5;
    mp[13] = 6;
    mp[17] = 7;
    mp[19] = 8;
    mp[23] = 9;
    mp[29] = 10;
    mp[31] = 11;
 //   vector<ll>prime;
  //  ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        unordered_set<ll>S;
        set<ll>notUSED;
        vector<ll>X,Y;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            ll val = smallestDivisor(tmp);

            X.pb(mp[val]);
            Y.pb(mp[val]);
            S.I(mp[val]);
        }
        ll val = S.size();

        cout << val << "\n";

        sort(Y.begin(),Y.end());

        for(i = 1;i <= 11;++i)
        {
           // ll tmp = i;
            if(binary_search(Y.begin(),Y.end(),i))
               {

               }
           else
                notUSED.I(i);
        }

        for(i = 0;i < X.size();++i)
        {
            if(X[i] > S.size())
            {
                X[i] = *notUSED.begin();
                notUSED.erase(notUSED.begin());
            }
            cout << X[i] << " ";
        }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unordered_map<ll,ll>mp;
    mp[2] = 1;
    mp[3] = 2;
    mp[5] = 3;
    mp[7] = 4;
    mp[11] = 5;
    mp[13] = 6;
    mp[17] = 7;
    mp[19] = 8;
    mp[23] = 9;
    mp[29] = 10;
    mp[31] = 11;
 //   vector<ll>prime;
  //  ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        unordered_set<ll>S;
        vector<ll>notUSED;
        vector<ll>X,Y;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            ll val = smallestDivisor(tmp);

            X.pb(mp[val]);
            Y.pb(mp[val]);
            S.I(mp[val]);
        }
        ll val = S.size();

        cout << val << "\n";

        sort(Y.begin(),Y.end());

        for(i = 1;i <= 11;++i)
        {
           // ll tmp = i;
            if(binary_search(Y.begin(),Y.end(),i))
               {

               }
           else
                notUSED.pb(i);
        }
        j = 0;
        for(i = 0;i < X.size();++i)
        {
            if(X[i] > S.size())
            {
                X[i] = notUSED[j];
               // j++;
               // notUSED.erase(notUSED.begin());
            }
            cout << X[i] << " ";
        }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unordered_map<ll,ll>mp;
    mp[2] = 1;
    mp[3] = 2;
    mp[5] = 3;
    mp[7] = 4;
    mp[11] = 5;
    mp[13] = 6;
    mp[17] = 7;
    mp[19] = 8;
    mp[23] = 9;
    mp[29] = 10;
    mp[31] = 11;
 //   vector<ll>prime;
  //  ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        unordered_set<ll>S;
        vector<ll>notUSED;
        vector<ll>X,Y;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            ll val = smallestDivisor(tmp);

            X.pb(mp[val]);
            Y.pb(mp[val]);
            S.I(mp[val]);
        }
        ll val = S.size();
        if(val > 10)
            val = 11;

        cout << val << "\n";

        sort(Y.begin(),Y.end());

        for(i = 1;i <= 11;++i)
        {
           // ll tmp = i;
            if(binary_search(Y.begin(),Y.end(),i))
               {

               }
           else
                notUSED.pb(i);
        }
        j = 0;
         k = notUSED.size();
        for(i = 0;i < X.size() - k;++i)
        {
            cout << X[i] << " ";
        }
         for(i = 0;i < notUSED.size();++i)
        {
            cout << notUSED[i] << " ";
        }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // unordered_map<ll,ll>mp;
    // mp[2] = 1;
    // mp[3] = 2;
    // mp[5] = 3;
    // mp[7] = 4;
    // mp[11] = 5;
    // mp[13] = 6;
    // mp[17] = 7;
    // mp[19] = 8;
    // mp[23] = 9;
    // mp[29] = 10;
    // mp[31] = 11;
 //   vector<ll>prime;
  //  ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        set<ll>S;
        vector<ll>notUSED;
        unordered_map<ll,ll>mp;
       vector<ll>X,Y;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            ll val = smallestDivisor(tmp);
            X.pb(val);
            S.I(val);
        }
        ll val = S.size();
        i = 1;
        cout << val << "\n";
        for(auto it : S)
        {
             mp[it] = i;
             ++i;
        }

        for(i = 0;i < X.size();++i)
        {
            cout << mp[X[i]] << " ";
        }

//         sort(Y.begin(),Y.end());

//         for(i = 1;i <= 11;++i)
//         {
//            // ll tmp = i;
//             if(binary_search(Y.begin(),Y.end(),i))
//                {

//                }
//            else
//                 notUSED.pb(i);
//         }
//         j = 0;
//          k = notUSED.size();
//         for(i = 0;i < X.size() - k;++i)
//         {
//             cout << X[i] << " ";
//         }
//          for(i = 0;i < notUSED.size();++i)
//         {
//             cout << notUSED[i] << " ";
//         }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.
   PREFER CODING RATHER THAN MEDITATION !!!*/
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define vin ll n; cin>>n; vector<ll>x(n); for(ll i=0; i<n; i++) cin>>x[i]
#define vout for(ll i=0; i<n; i++) cout<<x[i]<<" "
#define T ll t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for( i=0; i<n; i++) cin>>a[i]
#define aout for(ll i=0; i<n; i++) cout<<a[i]<<" "
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1] ; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define matout for(ll i=0;i<m;i++){for(ll j=0;j<n;j++) cout<<a[i][j]<<" "; cout<<"\n";}
#define F first
//#define S second
#define I insert
#define sin set<ll>s; ll n; cin>>n; ll tmp; for(ll i=0;i<n;i++){cin>>tmp; s.I(tmp);}
#define sout for(auto it=s.begin();it!=s.end();++it) cout<<*it<<" "
#define AISORT sort(a,a+n)
#define ADSORT sort(a,a+n,greater<ll>())
#define VISORT sort(x.begin(),x.end())
#define VDSORT sort(x.begin(),x.end(),greater<ll>())
#define pb push_back
#define ppb pop_back

const ll maxs = 1e6+3;
const ll maxs1 = 2e3 + 3;
const ll mod = 1e9+7;
//MODULO OPEARTIONS
inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
ll fastpow(ll x,ll y)
{ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}
//MODULAR INVERSE
ll inv(ll x){ return pow(x , mod - 2);}

//ALWAYS CLEAR THEM WHEN TESTCASES ARE GIVEN
bool vis[maxs];
vector<ll>graph[maxs];
ll a[maxs];
//ll tree[maxs];

ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for (ll i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}

int main()
{
    //pre();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unordered_map<ll,ll>mp;
    mp[2] = 1;
    mp[3] = 2;
    mp[5] = 3;
    mp[7] = 4;
    mp[11] = 5;
    mp[13] = 6;
    mp[17] = 7;
    mp[19] = 8;
    mp[23] = 9;
    mp[29] = 10;
    mp[31] = 11;
 //   vector<ll>prime;
  //  ll prime[] = {2,3,5,7,11,13,17,19,23,29,31};
    T{
        ll j;
       ain;
        unordered_set<ll>S;
        vector<ll>notUSED;
        vector<ll>X,Y;
        for(ll I = 0;I < n;++I)
        {
            ll tmp = a[I];
            ll val = smallestDivisor(tmp);

            X.pb(mp[val]);
            Y.pb(mp[val]);
            S.I(mp[val]);
        }
        ll val = S.size();

        cout << val << "\n";

        sort(Y.begin(),Y.end());

        for(i = 1;i <= 11;++i)
        {
           // ll tmp = i;
            if(binary_search(Y.begin(),Y.end(),i))
               {

               }
           else
                notUSED.pb(i);
        }
        j = 0;
        for(i = 0;i < X.size();++i)
        {
            if(X[i] > S.size())
            {
                X[i] = notUSED[j];
                j++;
               // notUSED.erase(notUSED.begin());
            }
            cout << X[i] << " ";
        }

        cout << "\n";
      //  cout << notUSED.size();

    }

}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define popb pop_back
using namespace std;
ll mod=1000000007;

int main(){
	ll t;cin>>t;
    while(t--){
    	int n;cin>>n;
    	int arr[n];
    	for(int i=0;i<n;i++){
    		cin>>arr[i];
    	}
    	set<int> s;
    	int colo[n]={0};
    	int color=1;
    	int val=0;
    	while(true){
    		colo[val]=color;
    		for(int i=0;i<n;i++){
    			if(i!=val && colo[i]==0){
    				if(__gcd(arr[i],arr[val])==1){
    			   		s.insert(i);
    			    }
    			    else{
    			    	s.erase(i);
    			    	colo[i]=color;
    			  	}
    			}
    		}
    		color++;
    		if(s.size()==0)	break;
    		val=*s.begin();
    		s.erase(val);
    	}
    	for(int i=0;i<n;i++)	cout<<colo[i]<<" ";
    		cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define popb pop_back
using namespace std;
ll mod=1000000007;

int main(){
    ll t;cin>>t;
    while(t--){
    	int n;cin>>n;
    	int arr[n];
    	for(int i=0;i<n;i++)	cin>>arr[i];
    	vector<int> res(n,0);
    	int c=1;
    	int prime[11]={2,3,5,7,11,13,17,19,23,29,31};
    	int color[11]={0,0,0,0,0,0,0,0,0,0,0};
    	for(int i=0;i<n;i++){
    		for(int j=0;j<11;j++){
    			if(arr[i]%prime[j]==0 && res[i]==0){
    				if(color[j]==0)	color[j]=c++;
    				res[i]=color[j];
    				break;
    			}
    		}
    	}
    	cout<<c<<endl;
    	for(int i=0;i<n;i++)	cout<<res[i]<<" ";
    		cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define popb pop_back
using namespace std;
ll mod=1000000007;

int main(){
    ll t;cin>>t;
    while(t--){
    	int n;cin>>n;
    	int arr[n];
    	for(int i=0;i<n;i++)	cin>>arr[i];
    	vector<int> res(n,0);
    	int c=1;
    	int prime[11]={2,3,5,7,11,13,17,19,23,29,31};
    	int color[11]={0,0,0,0,0,0,0,0,0,0,0};
    	for(int i=0;i<n;i++){
    		for(int j=0;j<11;j++){
    			if(arr[i]%prime[j]==0 && res[i]==0){
    				if(color[j]==0)	color[j]=c++;
    				res[i]=color[j];
    				break;
    			}
    		}
    	}
    	c--;
    	cout<<c<<endl;
    	for(int i=0;i<n;i++)	cout<<res[i]<<" ";
    		cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define popb pop_back
using namespace std;
ll mod=1000000007;

int main(){
    ll t;cin>>t;
    while(t--){
    	int n;cin>>n;
    	int arr[n];
    	for(int i=0;i<n;i++)	cin>>arr[i];
    	vector<int> res(n,0);
    	int color=1;
    	int prime[11]={2,3,5,7,11,13,17,19,23,29,31};
    	for(int i=0;i<n;i++){
    		for(int j=0;j<11;j++){
    			if(arr[i]%prime[j]==0){
    				res[i]=j+1;
    				color=max(color,j+1);
    				break;
    			}
    		}
    	}
    	cout<<color<<endl;
    	for(int i=0;i<n;i++)	cout<<res[i]<<" ";
    		cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define popb pop_back
using namespace std;
ll mod=1000000007;
bool prime[1001];
void isprime(int n)
{
	memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int main(){
	isprime(1000);
    ll t;cin>>t;
    while(t--){
    	int n;cin>>n;
    	int arr[n];
    	for(int i=0;i<n;i++){
    		cin>>arr[i];
    	}
    	int colo[n]={0};
    	int color=1;
    	for(int i=2;i<1000;i++){
    		if(prime[i]==true){
    			for(int j=0;j<n;j++){
    				if(colo[j]==0 && arr[j]%i==0){
    					colo[j]=color;
    				}
    			}
    			color++;
    		}
    	}
    	for(int i=0;i<n;i++)	cout<<colo[i]<<" ";
    		cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define popb pop_back
using namespace std;
ll mod=1000000007;
bool prime[1001];
void isprime(int n)
{
	memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int main(){
	isprime(1000);
    ll t;cin>>t;
    while(t--){
    	int n;cin>>n;
    	int arr[n];
    	for(int i=0;i<n;i++){
    		cin>>arr[i];
    	}
    	int colo[n]={0};
    	int color=1;
    	for(int i=2;i<1000;i++){
    		if(prime[i]==true){
                int tcolor=color;
    			for(int j=0;j<n;j++){
    				if(arr[j]%i==0){
                        if(colo[j]!=0){
                            tcolor=colo[j];
                        }
                        else{
                            colo[j]=tcolor;
                        }
                    }
    			}
                if(tcolor==color)   color++;
    		}
    	}
    	for(int i=0;i<n;i++)	cout<<colo[i]<<" ";
    		cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define maxn 5000010

int main()
{
    fast;
    ll t;
    cin >> t;
    while(t--){
        ll n;
        cin >> n ;
        ll a[n];
        input(a,n);
        ll temp=1,vis[n]={0};
        fr(i,0,n){
            if(vis[i]!=0)continue;
            vis[i]=temp;
            fr(j,i+1,n){
                if(vis[j]!=0 || __gcd(a[i],a[j])==1)continue;
                vis[j]=temp;
            }
            temp++;
        }
        output(vis,n);
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define maxn 5000010

int main()
{
	fast;
	ll k;
	cin >> k;
	cout << "2 3\n";
	cout << k+(ll)pow(2,17) sp k << " 0\n";
	cout << (ll)pow(2,17) sp k+(ll)pow(2,17) sp k;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define maxn 5000010

int main()
{
    fast;
    ll t;
    cin >> t;
    while(t--){
        ll n;
        cin >> n ;
        ll a[n];
        input(a,n);
        ll temp=1,vis[n]={0},cnt=0;
        fr(i,0,n){
            if(vis[i]!=0)continue;
            vis[i]=temp;
            cnt=max(temp,cnt);
            ll g=a[i];
            fr(j,i+1,n){
                if(vis[j]!=0 || __gcd(g,a[j])==1)continue;
                g=__gcd(g,a[j]);
                //cout << i sp j sp temp << ", ";
                vis[j]=temp;
                cnt=max(temp,cnt);
            }
            temp++;
        }
        cout << cnt << endl;
        output(vis,n);
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define maxn 5000010

int main()
{
    fast;
    ll t;
    cin >> t;
    while(t--){
        ll n;
        cin >> n ;
        ll a[n];
        input(a,n);
        ll temp=1,vis[n]={0},cnt=0;
        fr(i,0,n){
            if(vis[i]!=0)continue;
            vis[i]=temp;
            cnt=max(temp,cnt);
            fr(j,i+1,n){
                if(vis[j]!=0 || __gcd(a[i],a[j])==1)continue;
                vis[j]=temp;
                cnt=max(temp,cnt);
            }
            temp++;
        }
        cout << cnt << endl;
        output(vis,n);
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define maxn 5000010

int main()
{
    fast;
    ll n=sqrt(1010)+1;
    bool vis[n]={0};
    for(ll i=2;i*i<=n;i++){
    	if(!vis[i]){
    		for(ll j=i*i;j<=n;j+=i)vis[j]=1;
    	}
    }
    vii v;
    fr(i,2,n+1)if(!vis[i])v.pb({i,0});
    ll t;
    cin >> t;
    while(t--){
    	fr(i,0,11)v[i].se=0;
    	ll n,mx=0;
    	cin >> n;
    	ll a[n],vis[n],temp=0;
    	input(a,n);
    	fr(i,0,n){
    		fr(j,0,11){
    			if(a[i]%v[j].fi==0){
    				if(v[j].se==0){
    					temp++;
    					v[j].se=temp;
    				}
    				mx=max(mx,j+1);
    				vis[i]=v[j].se;
    				break;
    			}
    		}
    	}
    	cout << temp << endl;
    	output(vis,n);
    	cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define maxn 5000010

int main()
{
    fast;
    ll n=sqrt(1010)+1;
    bool vis[n]={0};
    for(ll i=2;i*i<=n;i++){
    	if(!vis[i]){
    		for(ll j=i*i;j<=n;j+=i)vis[j]=1;
    	}
    }
    vi v;
    fr(i,2,n+1)if(!vis[i])v.pb(i);
    ll t;
    cin >> t;
    while(t--){
    	ll n,mx=0;
    	cin >> n;
    	ll a[n],vis[n];
    	input(a,n);
    	fr(i,0,n){
    		fr(j,0,11){
    			if(a[i]%v[j]==0){
    				mx=max(mx,j+1);
    				vis[i]=j+1;
    				break;
    			}
    		}
    	}
    	cout << mx << endl;
    	output(vis,n);
    	cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define maxn 5000010

int main()
{
    fast;
    ll t;
    cin >> t;
    while(t--){
        ll n;
        cin >> n ;
        ll a[n];
        input(a,n);
        ll temp=1,vis[n]={0},cnt=0;
        vii v;
        fr(i,0,n){
            ll g=0;
            fr(j,i+1,n)
                if(__gcd(a[i],a[j])==1)g++;
            v.pb(mp(g,i));
        }
        sort(all(v));
        fr(i,0,n){
            if(vis[v[i].se]!=0)continue;
            vis[v[i].se]=temp;
            ll g=a[v[i].se];
            cnt=max(cnt,temp);
            fr(j,0,n){
                if(vis[j]!=0 || __gcd(a[j],g)==1)continue;
                g=__gcd(g,a[j]);
                vis[j]=temp;
            }
            temp++;
        }
        cout << cnt << endl;
        output(vis,n);
        cout << endl;
    }
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define ll long long
using namespace std;
ll int gcd(ll int a,ll int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[1009];ll int ct=0;
        /*auto it= st.begin();
        auto ed=st.end();
        for (; it!=ed; ++it) {
            auto ak= st.begin();
            a=*it;
            //vk[ct].push_back(a);
            for (; ak!=ed; ++ak) {
                b=*ak;
                ll int g=gcd(a, b);
                if (g>1) {
                    vk[ct].push_back(b);
                }

            }
            for (i=0; i<vk[ct].size(); i++) {
                st.erase(vk[ct][i]);
            }

            ct=ct+1;
            ed=st.end();
            it= st.begin();
        }*/
        map<ll int, bool> bf;
        for (i=0; i<N; i++) {
            //if ( bf[v[i]] == false) {
                //bf[v[i]] = true;
                a=v[i];
                for (j=i; j<N; j++) {
                    b=v[j];
                    ll int g=gcd(a, b);
                    if (g>1) {
                        vk[i].push_back(b);
                        //bf[v[j]] = true;
                    }

                }
                //ct=ct+1;
           // }

        }
        map<ll int, ll int > mp;
        vector<pair<ll int, ll int>> ghj;
        for (i=0; i<N; i++) {
            ghj.push_back({vk[i].size(),i});
        }
        sort(ghj.begin(), ghj.end(), greater<>());
        for (i=0; i<11; i++) {
            if (i>=N) {
                break;
            }
            for (j=0; j<vk[ghj[i].second].size(); j++) {
                mp[ vk[ghj[i].second][j] ]=i+1;
            }
        }
        cout<<min(11, N)<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<"\t";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
using namespace std;
set<ll int > pfs;
void SieveOfEratosthenes(ll int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++){
        if (prime[p]){
            pfs.insert(p);
        }

    }

}

int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    SieveOfEratosthenes(1009);
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;ll int ma=0;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            ma=max(a, ma);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[1000];ll int ct=0;
        map<ll int, bool> bf;
        vector< pair<ll int, ll int> > tfl;
        ct=0;ll int counter=0;
        for (auto it = pfs.begin(); it!=pfs.end(); it++) {
            a=*it;bool ck=false;
            for (auto gg=st.begin(); gg!=st.end(); gg++) {
                b=*gg;
                if (b%a==0) {
                    if (bf[b]==false) {
                        vk[ct].push_back(b);
                        bf[b]=true;
                        ck=true;
                        counter= counter +1;
                    }
                }

            }
            if (a>ma) {
                break;
            }
            tfl.push_back({vk[ct].size(),ct});
            if (ck==true) {
                ct=ct+1;
            }
            if (counter==(st.size())) {
                break;
            }
        }
        map<ll int, ll int > mp;
        //sort(tfl.begin(), tfl.end(), greater<>());
        for (i=0; i<ct; i++) {
            if (i==11) {
                break;
            }
            for (j=0; j<vk[i].size(); j++) {
                mp[vk[i][j]] = i +1;
            }
        }

        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<" ";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
set<ll int > pfs;
void SieveOfEratosthenes(ll int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++){
        if (prime[p]){
            pfs.insert(p);
        }

    }

}

int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    SieveOfEratosthenes(1009);
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;ll int ma=0;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            ma=max(a, ma);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[1000];ll int ct=0;
        map<ll int, bool> bf;
        vector< pair<ll int, ll int> > tfl;
        ct=0;ll int counter=0;
        for (auto it = pfs.begin(); it!=pfs.end(); it++) {
            a=*it;bool ck=false;
            for (auto gg=st.begin(); gg!=st.end(); gg++) {
                b=*gg;
                if (b%a==0) {
                    if (bf[b]==false) {
                        vk[ct].push_back(b);
                        bf[b]=true;
                        ck=true;
                        counter= counter +1;
                    }
                }

            }
            if (a>ma) {
                break;
            }
            //tfl.push_back({vk[ct].size(),ct});
            if (ck==true) {
                ct=ct+1;
            }
            if (counter==(st.size())) {
                break;
            }
        }
        map<ll int, ll int > mp;
        //sort(tfl.begin(), tfl.end(), greater<>());
        for (i=0; i<ct; i++) {
            if (i==11) {
                break;
            }
            for (j=0; j<vk[i].size(); j++) {
                mp[vk[i][j]] = i +1;
            }
        }

        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<" ";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define ll long long
using namespace std;
ll int gcd(ll int a,ll int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[12];ll int ct=0;
        /*auto it= st.begin();
        auto ed=st.end();
        for (; it!=ed; ++it) {
            auto ak= st.begin();
            a=*it;
            //vk[ct].push_back(a);
            for (; ak!=ed; ++ak) {
                b=*ak;
                ll int g=gcd(a, b);
                if (g>1) {
                    vk[ct].push_back(b);
                }

            }
            for (i=0; i<vk[ct].size(); i++) {
                st.erase(vk[ct][i]);
            }

            ct=ct+1;
            ed=st.end();
            it= st.begin();
        }*/
        map<ll int, bool> bf;
        for (i=0; i<N; i++) {
            if ( bf[v[i]] == false) {
                bf[v[i]] = true;
                a=v[i];
                for (j=i; j<N; j++) {
                    b=v[j];
                    if ( bf[v[j]] == false) {
                        ll int g=gcd(a, b);
                        if (g>1) {
                                         vk[ct].push_back(b);
                             bf[v[j]] = true;
                                     }

                    }

                }
                ct=ct+1;
            }

        }
        map<ll int, ll int > mp;

        for (i=0; i<ct; i++) {
            for (j=0; j<vk[i].size(); j++) {
                mp[ vk[i][j] ]=i+1;
            }
        }
        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<"\t";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
using namespace std;
ll int gcd(ll int a,ll int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
set<ll int> pfs;
void primeFactors(ll int n)
{
    pfs.clear();
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        pfs.insert(2);
        n = n/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            pfs.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        pfs.insert(n);
}

int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[12];ll int ct=0;
        /*auto it= st.begin();
        auto ed=st.end();
        for (; it!=ed; ++it) {
            auto ak= st.begin();
            a=*it;
            //vk[ct].push_back(a);
            for (; ak!=ed; ++ak) {
                b=*ak;
                ll int g=gcd(a, b);
                if (g>1) {
                    vk[ct].push_back(b);
                }

            }
            for (i=0; i<vk[ct].size(); i++) {
                st.erase(vk[ct][i]);
            }

            ct=ct+1;
            ed=st.end();
            it= st.begin();
        }*/
        map<ll int, bool> bf;
        vector<pair<ll int, ll int> > trv;

        for (auto it=st.begin(); it!=st.end(); it++) {
            a=*it;
            primeFactors(a);
            trv.push_back({pfs.size(),a});

        }
        sort(trv.begin(), trv.end(), greater<>());
        ct=0;ll int counter=0;
        for (i=0; i<trv.size(); i++) {
            a=trv[i].second;

            //bf[a]=true;
            for (auto it=st.begin(); it!=st.end(); it++) {
                b=*it;
                 ll int g=gcd(a, b);
                if (g>1) {
                    if ((bf[b]==false)&&(b!=a)) {
                        vk[ct].push_back(b);
                        counter=counter+1;
                        bf[b]=true;
                    }
                }
            }
            if (vk[ct].size()>0) {
                vk[ct].push_back(a);
                if (bf[a]==false) {
                    counter=counter+1;
                }
                bf[a]=true;

                ct=ct+1;
            }else{
                if (bf[a]==true) {

                }else{
                    bf[a]=true;
                    vk[ct].push_back(a);
                    counter=counter+1;
                    ct=ct+1;
                }

            }
            if (counter == st.size()) {
                break;
            }
        }
        /*for (i=0; i<N; i++) {
            if ( bf[v[i]] == false) {
                bf[v[i]] = true;
                a=v[i];
                vk[ct].push_back(a);
                for (j=i; j<N; j++) {
                    b=v[j];
                    if ( bf[v[j]] == false) {
                        ll int g=gcd(a, b);
                        if (g>1) {
                                         vk[ct].push_back(b);
                             bf[v[j]] = true;
                                     }

                    }

                }
                ct=ct+1;
            }

        }*/
        map<ll int, ll int > mp;

        for (i=0; i<ct; i++) {
            for (j=0; j<vk[i].size(); j++) {
                mp[ vk[i][j] ]=i+1;
            }
        }
        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<"\t";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define ll long long
using namespace std;
ll int gcd(ll int a,ll int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[1009];ll int ct=0;
        /*auto it= st.begin();
        auto ed=st.end();
        for (; it!=ed; ++it) {
            auto ak= st.begin();
            a=*it;
            //vk[ct].push_back(a);
            for (; ak!=ed; ++ak) {
                b=*ak;
                ll int g=gcd(a, b);
                if (g>1) {
                    vk[ct].push_back(b);
                }

            }
            for (i=0; i<vk[ct].size(); i++) {
                st.erase(vk[ct][i]);
            }

            ct=ct+1;
            ed=st.end();
            it= st.begin();
        }*/
        map<ll int, bool> bf;
        for (i=0; i<N; i++) {
            //if ( bf[v[i]] == false) {
                //bf[v[i]] = true;
                a=v[i];
                for (j=i; j<N; j++) {
                    b=v[j];
                    ll int g=gcd(a, b);
                    if (g>1) {
                        vk[i].push_back(b);
                        //bf[v[j]] = true;
                    }

                }
                //ct=ct+1;
           // }

        }
        map<ll int, ll int > mp;
        vector<pair<ll int, ll int>> ghj;
        for (i=0; i<N; i++) {
            ghj.push_back({vk[i].size(),i});
        }
        sort(ghj.begin(), ghj.end(), greater<>());
        for (i=0; i<11; i++) {
            if (i>=N) {
                break;
            }
            for (j=0; j<vk[ghj[i].second].size(); j++) {
                mp[ vk[ghj[i].second][j] ]=i+1;
            }
        }
        a=11;
        cout<<min(N, a) <<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<"\t";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
using namespace std;
set<ll int > pfs;
void SieveOfEratosthenes(ll int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++){
        if (prime[p]){
            pfs.insert(p);
        }

    }

}

int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    SieveOfEratosthenes(1009);
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;ll int ma=0;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            ma=max(a, ma);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[1000];ll int ct=0;
        map<ll int, bool> bf;
        vector< pair<ll int, ll int> > tfl;
        ct=0;ll int counter=0;
        for (auto it = pfs.begin(); it!=pfs.end(); it++) {
            a=*it;bool ck=false;
            for (auto gg=st.begin(); gg!=st.end(); gg++) {
                b=*gg;
                if (b%a==0) {
                    if (bf[b]==false) {
                        vk[ct].push_back(b);
                        bf[b]=true;
                        ck=true;
                        counter= counter +1;
                    }
                }

            }
            if (a>ma) {
                break;
            }
            //tfl.push_back({vk[ct].size(),ct});
            if (ck==true) {
                ct=ct+1;
            }
            if (counter==(st.size())) {
                break;
            }
        }
        map<ll int, ll int > mp;
        //sort(tfl.begin(), tfl.end(), greater<>());
        for (i=0; i<ct; i++) {
            if (i==11) {
                break;
            }
            for (j=0; j<vk[i].size(); j++) {
                mp[vk[i][j]] = i +1;
            }
        }

        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<" ";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define ll long long
using namespace std;
ll int gcd(ll int a,ll int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[12];ll int ct=0;
        /*auto it= st.begin();
        auto ed=st.end();
        for (; it!=ed; ++it) {
            auto ak= st.begin();
            a=*it;
            //vk[ct].push_back(a);
            for (; ak!=ed; ++ak) {
                b=*ak;
                ll int g=gcd(a, b);
                if (g>1) {
                    vk[ct].push_back(b);
                }

            }
            for (i=0; i<vk[ct].size(); i++) {
                st.erase(vk[ct][i]);
            }

            ct=ct+1;
            ed=st.end();
            it= st.begin();
        }*/
        map<ll int, bool> bf;
        for (i=0; i<N; i++) {
            if ( bf[v[i]] == false) {
                bf[v[i]] = true;
                a=v[i];
                for (j=i; j<N; j++) {
                    b=v[j];
                    ll int g=gcd(a, b);
                    if (g>1) {
                                     vk[ct].push_back(b);
                         bf[v[j]] = true;
                                 }

                }
                ct=ct+1;
            }

        }
        map<ll int, ll int > mp;

        for (i=0; i<ct; i++) {
            for (j=0; j<vk[i].size(); j++) {
                mp[ vk[i][j] ]=i+1;
            }
        }
        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<"\t";
        }
        cout<<endl;

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
using namespace std;
ll int gcd(ll int a,ll int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
set<ll int> pfs;
void primeFactors(ll int n)
{
    pfs.clear();
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        pfs.insert(2);
        n = n/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            pfs.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        pfs.insert(n);
}

int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[12];ll int ct=0;
        /*auto it= st.begin();
        auto ed=st.end();
        for (; it!=ed; ++it) {
            auto ak= st.begin();
            a=*it;
            //vk[ct].push_back(a);
            for (; ak!=ed; ++ak) {
                b=*ak;
                ll int g=gcd(a, b);
                if (g>1) {
                    vk[ct].push_back(b);
                }

            }
            for (i=0; i<vk[ct].size(); i++) {
                st.erase(vk[ct][i]);
            }

            ct=ct+1;
            ed=st.end();
            it= st.begin();
        }*/
        map<ll int, bool> bf;
        vector<pair<ll int, ll int> > trv;

        for (auto it=st.begin(); it!=st.end(); it++) {
            a=*it;
            primeFactors(a);
            trv.push_back({pfs.size(),a});

        }
        sort(trv.begin(), trv.end(), greater<>());
        ct=0;ll int counter=0;
        for (i=0; i<trv.size(); i++) {
            a=trv[i].second;

            //bf[a]=true;
            for (auto it=st.begin(); it!=st.end(); it++) {
                b=*it;
                 ll int g=gcd(a, b);
                if (g>1) {
                    if ((bf[b]==false)&&(b!=a)) {
                        vk[ct].push_back(b);
                        counter=counter+1;
                        bf[b]=true;
                    }
                }
            }
            if (vk[ct].size()>0) {
                vk[ct].push_back(a);
                if (bf[a]==false) {
                    counter=counter+1;
                }
                bf[a]=true;

                ct=ct+1;
            }else{
                if (bf[a]==true) {

                }else{
                    bf[a]=true;
                    vk[ct].push_back(a);
                    counter=counter+1;
                    ct=ct+1;
                }

            }
            if (counter == st.size()) {
                break;
            }
        }
        /*for (i=0; i<N; i++) {
            if ( bf[v[i]] == false) {
                bf[v[i]] = true;
                a=v[i];
                vk[ct].push_back(a);
                for (j=i; j<N; j++) {
                    b=v[j];
                    if ( bf[v[j]] == false) {
                        ll int g=gcd(a, b);
                        if (g>1) {
                                         vk[ct].push_back(b);
                             bf[v[j]] = true;
                                     }

                    }

                }
                ct=ct+1;
            }

        }*/
        map<ll int, ll int > mp;

        for (i=0; i<ct; i++) {
            for (j=0; j<vk[i].size(); j++) {
                mp[ vk[i][j] ]=i+1;
            }
        }
        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<"\t";
        }
        cout<<"\n";

    }
    return 0;
}


//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 31/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
using namespace std;
ll int gcd(ll int a,ll int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
set<ll int> pfs;
void primeFactors(ll int n)
{
    pfs.clear();
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        pfs.insert(2);
        n = n/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (ll int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            pfs.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        pfs.insert(n);
}

int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,T,N=0,a,b;
    cin>>T;
    while (T--) {
        cin>>N;
        vector<ll int> v;
        set<ll int> st;
        for (i=0; i<N; i++) {
            cin>>a;
            v.push_back(a);
            st.insert(a);
        }
        //ll int mat[1000+5][1000+5]={0};
        vector<ll int> vk[12];ll int ct=0;
        /*auto it= st.begin();
        auto ed=st.end();
        for (; it!=ed; ++it) {
            auto ak= st.begin();
            a=*it;
            //vk[ct].push_back(a);
            for (; ak!=ed; ++ak) {
                b=*ak;
                ll int g=gcd(a, b);
                if (g>1) {
                    vk[ct].push_back(b);
                }

            }
            for (i=0; i<vk[ct].size(); i++) {
                st.erase(vk[ct][i]);
            }

            ct=ct+1;
            ed=st.end();
            it= st.begin();
        }*/
        map<ll int, bool> bf;
        vector<pair<ll int, ll int> > trv;

        for (auto it=st.begin(); it!=st.end(); it++) {
            a=*it;
            primeFactors(a);
            trv.push_back({pfs.size(),a});

        }
        sort(trv.begin(), trv.end(), greater<>());
        ct=0;ll int counter=0;
        for (i=0; i<trv.size(); i++) {
            a=trv[i].second;

            //bf[a]=true;
            for (auto it=st.begin(); it!=st.end(); it++) {
                b=*it;
                 ll int g=gcd(a, b);
                if (g>1) {
                    if ((bf[b]==false)&&(b!=a)) {
                        vk[ct].push_back(b);
                        counter=counter+1;
                        bf[b]=true;
                    }
                }
            }
            if (vk[ct].size()>0) {
                vk[ct].push_back(a);
                if (bf[a]==false) {
                    counter=counter+1;
                }
                bf[a]=true;

                ct=ct+1;
            }else{
                if (bf[a]==true) {

                }else{
                    bf[a]=true;
                    vk[ct].push_back(a);
                    counter=counter+1;
                    ct=ct+1;
                }

            }
            if (counter == st.size()) {
                break;
            }
        }
        /*for (i=0; i<N; i++) {
            if ( bf[v[i]] == false) {
                bf[v[i]] = true;
                a=v[i];
                vk[ct].push_back(a);
                for (j=i; j<N; j++) {
                    b=v[j];
                    if ( bf[v[j]] == false) {
                        ll int g=gcd(a, b);
                        if (g>1) {
                                         vk[ct].push_back(b);
                             bf[v[j]] = true;
                                     }

                    }

                }
                ct=ct+1;
            }

        }*/
        map<ll int, ll int > mp;

        for (i=0; i<ct; i++) {
            for (j=0; j<vk[i].size(); j++) {
                mp[ vk[i][j] ]=i+1;
            }
        }
        cout<<ct<<endl;
        for (i=0; i<N; i++) {
            cout<<mp[v[i]]<<" ";
        }
        cout<<endl;

    }
    return 0;
}


//Jatin Kumar
//jatiny17

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define print4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";
#define s(a) sort(a.begin(),a.end());
#define lli long long int
#define ulli unsigned long long int
#define dd long double
#define pi pair<lli,lli>
#define pp pair<lli,pi>
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//***************************************************//
class solution{

	public:
		solution()
		{
			;
		}

		void solve()
		{
			lli t;
			cin>>t;

			// bool prime[10001];
			lli f[1001];

			// memset(prime,true,sizeof(prime));

			// prime[0]=false;
			// prime[1]=false;

			for(lli i=1;i<=1000;i++)
				f[i]=i;

			for(lli i=4;i<=1000;i+=2)
				f[i]=2;

			for(lli i=3;i*i<=1000;i++)
			{
				if(f[i]==i)
				{
					for(lli j=i*i;j<=1000;j+=i)
					{
						if(f[j]==j)
							f[j]=i;
					}
				}
			}

			while(t--)
			{
				lli n;
				cin>>n;

				lli a[n+1];

				for(lli i=1;i<=n;i++)
					cin>>a[i];

				lli ans[n+1];

				memset(ans,0,sizeof(ans));

				map<lli,vector<lli> >mp;
				map<lli ,vector<lli> >pf;

				for(lli i=1;i<=n;i++)
				{
					lli temp=a[i];

					while(temp!=1)
					{
						mp[f[temp]].pb(i);
						pf[i].pb(f[temp]);
						temp=temp/f[temp];
					}
				}

				map<lli, vector<lli> >::iterator it;

				// for(it=pf.begin();it!=pf.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				// cout<<"\n";

				// for(it=mp.begin();it!=mp.end();it++)
				// {
				// 	cout<<it->ff<<"->";

				// 	for(lli j=0;j<it->ss.size();j++)
				// 		cout<<it->ss[j]<<" ";

				// 	cout<<"\n";
				// }

				// for(lli i=1;i<=min(n,(lli)11);i++)
				// 	ans[i]=i;

				lli ct=1;

				ans[1]=1;

				for(lli i=2;i<=n;i++)
				{
					bool c=false;

					for(lli j=0;j<pf[i].size();j++)
					{
						if(mp[pf[i][j]].size()>0)
						{
							for(lli k=0;k<mp[pf[i][j]].size();k++)
							{
								if(mp[pf[i][j]][k]<i)
								{
									ans[i]=ans[mp[pf[i][j]][k]];
									ct=max(ct,ans[i]);
									c=true;
									break;
								}
							}
						}
					}

					if(!c)
					{
						ans[i]=++ct;
					}

					if(ct==12)
						ct=1;
				}

				set<lli> st;

				for(lli i=1;i<=n;i++)
					st.insert(ans[i]);

				cout<<st.size()<<"\n";

				for(lli i=1;i<=n;i++)
					cout<<ans[i]<<" ";
				cout<<"\n";
			}

		}
};

int main()
{
    fast;

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solution s;
    s.solve();
}


//Jatin Kumar
//jatiny17

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define print4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";
#define s(a) sort(a.begin(),a.end());
#define lli long long int
#define ulli unsigned long long int
#define dd long double
#define pi pair<lli,lli>
#define pp pair<lli,pi>
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

//***************************************************//
class solution{

	public:
		solution()
		{
			;
		}

		void solve()
		{
			lli t;
			cin>>t;

			lli f[1001];

			for(lli i=1;i<=1000;i++)
				f[i]=i;

			// for(lli i=4;i<=1000;i+=2)
			// 	f[i]=2;

			for(lli i=2;i*i<=1000;i++)
			{
				if(f[i]==i)
				{
					for(lli j=2*i;j<=1000;j+=i)
					{
						f[j]=i;
					}
				}
			}

			while(t--)
			{
				lli n;
				cin>>n;

				lli a[n+1];

				lli ans[n+1];
				memset(ans,0,sizeof(ans));

				for(lli i=1;i<=n;i++)
					cin>>a[i];

				map<lli ,set<lli> > pf;

				map<lli, vector<lli> >mp;

				for(lli i=1;i<=n;i++)
				{
					lli temp=a[i];

					while(temp!=1)
					{
						pf[i].insert(f[temp]);
						mp[f[temp]].pb(i);

						temp=temp/f[temp];
					}
				}

				set<lli>::iterator it_s;

				// for(lli i=1;i<=n;i++)
				// {
				// 	cout<<i<<"->";

				// 	for(it_s=pf[i].begin();it_s!=pf[i].end();it_s++)
				// 		cout<<*it_s<<" ";
				// 	cout<<"\n";
				// }

				// cout<<"\n";

				bool visited[n+1];
				memset(visited,false,sizeof(visited));

				map<lli,vector<lli> >::iterator it;

				lli ct=1;

                it=mp.end();
                it--;

				do
				{
					// cout<<it->ff<<"->";
					bool c=false;

					for(lli j=0;j<it->ss.size();j++)
					{
						// cout<<it->ss[j]<<" ";

						if(visited[it->ss[j]]==false)
						{
							visited[it->ss[j]]=true;
							ans[it->ss[j]]=ct;
							c=true;
						}
					}

					// cout<<"\n"<<ct<<"\n";

					// for(lli i=1;i<=n;i++)
					// cout<<ans[i]<<" ";

					// cout<<"\n";
					if(c)
					ct++;

					it--;
				}while(it!=mp.begin());

				set<lli> st;

				for(lli i=1;i<=n;i++)
					st.insert(ans[i]);

				cout<<st.size()<<"\n";

				for(lli i=1;i<=n;i++)
					cout<<ans[i]<<" ";

				cout<<"\n";
			}

		}
};

int main()
{
    fast;

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    solution s;
    s.solve();
}