#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 20;
const long long inf = 1e16;
long long powm(long long x, long long y, long long m = 1000000007) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long modinv(long long a, long long m = 1000000007) {
  return powm(a, m - 2, m);
}
void mkr() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
}
int32_t main() {
  mkr();
  long long t;
  cin >> t;
  while (t--) {
    long long prime[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    long long n;
    cin >> n;
    vector<long long> v;
    v.resize(n);
    for (long long i = 0; i < n; i++) cin >> v[i];
    ;
    map<long long, long long> mpp;
    long long k = 0;
    vector<bool> bul(11, 0);
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j <= 10; j++) {
        if (!(v[i] % prime[j])) {
          if (bul[j] == 1) {
            v[i] = mpp[j];
            break;
          } else {
            k++;
            v[i] = k;
            mpp[j] = k;
            bul[j] = 1;
            break;
          }
        }
      }
    }
    cout << mpp.size();
    cout << "\n";
    for (long long i = 0; i < n; i++) {
      cout << v[i] << " ";
    }
    cout << "\n";
    ;
  }
}
