#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 7;
int x[12] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
const long long N = 1e6 + 50;
long long a[N];
bool prime[N];
void seive() {
  for (int i = 2; i <= N; i++) prime[i] = 1;
  for (int i = 2; i <= N; i++)
    for (int j = 2; j * i <= N; j++) prime[j * i] = 0;
  for (long long i = 2; i <= N; i++) a[i] = a[i - 1] + prime[i];
}
bool sortf(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long int r, e, t, y, z, d, n, i, xx, j, k, l, m, h = 0, u, p;
  cin >> t;
  while (t--) {
    int a[maxn] = {};
    int b[maxn] = {};
    int n;
    cin >> n;
    int cnt = 0;
    int c[12] = {};
    for (i = 1; i <= n; i++) {
      cin >> a[i];
      int flag = 0;
      for (j = 1; j <= cnt; j++) {
        if (a[i] % c[j] == 0) {
          b[i] = j;
          flag = 1;
          break;
        }
      }
      if (!flag) {
        for (j = 1; j <= 11; j++) {
          if (a[i] % x[j] == 0) {
            c[++cnt] = x[j];
            b[i] = cnt;
            break;
          }
        }
      }
    }
    cout << cnt << "\n";
    for (i = 1; i <= n; i++) cout << b[i] << " ";
    cout << endl;
  }
}
