#include <bits/stdc++.h>
void rd(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
void lrd(long long &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
const int INF = 1e9;
const long long LINF = 1e18;
const int N = 1e3 + 10;
using namespace std;
int T;
int n, a[N], col[N];
int p[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
vector<int> S[11];
bool tag[N];
int main() {
  rd(T);
  while (T--) {
    rd(n);
    for (int i = 1; i <= n; i++) rd(a[i]), tag[i] = 0;
    for (int i = 0; i < 11; i++) S[i].clear();
    for (int i = 0; i < 11; i++) {
      for (int j = 1; j <= n; j++) {
        if (tag[j] || a[j] % p[i]) continue;
        S[i].push_back(j);
        tag[j] = 1;
      }
    }
    int now = 0;
    for (int i = 0; i < 11; i++) {
      if (!S[i].size()) continue;
      now++;
      for (int j = 0; j < S[i].size(); j++) col[S[i][j]] = now;
    }
    printf("%d\n", now);
    for (int i = 1; i <= n; i++) printf("%d ", col[i]);
    puts("");
  }
  return 0;
}
