#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n][2];
    for (int i = 0; i < n; i++) {
      cin >> arr[i][0];
      arr[i][1] = -1;
    }
    int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    int count = 0, i, cnt = 0;
    int k = 1;
    for (i = 0; i < 11; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        if (arr[j][0] % prime[i] == 0 && arr[j][1] == -1) {
          arr[j][1] = k;
          count++;
          cnt++;
        }
      }
      if (cnt != 0) k++;
      if (count == n) break;
    }
    cout << k - 1 << endl;
    for (int j = 0; j < n; j++) cout << arr[j][1] << " ";
    cout << endl;
  }
}
