#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int list[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  while (t--) {
    int n;
    cin >> n;
    int a[n], x[11] = {0}, colornum = 1;
    map<int, int> colors;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 11; j++) {
        if (a[i] % list[j] == 0) {
          a[i] = list[j];
          if (x[j] == 0) {
            x[j] = 1;
            colors[list[j]] = colornum++;
          }
          a[i] = list[j];
          break;
        }
      }
    }
    cout << colornum - 1 << endl;
    for (int i = 0; i < n; i++) {
      cout << colors[a[i]] << " ";
    }
    cout << endl;
  }
  return 0;
}
