#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; ++i) cin >> a[i];
  vector<long long> prs = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  map<long long, long long> col;
  set<long long> an;
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < prs.size(); ++j) {
      if (a[i] % prs[j] == 0) {
        an.insert(j);
        break;
      }
    }
  }
  long long cnt = 1;
  for (auto el : an) {
    col[el] = cnt;
    ++cnt;
  }
  cout << an.size() << '\n';
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j < prs.size(); ++j) {
      if (a[i] % prs[j] == 0) {
        cout << col[j] << ' ';
        break;
      }
    }
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t) {
    --t;
    solve();
  }
  return 0;
}
