#include <bits/stdc++.h>
using namespace std;
bool fun(long long x, long long y) {
  for (long long i = 2; i <= min(x, y); i++) {
    if (x % i == 0 && y % i == 0) return 1;
  }
  return 0;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; ++i) {
      cin >> a[i];
    }
    vector<long long> ans(n, 0);
    map<long long, long long> make_pair, m;
    for (long long i = 0; i < n; i++) {
      for (long long j = 2; j <= sqrt(a[i]); j++) {
        if (a[i] % j == 0) {
          if (m.find(j) != m.end()) {
            ans[i] = m[j];
          } else {
            long long s = m.size();
            m[j] = s + 1;
            ans[i] = m[j];
          }
          make_pair[a[i]] = j;
          break;
        }
      }
    }
    cout << m.size() << endl;
    for (long long i = 0; i < n; i++) cout << ans[i] << " ";
    cout << '\n';
  }
  return 0;
}
