#include <bits/stdc++.h>
using namespace std;
void runcase() {
  map<int, int> mm;
  int n;
  cin >> n;
  int t;
  int res[n];
  int color = 1;
  int en;
  for (int i = 0; i < n; i++) {
    cin >> en;
    for (int j = 2; j <= 31; j++)
      if (en % j == 0) {
        if (mm.count(j) <= 0) mm[j] = color++;
        res[i] = mm[j];
        break;
      }
  }
  cout << (color - 1) << endl;
  for (int i = 0; i < n; i++) cout << res[i] << ' ';
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) runcase();
  return 0;
}
