#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  while (t--) {
    int n;
    cin >> n;
    int array[n];
    for (auto &i : array) cin >> i;
    int sol[n];
    for (int i = 0; i < n; i++) sol[i] = -1;
    int colour = 1;
    for (int p : prime) {
      bool check = false;
      for (int j = 0; j < n; j++) {
        if (sol[j] != -1) continue;
        if (array[j] % p) continue;
        check = true;
        sol[j] = colour;
      }
      if (check) colour++;
    }
    cout << colour - 1 << "\n";
    for (auto i : sol) cout << i << " ";
    cout << endl;
  }
}
