#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
using namespace std;
void solve();
signed main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();
  return 0;
}
const long long MOD = 1e9 + 7, MAXN = 3e5 + 10, INF = 1e18 + 10;
void query() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<vector<long long>> b(n);
  for (long long i = 0; i < n; ++i) {
    long long first = a[i];
    long long d = 2;
    while (d * d <= first) {
      if (first % d == 0) {
        b[i].push_back(d);
        first /= d;
      } else {
        d++;
      }
    }
    if (first > 1) {
      b[i].push_back(first);
    }
    sort(b[i].begin(), b[i].end());
  }
  long long T = 1;
  vector<long long> cl(n);
  map<long long, vector<long long>> mp;
  for (long long i = 0; i < n; ++i) {
    mp[b[i][0]].push_back(i);
  }
  for (auto it : mp) {
    for (long long el : it.second) {
      cl[el] = T;
    }
    T++;
  }
  cout << T - 1 << '\n';
  for (long long i = 0; i < n; ++i) {
    cout << cl[i] << " ";
  }
  cout << '\n';
}
void solve() {
  long long t;
  cin >> t;
  for (long long i = 0; i < t; ++i) {
    query();
  }
}
