#include <bits/stdc++.h>
using namespace std;
int PRIMES[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &e : a) cin >> e;
  vector<int> ans(n, -1);
  int cnt = 0;
  int skipped = 0;
  for (int i = 0; i < 11; i++) {
    bool used = false;
    for (int j = 0; j < n; j++) {
      if (ans[j] == -1 && a[j] % PRIMES[i] == 0) {
        used = true;
        ans[j] = (i - skipped);
      }
    }
    cnt += used;
    skipped += (1 - used);
  }
  cout << cnt << '\n';
  for (auto e : ans) {
    cout << e + 1 << ' ';
  }
  cout << '\n';
}
signed main() {
  int t;
  cin >> t;
  while (t-- > 0) solve();
  return 0;
}
