#include <bits/stdc++.h>
using namespace std;
const int pr[12] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int answer[1000 + 1];
int nen(int len) {
  pair<long long, long long> save[len + 1];
  for (int i = 1; i <= len; i++)
    save[i] = pair<long long, long long>(answer[i], i);
  sort(save + 1, save + 1 + len);
  int num = 0;
  for (int i = 1; i <= len; i++) {
    if (i == 1 || save[i].first != save[i - 1].first) num++;
    answer[save[i].second] = num;
  }
  return num;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int iiii = 0; iiii < t; iiii++) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      int num;
      cin >> num;
      for (int color = 1; color < 12; color++) {
        if (num % pr[color]) continue;
        answer[i] = color;
        break;
      }
    }
    cout << nen(n) << '\n';
    for (int i = 1; i <= n; i++) cout << answer[i] << ' ';
    cout << '\n';
    memset(answer, 0, sizeof(answer));
  }
}
