#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  vector<long long> primes{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  long long t;
  cin >> t;
  while (t--) {
    long long n, i, j, c = 0, c1 = 0, flag = 0;
    cin >> n;
    vector<long long> v(n), v1(n, 0);
    for (i = 0; i < n; i++) cin >> v[i];
    for (i = 0; i < 11; i++) {
      flag = 0;
      if (c1 == n) break;
      for (j = 0; j < n; j++) {
        if (v1[j] == 0 && v[j] % primes[i] == 0) {
          flag = 1;
          c1++;
          v1[j] = c + 1;
        }
      }
      if (flag == 1) c++;
    }
    cout << c << "\n";
    for (auto i : v1) cout << i << " ";
    cout << "\n";
  }
}
