#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long double pi = acos(-1);
const long long maxn = 3e5 + 5;
const int mod = 998244353;
const long long INF = 1e18;
const int MX = 2000000001;
vector<long long> lps(maxn, 0);
void KMP(string second) {
  long long l = 0, r = 1;
  while (r < second.size()) {
    if (second[l] == second[r]) {
      lps[r++] = ++l;
    } else {
      l = 0;
      lps[r++] = 0;
    }
  }
  for (long long i = 0; i < ((long long)(second).size()); i++)
    cout << lps[i] << " ";
}
void find_sub(string second, string t) {
  long long i = 0, j = 0, ans = 0;
  bool ch = false;
  while (i < second.size()) {
    if (second[i] == t[j]) {
      j++;
      i++;
      if (j == t.size()) {
        ans++;
        cout << "Substring found at " << i - j << " index"
             << "\n";
        j = lps[j - 1];
        ch = true;
      }
    } else {
      if (j)
        j = lps[j - 1];
      else
        i++;
    }
  }
  if (!ch) cout << "Substring not found\n";
  cout << "NUMBER OD OCC" << ans << "\n";
}
long long max_gold_mine() {
  long long v[3][1] = {{1}, {2}, {3}};
  long long m = 3, n = 1;
  long long ans = 0;
  for (int j = n - 2; j >= 0; j--) {
    for (int i = 0; i < m; i++) {
      if (!i)
        v[i][j] += max(v[i][j + 1], v[i + 1][j + 1]);
      else if (i == m - 1)
        v[i][j] += max(v[i][j + 1], v[i - 1][j + 1]);
      else
        v[i][j] += max({v[i + 1][j + 1], v[i - 1][j + 1], v[i][j + 1]});
    }
  }
  for (int i = 0; i < m; i++) ans = max(ans, v[i][0]);
  return ans;
}
int optimal_merge(vector<int> v) {
  int ans = 0;
  priority_queue<int, vector<int>, greater<int>> pq;
  for (auto x : v) pq.push(x);
  while (pq.size() != 1) {
    int a = pq.top();
    pq.pop();
    int b = pq.top();
    pq.pop();
    ans += a + b;
    pq.push(a + b);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long t, q, n, a, b, c, d, k, l, m, r, x = 0, y = 0, z = 0, sum = 0,
                                             ans = 0, temp = 0, res = 0;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long> v(n), vis(n, 0);
    vector<long long> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
    for (auto &x : v) cin >> x;
    map<long long, long long> ma;
    for (long long i = 0; i < (n); i++) {
      for (long long j = 0; j < (11); j++) {
        if (v[i] % prime[j] == 0) {
          ma[j] = 1;
          vis[i] = j;
          break;
        }
      }
    }
    cout << (long long)(ma).size() << "\n";
    ans = 0;
    for (auto &x : ma) x.second = ++ans;
    for (long long i = 0; i < (n); i++) {
      cout << ma[vis[i]] << " ";
      if (i == n - 1) cout << "\n";
    }
  }
}
