#include <bits/stdc++.h>
using namespace std;
int SmallestPrime[1001];
vector<int> Primes;
void Print2DVector(vector<vector<int>>& v) {
  int i, j;
  for (i = 0; i < v.size(); i++) {
    for (j = 0; j < v[i].size(); j++) {
      cout << v[i][j];
      if (j == v[i].size() - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}
void PrintVector(vector<int>& v) {
  int i;
  for (i = 0; i < v.size(); i++) {
    cout << v[i];
    if (i == v.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}
void PrintArr(int* a, int N) {
  int i;
  for (i = 0; i < N; i++) {
    cout << a[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}
int gcd(int a, int b) {
  if (a < b) {
    {
      int t;
      t = a;
      a = b;
      b = t;
    }
  }
  int r = a % b;
  while (r) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
void PreProcessTables() {
  int i, j,
      Sieve[1001] = {
          0,
      };
  SmallestPrime[0] = SmallestPrime[1] = 1;
  for (i = 2; i < 1001; i++) {
    if (Sieve[i] == 0) {
      for (j = 2 * i; j < 1001; j += i) {
        if (Sieve[j] == 0) {
          SmallestPrime[j] = i;
          Sieve[j] = 1;
        }
      }
      SmallestPrime[i] = i;
      Primes.push_back(i);
    }
  }
}
void TC(int T) {
  int N, n, i;
  cin >> N;
  int A[N], C[N], D[11] = {0}, Cnt = 0;
  for (n = 0; n < N; n++) {
    cin >> A[n];
    for (i = 0; i < 11; i++) {
      if (SmallestPrime[A[n]] == Primes[i]) {
        C[n] = i;
        D[i]++;
        break;
      }
    }
  }
  for (i = 0; i < 11; i++) {
    if (D[i]) {
      Cnt++;
      D[i] = Cnt;
    }
  }
  cout << Cnt << endl;
  for (i = 0; i < N; i++) {
    cout << D[C[i]];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  PreProcessTables();
  int T, t;
  cin >> T;
  for (t = 1; t <= T; t++) {
    TC(t);
  }
  return 0;
}
