#include <bits/stdc++.h>
using namespace std;
void color(vector<int> &A) {
  vector<int> prime{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  int m = 0;
  vector<int> index;
  vector<bool> flag(11, false);
  vector<int> missing;
  for (int i = 0; i < A.size(); i++) {
    for (int j = 0; j < 11; j++) {
      if (A[i] % prime[j] == 0) {
        index.push_back(j);
        if (flag[j] == false) {
          m++;
          flag[j] = true;
        }
        break;
      }
    }
  }
  for (int i = 0; i < 11; i++) {
    if (flag[i] == false) missing.push_back(i);
  }
  cout << m << endl;
  int c = 0;
  vector<int> map(11, -1);
  for (int i = 0; i < A.size(); i++) {
    if (index[i] + 1 > m) {
      if (map[index[i]] == -1) {
        map[index[i]] = missing[c];
        c++;
      }
    }
  }
  for (int i = 0; i < A.size(); i++) {
    if (index[i] + 1 <= m) {
      cout << index[i] + 1 << " ";
    } else {
      cout << map[index[i]] + 1 << " ";
    }
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int j = 0; j < n; j++) cin >> arr[j];
    color(arr);
  }
  return 0;
}
