#include <bits/stdc++.h>
using namespace std;
int T, n, num;
int a[1005], b[1005], p[1005];
int c[20];
bool vis[20];
int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int main() {
  cin >> T;
  c[1] = 2, c[2] = 3, c[3] = 5, c[4] = 7;
  c[5] = 11, c[6] = 13, c[7] = 17, c[8] = 19;
  c[9] = 23, c[10] = 29, c[11] = 31;
  while (T--) {
    memset(vis, 0, sizeof(vis));
    memset(b, 0, sizeof(b));
    cin >> n;
    num = 0;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= 11; ++j)
        if (a[i] % c[j] == 0) {
          b[i] = j;
          if (!vis[j]) ++num;
          vis[j] = true;
          break;
        }
    }
    cout << num << endl;
    num = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; ++i) {
      if (!vis[b[i]]) {
        vis[b[i]] = true;
        p[b[i]] = ++num;
      }
      b[i] = p[b[i]];
    }
    for (int i = 1; i <= n; ++i) cout << b[i] << ' ';
    cout << endl;
  }
  return 0;
}
