#include <bits/stdc++.h>
using namespace std;
int t, a[1010], p[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
struct st {
  int x;
  int y;
  int idx;
};
st ans[1010];
bool cmp1(st p, st q) { return p.x < q.x; }
bool cmp2(st p, st q) { return p.idx < q.idx; }
int main() {
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%d", a + i);
      for (int j = 0; j < 11; j++) {
        if (a[i] % p[j] == 0) {
          ans[i] = {j + 1, 0, i};
          break;
        }
      }
    }
    sort(ans, ans + n, cmp1);
    ans[0].y = 1;
    for (int i = 1; i < n; i++) {
      if (ans[i].x == ans[i - 1].x) {
        ans[i].y = ans[i - 1].y;
      } else {
        ans[i].y = ans[i - 1].y + 1;
      }
    }
    printf("%d\n", ans[n - 1].y);
    sort(ans, ans + n, cmp2);
    for (int i = 0; i < n; i++) {
      printf("%d ", ans[i].y);
    }
    printf("\n");
  }
}
