#include <bits/stdc++.h>
using namespace std;
const int num = 200001;
vector<int> vect[1001];
int main() {
  int n, t;
  cin >> t;
  vector<int> pn;
  int vis[1001] = {0};
  for (int i = 2; i < 1001; i++) {
    if (!vis[i]) {
      for (int j = 2 * i; j <= 1001; j += i) {
        vis[j] = 1;
        vect[j].push_back(i);
      }
    }
  }
  for (int i = 2; i < 1001; i++) {
    if (!vis[i]) pn.push_back(i);
  }
  while (t--) {
    cin >> n;
    int col[n], a[n];
    for (int i = 0; i < n; i++) cin >> a[i], col[i] = 0;
    int cur = 1;
    int cnt = 0;
    for (int i = 0; i < pn.size(); i++) {
      int flag = 0;
      for (int j = 0; j < n; j++) {
        if (a[j] % pn[i] == 0 and !col[j]) col[j] = cur, cnt++, flag = 1;
      }
      if (cnt == n) break;
      if (flag == 1) cur++;
    }
    cout << cur << "\n";
    for (int i = 0; i < n; i++) cout << col[i] << " ";
    cout << "\n";
  }
  return 0;
}
