#include <bits/stdc++.h>
using namespace std;
int t, n, a[1005], c[1005], prost[1005], m;
bool b[2000];
set<int> s;
void f(int x) {
  for (int i = 0; i < m; i++) {
    if (x % prost[i] == 0) s.insert(prost[i]);
  }
}
int main() {
  b[1] = 1;
  for (int i = 2; i <= sqrt(2000); i++) {
    if (b[i] == 0) {
      int j = i * i;
      while (j <= 2000) {
        b[j] = 1;
        j += i;
      }
    }
  }
  m = 0;
  for (int i = 1; i <= 1000; i++) {
    if (b[i] == 0) prost[m++] = i;
  }
  cin >> t;
  while (t--) {
    cin >> n;
    s.clear();
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      c[i] = 0;
      f(a[i]);
    }
    int cc = 1;
    bool ch = false;
    for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
      int p = *it;
      ch = false;
      for (int i = 0; i < n; i++) {
        if (a[i] % p == 0 && c[i] == 0) {
          ch = true;
          c[i] = cc;
        }
      }
      if (ch) cc++;
    }
    cc = 0;
    for (int i = 0; i < n; i++) {
      if (c[i] > cc) cc = c[i];
    }
    cout << cc << endl;
    for (int i = 0; i < n; i++) {
      cout << c[i] << ' ';
    }
    cout << endl;
  }
  return 0;
}
