#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j, n, arr[1001] = {0}, cnt,
                  str[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}, flag,
                  cnt1, arr1[1001] = {0}, k, flag1;
  cin >> t;
  while (t--) {
    memset(arr1, 0, sizeof(arr1));
    cnt = cnt1 = 0;
    k = 1;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> arr[i];
    }
    for (i = 0; i < 12; i++) {
      flag1 = 0;
      for (j = 0; j < n; j++) {
        if (arr[j] % str[i] == 0 && arr1[j] == 0) {
          arr1[j] = k;
          cnt1++;
          flag1 = 1;
        }
      }
      if (flag1 == 1) k++;
      if (cnt1 == n) {
        cnt = k - 1;
        break;
      }
    }
    cout << cnt << endl;
    for (i = 0; i < n; i++) {
      cout << arr1[i] << " ";
    }
    cout << endl;
  }
}
