#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long add(long long x, long long y) {
  long long res = x + y;
  return (res >= 1000000007 ? res - 1000000007 : res);
}
long long mul(long long x, long long y) {
  long long res = x * y;
  return (res >= 1000000007 ? res % 1000000007 : res);
}
long long sub(long long x, long long y) {
  long long res = x - y;
  return (res < 0 ? res + 1000000007 : res);
}
long long power(long long x, long long y) {
  long long res = 1;
  x %= 1000000007;
  while (y) {
    if (y & 1) res = mul(res, x);
    y >>= 1;
    x = mul(x, x);
  }
  return res;
}
long long mod_inv(long long x) { return power(x, 1000000007 - 2); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long ttt;
  cin >> ttt;
  vector<long long> b(1001, 0);
  vector<long long> pr;
  for (long long i = 2; i < 1001; i++) {
    if (b[i] > 0) {
      continue;
    }
    pr.push_back(i);
    for (long long j = 2 * i; j < 1001; j += i) {
      b[j] = 1;
    }
  }
  while (ttt--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = (0); i < (n); i++) cin >> (a)[i];
    ;
    vector<long long> ans(n);
    long long c = 1;
    for (auto p : pr) {
      long long f = 0, d = 0;
      for (long long i = 0; i < n; i++) {
        if (ans[i] == 0) {
          f = 1;
          if (a[i] % p == 0) {
            d++;
            ans[i] = c;
          }
        }
      }
      if (f == 0) {
        break;
      }
      if (d > 0) {
        c++;
      }
    }
    cout << *max_element(ans.begin(), ans.end()) << endl;
    for (long long i = (0); i < (n); i++) cout << (ans)[i] << " ";
    ;
    cout << endl;
  }
}
