#include <bits/stdc++.h>
using namespace std;
inline void print(vector<long long int>& a) {
  for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
  cout << "\n";
}
inline void inp(vector<long long int>& a) {
  for (int i = 0; i < a.size(); i++) {
    cin >> a[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long int> a(n);
    inp(a);
    vector<long long int> c(n, 0);
    int cnt = 0;
    vector<int> p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    vector<vector<int> > m(11);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 11; j++) {
        if (a[i] % p[j] == 0) {
          m[j].push_back(i);
          break;
        }
      }
    }
    for (int i = 0; i < 11; i++) {
      if (m[i].size() > 0) cnt++;
      for (int j = 0; j < m[i].size(); j++) {
        c[m[i][j]] = cnt;
      }
    }
    cout << cnt << "\n";
    print(c);
  }
  return 0;
}
