#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long gcd(long long a, long long b) {
  while (1) {
    if (a == 0) return b;
    b %= a;
    if (b == 0) return a;
    a %= b;
  }
}
vector<long long> prime;
void pri() {
  long long i, j, k;
  vector<long long> a(1000);
  for (i = 2; i < 1000; i++) {
    if (a[i] == 1) continue;
    prime.push_back(i);
    a[i] = i;
    k = i * i;
    while (k < 1000) {
      a[k] = 1;
      k += i;
    }
  }
}
int main() {
  pri();
  long long n, m, i, j, t;
  cin >> t;
  for (long long ii = 0; ii < t; ii++) {
    cin >> n;
    vector<long long> a(n), b(n), d(12), p(1007);
    j = 1;
    for (i = 0; i < n; i++) cin >> a[i];
    for (i = 0; i < n; i++) {
      long long l;
      for (l = 0; l < prime.size(); l++) {
        if (a[i] % prime[l] == 0) {
          if (p[prime[l]] != 0)
            b[i] = p[prime[l]];
          else {
            b[i] = j;
            p[prime[l]] = j;
            j++;
          }
          break;
        }
      }
    }
    cout << j - 1 << endl;
    for (i = 0; i < n; i++) cout << b[i] << " ";
    cout << endl;
  }
}
