#include <bits/stdc++.h>
std::mt19937_64 rng(
    std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long b[n];
    long long count = 1;
    map<long long, long long> m;
    for (long long i = 2; i <= 1000; i++) {
      long long flag = 0;
      for (long long j = 0; j < n; j++) {
        if (m.find(a[j]) == m.end() && a[j] % i == 0) {
          flag = 1;
          m[a[j]] = count;
        }
      }
      if (flag == 1) count++;
    }
    cout << count - 1 << "\n";
    for (long long i = 0; i < n; i++) {
      cout << m[a[i]] << " ";
    }
    cout << "\n";
  }
  return 0;
}
