#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long powmod(long long x, long long y) {
  long long t;
  for (t = 1; y; y >>= 1, x = x * x % mod)
    if (y & 1) t = t * x % mod;
  return t;
}
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
long long lcm(long long x, long long y) { return x * (y / gcd(x, y)); }
void smask(int pos, int &i) { i = i ^ (1 << pos); }
void clmask(int pos, int &i) { i = i & ~(1 << pos); }
bool chmask(int pos, int i) { return i & (1 << pos); }
double cordist(pair<double, double> a, pair<double, double> b) {
  return sqrt(((a.first - b.first) * (a.first - b.first)) +
              ((a.second - b.second) * (a.second - b.second)));
}
long long n, m, q, r;
int primes[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
void solve() {
  cin >> n;
  long long arr[n];
  long long brr[n];
  unordered_map<int, int> mp;
  int k = 1;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    for (int j = 0; j < 11; j++) {
      if (arr[i] % primes[j] == 0) {
        if (mp.count(primes[j]) == 0) {
          brr[i] = k;
          mp[primes[j]] = k++;
        } else {
          brr[i] = mp[primes[j]];
        }
        break;
      }
    }
  }
  cout << k - 1 << endl;
  for (int i = 0; i < n; i++) cout << brr[i] << " ";
  cout << endl;
}
int main() {
  int k = 1;
  cin >> k;
  while (k--) {
    solve();
  }
  return 0;
}
