#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 100;
int a[maxn], ans[maxn];
int prime[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int used[12], sub[12];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    memset(used, 0, sizeof(used));
    memset(sub, 0, sizeof(sub));
    for (int i = 1; i <= n; i++) {
      a[i] = i;
      cin >> a[i];
      for (int j = 1; j <= 11; j++) {
        if (a[i] % prime[j] == 0) {
          ans[i] = j;
          used[j] = 1;
          break;
        }
      }
    }
    for (int i = 1; i <= 11; i++) {
      sub[i] = sub[i - 1];
      if (used[i] == 0) sub[i]++;
    }
    cout << 11 - sub[11] << '\n';
    for (int i = 1; i <= n; i++) cout << ans[i] - sub[ans[i]] << ' ';
    cout << '\n';
  }
}
