#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int t, n;
int a[N], p[20], cnt = 0, c[N];
map<int, int> mp;
int main() {
  ios::sync_with_stdio(false);
  ;
  cin >> t;
  for (int i = 2; i <= 50; i++) {
    int flag = 1;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        flag = 0;
        break;
      }
    }
    if (flag) p[++cnt] = i;
    if (cnt == 11) break;
  }
  while (t--) {
    mp.clear();
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      c[i] = 0;
      for (int j = 1; j <= 11; j++) {
        if (a[i] % p[j] == 0) {
          c[i] = j;
          break;
        }
      }
      if (!mp.count(c[i])) {
        mp[c[i]] = ++ans;
      }
    }
    cout << ans << "\n";
    for (int i = 0; i < n; i++) {
      cout << mp[c[i]] << " ";
    }
    cout << "\n";
  }
  return 0;
}
