#include <bits/stdc++.h>
using namespace std;
vector<int> p;
int chk[10005], color[1005], arr[1005];
int main() {
  for (int i = 2; i <= 10000; i++) {
    if (chk[i]) continue;
    p.push_back(i);
    for (int j = 2; i * j <= 10000; j++) chk[i * j] = 1;
  }
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
    fill(color, color + 1005, 0);
    int ans = 1;
    for (int i = 0; i < p.size(); i++) {
      int k = p[i], cnt = 0;
      for (int j = 0; j < n; j++) {
        if (!color[j] && arr[j] % k == 0) {
          color[j] = ans;
          cnt++;
        }
      }
      if (cnt) ans++;
    }
    cout << ans - 1 << '\n';
    for (int i = 0; i < n; i++) {
      printf("%d ", color[i]);
    }
    cout << '\n';
  }
}
