#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> ans(0);
    vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    set<int> s;
    map<int, int> mp;
    int j = 1;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      for (int x : primes) {
        if (v[i] % x == 0) {
          ans.push_back(x);
          if (!s.count(x)) mp[x] = j++, s.insert(x);
          break;
        }
      }
    }
    cout << s.size() << '\n';
    for (int x : ans) cout << mp[x] << ' ';
    cout << '\n';
  }
}
