#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, k;
  cin >> t;
  int flag;
  int primes[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  while (t--) {
    cin >> n;
    int a;
    int m_div[11] = {0};
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      cin >> a;
      for (int j = 0; j < 11; j++) {
        if (a % primes[j] == 0) {
          flag = 0;
          for (int l = 0; l < 11; l++) {
            if (m_div[l] == primes[j]) {
              ans.push_back(l);
              flag = 1;
              break;
            }
          }
          if (flag == 0) {
            for (int l = 0; l < 11; l++) {
              if (m_div[l] == 0) {
                m_div[l] = primes[j];
                ans.push_back(l);
                break;
              }
            }
          }
          break;
        }
      }
    }
    flag = 0;
    for (int i = 0; i < 11; i++) {
      if (m_div[i] == 0) {
        cout << i << endl;
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      cout << "11" << endl;
    }
    for (int i = 0; i < n; i++) {
      cout << ans[i] + 1 << " ";
    }
    cout << endl;
  }
}
