#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a[1005] = {0};
  int k = 0;
  for (int i = 2; i <= 1000; i++) {
    if (a[i] == 0) {
      k++;
      a[i] = k;
      for (int j = i * i; j <= 1000; j += i) a[j] = k;
    }
  }
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int b[n], c[n];
    int k = 0;
    unordered_map<int, int> m;
    for (int i = 0; i < n; i++) {
      cin >> b[i];
      if (m[a[b[i]]] == 0) {
        k++;
        m[a[b[i]]] = k;
        c[i] = m[a[b[i]]];
      } else
        c[i] = m[a[b[i]]];
    }
    cout << m.size() << "\n";
    for (int i = 0; i < n; i++) cout << c[i] << " ";
    cout << "\n";
  }
}
