#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int clr[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    long long int input[1004];
    long long int answer[1004];
    long long int prime_factors[35] = {0};
    long long int av[35] = {0};
    long long int n;
    cin >> n;
    long long int m = 1;
    for (long long int i = 0; i < n; ++i) {
      cin >> input[i];
    }
    for (long long int i = 0; i < n; ++i) {
      long long int num;
      for (long long int j = 0; j < 35; ++j) {
        prime_factors[j] = 0;
      }
      for (long long int j = 0; j < 11; ++j) {
        if ((input[i] % clr[j]) == 0) {
          num = clr[j];
          prime_factors[clr[j]] = 1;
          break;
        }
      }
      for (long long int j = 0; j < 35; ++j) {
        if (prime_factors[j] == 1) {
          if (av[j] == 0) {
            av[j] = m;
            m++;
          }
          break;
        }
      }
      answer[i] = av[num];
    }
    cout << m - 1 << endl;
    for (long long int i = 0; i < n; ++i) cout << answer[i] << " ";
    cout << endl;
  }
  return 0;
}
