#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
constexpr int MOD = 1000000007;
const int INF = 1 << 30;
bool is_prime(int n) {
  if (n <= 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
vec get_primes() {
  vec p;
  for (int i = 2; i <= 1000; i++) {
    if (is_prime(i)) p.push_back(i);
  }
  return p;
}
int main() {
  int t;
  cin >> t;
  for (int _ = 0; _ < (int)(t); _++) {
    int n;
    cin >> n;
    vec a(n);
    for (int i = 0; i < (int)(n); i++) cin >> a[i];
    auto p = get_primes();
    vec c(n, -1);
    int now = 1;
    for (auto&& pm : p) {
      bool f = false;
      for (int i = 0; i < (int)(n); i++) {
        if (c[i] == -1) {
          if (a[i] % pm == 0) c[i] = now, f = true;
        }
      }
      if (f) now++;
    }
    int mx = -1;
    for (int i = 0; i < (int)(n); i++) mx = max(mx, c[i]);
    cout << mx << "\n";
    for (int i = 0; i < (int)(n); i++) {
      if (i != 0) cout << " ";
      cout << c[i];
    }
    cout << "\n";
  }
  return 0;
}
