#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int ps[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  while (t--) {
    int n;
    cin >> n;
    vector<int> c(n);
    vector<int> cc(11);
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      for (int j = 0; j < 11; j++) {
        if (a % ps[j] == 0) {
          cc[j]++;
          c[i] = j;
          break;
        }
      }
    }
    int m = 0;
    vector<int> mps(11);
    for (int j = 0; j < 11; j++) {
      if (cc[j]) {
        mps[j] = ++m;
      }
    }
    cout << m << endl;
    for (int i = 0; i < n; i++) {
      cout << mps[c[i]] << " ";
    }
    cout << endl;
  }
}
