#include <bits/stdc++.h>
using namespace std;
const long long INF64 = 1e18;
clock_t time_p = clock();
void time() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
void doc() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  long long t;
  cin >> t;
  while (t--) {
    long long j, n, i;
    cin >> n;
    long long ans[n], a[n];
    memset(ans, -1, sizeof(ans));
    vector<long long> even;
    unordered_map<long long, long long> done;
    long long haha[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (i = 0; i < n; i++) {
      for (j = 1; j <= 11; j++) {
        if (a[i] % haha[j] == 0) {
          done[i] = j;
        }
      }
    }
    set<long long> s;
    for (auto it : done) {
      s.insert(it.second);
    }
    long long zz = s.size();
    unordered_map<long long, long long> hihi;
    for (long long it : s) {
      hihi[(it)] = zz--;
    }
    cout << s.size() << '\n';
    for (i = 0; i < n; i++) {
      cout << hihi[done[i]] << ' ';
    }
    cout << '\n';
  }
}
