#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int gcd(int a, int b) { return (b ? gcd(b, a % b) : a); }
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < (int)n; i++) cin >> v[i];
  vector<int> c(n, 0);
  vector<int> p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  map<int, int> m;
  for (int i = 0; i < (int)n; i++) {
    for (int j = 0; j < (int)11; j++) {
      if (v[i] % p[j] == 0) {
        m[j] = 1;
        c[i] = j;
        break;
      }
    }
  }
  int mm = 1;
  for (auto& k : m) {
    k.second = mm++;
  }
  cout << mm - 1 << '\n';
  for (int i = 0; i < (int)n; i++) cout << m[c[i]] << " \n"[i == n - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
