#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  while (b != 0) {
    int t = b;
    b = a % b;
    a = t;
  }
  return a;
}
int lca(int a, int b) { return a * b / gcd(a, b); }
int main() {
  int t;
  cin >> t;
  int n;
  for (int i = 0; i < t; ++i) {
    cin >> n;
    vector<int> a(n);
    for (int j = 0; j < n; ++j) {
      cin >> a[j];
    }
    vector<int> result;
    vector<bool> used_colors(11, false);
    map<int, int> m_colors;
    int m = 0;
    for (int j = 0; j < n; ++j) {
      if (a[j] % 2 == 0) {
        if (!used_colors[0]) {
          used_colors[0] = true;
          m++;
          m_colors[0] = m;
        }
        result.push_back(m_colors[0]);
      } else if (a[j] % 3 == 0) {
        if (!used_colors[1]) {
          used_colors[1] = true;
          m++;
          m_colors[1] = m;
        }
        result.push_back(m_colors[1]);
      } else if (a[j] % 5 == 0) {
        if (!used_colors[2]) {
          used_colors[2] = true;
          m++;
          m_colors[2] = m;
        }
        result.push_back(m_colors[2]);
      } else if (a[j] % 7 == 0) {
        if (!used_colors[3]) {
          used_colors[3] = true;
          m++;
          m_colors[3] = m;
        }
        result.push_back(m_colors[3]);
      } else if (a[j] % 11 == 0) {
        if (!used_colors[4]) {
          used_colors[4] = true;
          m++;
          m_colors[4] = m;
        }
        result.push_back(m_colors[4]);
      } else if (a[j] % 13 == 0) {
        if (!used_colors[5]) {
          used_colors[5] = true;
          m++;
          m_colors[5] = m;
        }
        result.push_back(m_colors[5]);
      } else if (a[j] % 17 == 0) {
        if (!used_colors[6]) {
          used_colors[6] = true;
          m++;
          m_colors[6] = m;
        }
        result.push_back(m_colors[6]);
      } else if (a[j] % 19 == 0) {
        if (!used_colors[7]) {
          used_colors[7] = true;
          m++;
          m_colors[7] = m;
        }
        result.push_back(m_colors[7]);
      } else if (a[j] % 23 == 0) {
        if (!used_colors[8]) {
          used_colors[8] = true;
          m++;
          m_colors[8] = m;
        }
        result.push_back(m_colors[8]);
      } else if (a[j] % 29 == 0) {
        if (!used_colors[9]) {
          used_colors[9] = true;
          m++;
          m_colors[9] = m;
        }
        result.push_back(m_colors[9]);
      } else if (a[j] % 31 == 0) {
        if (!used_colors[10]) {
          used_colors[10] = true;
          m++;
          m_colors[10] = m;
        }
        result.push_back(m_colors[10]);
      }
    }
    cout << m << '\n';
    for (int j = 0; j < n; ++j) {
      cout << result[j] << ' ';
    }
    cout << '\n';
  }
  return 0;
}
