#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int primes[100];
  long long int k = 0;
  for (int i = 2; i <= 32; i++) {
    bool flag = false;
    for (int j = 2; j < i; j++) {
      if (i % j == 0) {
        flag = true;
        break;
      }
    }
    if (flag == false) {
      primes[k] = i;
      k++;
    }
  }
  long long int t;
  cin >> t;
  while (t != 0) {
    t--;
    long long int n;
    cin >> n;
    long long int a[n + 5];
    long long int box[n + 5];
    long long int p[k + 2];
    bool vis[k + 2];
    long long int rem[k + 2];
    for (int i = 0; i < k; i++) {
      p[i] = 0;
      vis[i] = false;
    }
    for (int i = 0; i < n; i++) {
      box[i] = 0;
    }
    long long int x = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      for (int j = 0; j < k; j++) {
        if (a[i] % primes[j] == 0) {
          if (vis[j] == false) {
            box[i] = x + 1;
            p[j]++;
            rem[j] = box[i];
            x++;
            vis[j] = true;
          } else {
            box[i] = rem[j];
          }
          break;
        }
      }
    }
    long long int counter = 0;
    for (int i = 0; i < k; i++) {
      if (p[i] != 0) counter++;
    }
    cout << counter << "\n";
    for (int i = 0; i < n; i++) {
      cout << box[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
