#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const double EPS = 1e-12;
int a[1010], col[1010], Div[14] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
bool used[16];
int Map[14];
int main() {
  int T = 1;
  cin >> T;
  while (T--) {
    int n, cnt = 0;
    scanf("%d", &n);
    for (int i = 0; i <= 14; i++) used[i] = false;
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= 11; j++) {
        if (a[i] % Div[j] == 0) {
          if (!used[j]) {
            used[j] = true;
            cnt++;
            Map[j] = cnt;
          }
          col[i] = j;
          break;
        }
      }
    }
    printf("%d\n%d", cnt, Map[col[0]]);
    for (int i = 1; i < n; i++) printf(" %d", Map[col[i]]);
    cout << '\n';
  }
}
