#include <bits/stdc++.h>
using namespace std;
int a[1010], sum, k, n, b[1010], c[1010];
int main() {
  int t = 0;
  for (int i = 2; i <= 1000; i++) {
    if (a[i] == 0) {
      int p = 0;
      for (int j = i + i; j <= 1000; j += i) {
        if (a[j] == 0) {
          p = 1;
          a[j] = t + p;
        }
      }
      t += p;
    }
  }
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    int p = 0;
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) {
      scanf("%d", &k);
      c[i] = a[k];
      if (b[a[k]] == 0) p++;
      b[a[k]]++;
    }
    printf("%d\n", p);
    for (int i = 0; i <= 1000; i++) {
      if (b[i] > 0) {
        b[i] = p--;
      }
    }
    for (int i = 0; i < n; i++) {
      printf("%d ", b[c[i]]);
    }
    printf("\n");
  }
  return 0;
}
