#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const ll MOD = 1e9 + 7, N = 1000 + 10;
vector<ll> fact[N];
void test() {
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  for (ll i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  ll tot = 0;
  vector<ll> col(N + 1), res(N + 1);
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = 0; j < fact[a[i]].size(); j++) {
      if (col[fact[a[i]][j]]) {
        res[i] = col[fact[a[i]][j]];
        break;
      }
    }
    if (!res[i]) {
      if (col[fact[a[i]][0]]) {
        res[i] = col[fact[a[i]][0]];
      } else {
        res[i] = col[fact[a[i]][0]] = ++tot;
      }
    }
  }
  cout << *max_element(res.begin(), res.end()) << '\n';
  for (ll i = 1; i < n + 1; i++) {
    cout << res[i] << ' ';
  }
  cout << '\n';
  return;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll tt = 1;
  for (ll i = 2; i < N; i++) {
    ll x = i;
    for (ll j = 2; j * j <= x; j++) {
      if (x % j == 0) {
        fact[i].push_back(j);
        while (x % j == 0) x /= j;
      }
    }
    if (x > 2) {
      fact[i].push_back(x);
    }
  }
  for (ll i = 2; i < N; i++) {
    sort(fact[i].begin(), fact[i].end());
  }
  cin >> tt;
  for (ll i = 0; i < tt; i++) test();
  return 0;
}
