#include <bits/stdc++.h>
using namespace std;
const long long BIG = 1000000000000000000LL;
void solve();
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
void solve() {
  vector<long long> dd{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  long long tt;
  cin >> tt;
  while (tt--) {
    long long n;
    cin >> n;
    vector<long long> col(11, -1);
    long long nbCol = 0;
    vector<long long> a(n);
    for (long long i = (0); i < (n); ++i) cin >> a[i];
    for (long long iElem = (0); iElem < (n); ++iElem) {
      for (long long iDiv = (0); iDiv < (11); ++iDiv) {
        if (dd[iDiv] <= a[iElem] && a[iElem] % dd[iDiv] == 0) {
          a[iElem] = iDiv;
          if (col[iDiv] == -1) col[iDiv] = ++nbCol;
        }
      }
    }
    cout << nbCol << "\n";
    for (long long x : a) cout << col[x] << " ";
    cout << "\n";
  }
}
