#include <bits/stdc++.h>
using namespace std;
std::vector<int> ans[1007];
int res[1007];
int32_t main() {
  auto f = [&](int u) {
    for (int i = 2; i <= u; i++) {
      if (u % i == 0) return i;
    }
  };
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i <= 1000; i++) ans[i].clear();
    for (int i = 1; i <= n; i++) {
      int u;
      cin >> u;
      ans[f(u)].push_back(i);
    }
    int color = 0;
    for (int i = 2; i <= 1000; i++) {
      if (ans[i].size()) {
        color++;
        for (auto it : ans[i]) {
          res[it] = color;
        }
      }
    }
    cout << color << '\n';
    for (int i = 1; i <= n; i++) {
      cout << res[i] << ' ';
    }
    cout << '\n';
  }
}
