#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, T;
int c[1005], res[N];
set<int> SET;
map<int, int> S;
int d[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int main() {
  for (int i = 0; i <= 10; i++) c[d[i]] = i + 1;
  cin >> T;
  while (T--) {
    int ans = 0;
    cin >> n;
    S.clear();
    SET.clear();
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      for (int j = 2; j <= sqrt(x); j++) {
        if (x % j != 0) continue;
        if (SET.find(j) == SET.end()) {
          SET.insert(j);
          S[j] = ++ans;
        }
        res[i] = S[j];
        break;
      }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) cout << res[i] << " ";
    cout << "\n";
  }
}
