#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const long long inf = 1e9;
const int N = 2e3 + 5;
const int M = 2e6 + 5;
const int mod = 998244353;
int n, m, k, t, T, len, x, y, z;
int a[N], vis[N];
void solve() {
  scanf("%d", &n);
  vector<int> v[N];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    for (int j = 2; j <= x; j++) {
      if (x % j == 0) {
        v[j].push_back(i);
        break;
      }
    }
  }
  y = x = 0;
  for (int i = 2; i <= 997; i++) {
    if (((int)(v[i]).size()) == 0) continue;
    x++;
    y += ((int)(v[i]).size());
    for (int j = 0; j < ((int)(v[i]).size()); j++) {
      a[v[i][j]] = x;
    }
    if (y == n) break;
  }
  printf("%d\n", x);
  for (int i = 1; i <= n; i++) printf("%d%s", a[i], i == n ? "\n" : " ");
}
int main() {
  int o;
  scanf("%d", &o);
  while (o--) {
    solve();
  }
  return 0;
}
