#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  int prime[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    map<int, int> mp;
    vector<int> ans;
    int cnt = 1;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      for (int j = 0; j < 11; j++) {
        if (arr[i] % prime[j] == 0) {
          if (mp[prime[j]] == 0) {
            mp[prime[j]] = cnt;
            cnt++;
          }
          ans.push_back(mp[prime[j]]);
          break;
        }
      }
    }
    cout << mp.size() << endl;
    for (auto it = ans.begin(); it != ans.end(); it++) {
      cout << *it << " ";
    }
    cout << endl;
  }
  return 0;
}
