#include <bits/stdc++.h>
using namespace std;
using ll = int;
using ld = long double;
constexpr ll lim = 20 * 1000000;
int check[lim];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t;
  cin >> t;
  for (ll i = 0; i < t; i++) {
    ll n;
    cin >> n;
    vector<ll> in(n + 1);
    for (ll i = 0; i < n; i++) {
      cin >> in[i];
    }
    in[n] = in[0];
    vector<ll> color(n + 1, -1);
    color[0] = color[n] = 0;
    for (ll j = n - 1; color[j] < 0 && in[j] != in[j + 1]; j--) {
      color[j] = 0;
      while ((color[j] == color[j + 1] && in[j] != in[j + 1]) ||
             (color[j] == color[j - 1] && in[j] != in[j - 1]))
        color[j]++;
    }
    for (ll j = 1; color[j] < 0; j++) {
      color[j] = 0;
      while ((color[j] == color[j + 1] && in[j] != in[j + 1]) ||
             (color[j] == color[j - 1] && in[j] != in[j - 1]))
        color[j]++;
    }
    cout << *max_element(begin(color), end(color)) + 1 << endl;
    for (ll i = 0; i < n; i++) {
      cout << color[i] + 1 << " ";
    }
    cout << endl;
  }
}
