#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
double pi = 3.1415926536;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  cin >> tt;
  while (tt--) {
    long long n, x = 0, m = 0, y = 0, d = 1, k = mod;
    cin >> n;
    long long a[n], b[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long f[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    set<long long> se;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < 11; j++) {
        if (a[i] % f[j] == 0) {
          b[i] = j + 1;
          se.insert(b[i]);
          break;
        }
      }
    }
    m = se.size();
    cout << m << '\n';
    long long t[11] = {};
    for (long long i = 0; i < n; i++) {
      t[b[i] - 1] = 1;
    }
    map<long long, long long> mp;
    d = 1;
    for (long long i = 0; i < 11; i++) {
      if (t[i] == 1) mp[i + 1] = d++;
    }
    for (long long i = 0; i < n; i++) {
      b[i] = mp[b[i]];
      cout << b[i] << " ";
    }
    cout << '\n';
  }
}
