#include <bits/stdc++.h>
using namespace std;
long long int powMod(long long int x, long long int y) {
  long long int p = 1;
  while (y) {
    if (y % 2) {
      p = (p * x) % 1000000007;
    }
    y /= 2;
    x = (x * x) % 1000000007;
  }
  return p;
}
long long int invMod(long long int x) { return powMod(x, 1000000007 - 2); }
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int fib(long long int n) {
  long long int a = 1;
  long long int b = 1;
  long long int c = 1;
  for (long long int i = 0; i < n - 1; i++) {
    c = (a + b) % 1000000007;
    a = b;
    b = c;
  }
  return c;
}
void solve() {
  long long int t;
  cin >> t;
  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];
    vector<long long int> v[11];
    for (long long int i = 0; i < n; i++) {
      if (a[i] % 2 == 0) {
        v[0].push_back(i);
      } else if (a[i] % 3 == 0) {
        v[1].push_back(i);
      } else if (a[i] % 5 == 0) {
        v[2].push_back(i);
      } else if (a[i] % 7 == 0) {
        v[3].push_back(i);
      } else if (a[i] % 11 == 0) {
        v[4].push_back(i);
      } else if (a[i] % 13 == 0) {
        v[5].push_back(i);
      } else if (a[i] % 17 == 0) {
        v[6].push_back(i);
      } else if (a[i] % 19 == 0) {
        v[7].push_back(i);
      } else if (a[i] % 23 == 0) {
        v[8].push_back(i);
      } else if (a[i] % 29 == 0) {
        v[9].push_back(i);
      } else if (a[i] % 31 == 0) {
        v[10].push_back(i);
      }
    }
    long long int cnt = 0;
    for (long long int i = 0; i < 11; i++) {
      if ((long long int)v[i].size() > 0) cnt++;
    }
    long long int ans[n];
    long long int x = 1;
    for (long long int i = 0; i < 11; i++) {
      if ((long long int)v[i].size() > 0) {
        for (long long int j = 0; j < (long long int)v[i].size(); j++) {
          ans[v[i][j]] = x;
        }
        x++;
      }
    }
    cout << cnt << '\n';
    for (long long int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
