#include <bits/stdc++.h>
using namespace std;
inline void chkmax(int &a, int b) {
  if (a < b) a = b;
}
inline void chkmin(int &a, int b) {
  if (a > b) a = b;
}
inline int read() {
  int a = 0, fh = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    a = a * 10 + c - 48;
    c = getchar();
  }
  return a * fh;
}
int T, n, m;
char ch[200005];
int a[200005], c[200005];
const int p[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int vis[15];
int main() {
  T = read();
  while (T--) {
    n = read();
    for (int j = 0; j < 11; ++j) vis[j] = 0;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      a[i] = read();
      for (int j = 0; j < 11; ++j) {
        if (a[i] % p[j] == 0) {
          if (!vis[j]) vis[j] = ++cnt;
          c[i] = vis[j];
          break;
        }
      }
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= n; ++i) printf("%d ", c[i]);
    puts("");
  }
  return 0;
}
