#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int smallest(int x) {
  for (int i = 2; i <= x; i++) {
    if (x % i == 0) return i;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    vector<int> ans[1010];
    cin >> n;
    vector<int> a(n + 1);
    int col[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      ans[smallest(a[i])].push_back(i);
    }
    int k = 0;
    for (int i = 1; i <= 1000; i++) {
      if (ans[i].size()) {
        k++;
        for (auto x : ans[i]) {
          col[x] = k;
        }
      }
    }
    cout << k << endl;
    for (int i = 1; i <= n; i++) {
      cout << col[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
