#include <bits/stdc++.h>
using namespace std;
inline int dcmp(double a, double b) {
  return fabs(a - b) < (1e-9) ? 0 : a < b ? -1 : +1;
}
const int N = 1000 + 9;
int pr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
int ans[N];
vector<vector<int> > g;
int x[N];
bitset<N> del;
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    int n;
    scanf("%d", &n);
    for (auto i = 0; i < n; ++i) scanf("%d", x + i);
    for (int cnt = 0, p = 0; cnt != n; p++) {
      g.emplace_back(vector<int>());
      for (auto i = 0; i < n; ++i)
        if (!del[i] && x[i] % pr[p] == 0)
          del[i] = 1, g.back().emplace_back(i), cnt++;
      if (g.back().empty()) g.pop_back();
    }
    for (auto i = 0; i < ((int)((g).size())); ++i)
      for (auto j = 0; j < ((int)((g[i]).size())); ++j) ans[g[i][j]] = i;
    printf("%d\n", ((int)((g).size())));
    for (auto i = 0; i < n; ++i) printf("%d ", ans[i] + 1);
    puts("");
    del.reset();
    g.clear();
  }
  return 0;
}
