#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int maxn = 1e3 + 25;
const int O = 1e5;
const double PI = acos(-1.0);
const double E = 2.718281828459;
const double eps = 1e-6;
int _g(int a, int b) { return a % b == 0 ? b : _g(b, a % b); }
int pri[maxn], l = 0, f[maxn];
void init() {
  for (int i = 2; i < maxn; i++) {
    if (!f[i]) pri[l++] = i;
    for (int j = 0; j < l && i * pri[j] < maxn; j++) {
      f[i * pri[j]] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
int main() {
  int T;
  cin >> T;
  init();
  while (T--) {
    int n;
    scanf("%d", &n);
    int col[maxn];
    memset(col, 0, sizeof(col));
    int cnt = 0;
    int a[maxn];
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int i = 0; i < l; i++) {
      int f = 0;
      for (int j = 0; j < n; j++) {
        if (col[j]) continue;
        if (a[j] % pri[i] == 0) {
          if (f)
            col[j] = cnt;
          else {
            col[j] = ++cnt;
            f = 1;
          }
        }
      }
    }
    printf("%d\n", cnt);
    for (int i = 0; i < n; i++) printf("%d ", col[i]);
    printf("\n");
  }
  return 0;
}
