#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int gcd(int m, int n) {
  if (n == 0) return m;
  return gcd(n, m % n);
}
int main() {
  int a[maxn];
  int ans[maxn] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 11; j++) {
        if (a[i] % ans[j] == 0) {
          a[i] = j;
          break;
        }
      }
    }
    int vis[12] = {0};
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (vis[a[i]] == 0) {
        vis[a[i]] = ++cnt;
        a[i] = vis[a[i]];
      } else {
        a[i] = vis[a[i]];
      }
    }
    printf("%d\n", cnt);
    for (int i = 0; i < n; i++) {
      printf("%d ", a[i]);
    }
    printf("\n");
  }
  return 0;
}
