#include <bits/stdc++.h>
using namespace std;
int idx[1003], mp[1003], res[1003], cnt;
int main() {
  for (int i = 2; i <= 1000; i++) {
    if (mp[i]) continue;
    int flag = ++cnt;
    for (int j = i; j <= 1000; j += i) {
      if (mp[j]) continue;
      mp[j] = flag;
    }
  }
  int tc;
  cin >> tc;
  while (tc--) {
    memset(idx, 0, sizeof idx);
    memset(res, 0, sizeof res);
    vector<int> v;
    int n, pt = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      int col = mp[x];
      if (!idx[col]) {
        idx[col] = ++pt;
      }
      res[i] = idx[col];
    }
    cout << pt << endl;
    for (int i = 1; i <= n; i++) {
      cout << res[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
