#include <bits/stdc++.h>
using namespace std;
const int MAX = 301;
const long long M = 1e10 + 11;
vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int color[1001], tab[1001];
long long mod_exp(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  if (b & 1) return ((a * mod_exp((a * a) % M, b / 2)) % M) % M;
  return mod_exp((a * a) % M, b / 2) % M;
}
void solve() {
  int n, c = 1;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tab[i];
    color[i] = 0;
  }
  bool f;
  for (int p : primes) {
    f = 0;
    for (int i = 0; i < n; ++i)
      if (tab[i] % p == 0 && color[i] == 0) {
        color[i] = c;
        f = 1;
      }
    if (f) c++;
  }
  cout << c - 1 << "\n";
  for (int i = 0; i < n; ++i) cout << color[i] << " ";
  cout << "\n";
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
