#include <bits/stdc++.h>
#pragma GCC optimize("O3,Ofast,no-stack-protector,fast-math,unroll-loops")
using namespace std;
bool prime(long long x) {
  for (long long i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
signed main() {
  vector<bool> check(1001, false);
  for (long long i = 2; i <= 1000; i++) {
    check[i] = prime(i);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t-- > 0) {
    long long n;
    cin >> n;
    vector<long long> katya(n);
    for (long long i = 0; i < n; i++) {
      cin >> katya[i];
    }
    vector<long long> ans(n);
    long long now = 0;
    for (long long i = 2; i <= 1000; i++) {
      bool flag = false;
      for (long long x : katya) {
        if (x != 0 && x % i == 0) {
          flag = true;
        }
      }
      if (!flag) continue;
      now++;
      for (long long j = 0; j < n; j++) {
        if (katya[j] != 0 && katya[j] % i == 0) {
          katya[j] = 0;
          ans[j] = now;
        }
      }
    }
    cout << now << '\n';
    for (long long x : ans) {
      cout << x << ' ';
    }
    cout << '\n';
  }
  fflush(stdout);
  return 0;
}
