#include <bits/stdc++.h>
using namespace std;
template <typename Head>
void print(Head&& head) {
  cout << head << '\n';
}
template <typename Head, typename... Tail>
void print(Head&& head, Tail... tail) {
  cout << head << " ";
  print(tail...);
}
void chandan1() {
  int y = 1;
  return;
}
void chandan2() {
  for (long long int i = 0; i < 10; i++) {
    long long int x = 1;
  }
  return (chandan1());
}
long long int isprime(long long int n) {
  for (long long int i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
bool func(long long int a[], long long int n) {
  for (long long int i = 0; i < n; i++)
    if (a[i] == -1) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  chandan2();
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    ;
    long long int ans[n];
    long long int primes[12] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
    for (long long int i = 0; i < n; i++) ans[i] = -1;
    long long int color = 1;
    for (long long int i = 0; i < 12; i++) {
      long long int f = 0;
      for (long long int j = 0; j < n; j++) {
        if (a[j] % primes[i] == 0 and ans[j] == -1) {
          ans[j] = color;
          f = 1;
        }
      }
      if (f) color++;
    }
    set<long long int> st(ans, ans + n);
    print(int(st.size()));
    for (long long int i = 0; i < n; i++) cout << ans[i] << " ";
    cout << '\n';
    ;
  }
  return 0;
}
