#include <bits/stdc++.h>
using namespace std;
const long long int infinity = 9e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  for (int idx = 0; idx < t; idx++) {
    long long int n;
    cin >> n;
    vector<long long int> v(n);
    map<long long int, long long int> m;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      m[v[i]]++;
    }
    vector<long long int> v1(n);
    bool val = 0;
    if (v.size() > 2) {
      if (v[0] != v[n - 1] && v[n - 1] != v[n - 2] && v[0] != v[n - 2]) {
        val = 1;
      }
    }
    if (m.size() == 1) {
      cout << 1 << "\n";
      for (int i = 0; i < n; i++) {
        v1[i] = 1;
      }
    } else if (m.size() == 2) {
      cout << 2 << "\n";
      long long int a = (m.begin())->first;
      long long int b = (m.rbegin())->first;
      for (int i = 0; i < n; i++) {
        if (v[i] == a) {
          v1[i] = 1;
        } else {
          v1[i] = 2;
        }
      }
    } else {
      int x = 2;
      for (int i = 0; i < n; i++) {
        v1[i] = (i % 2) + 1;
      }
      if (n & 1) {
        if (v[n - 1] == v[n - 2]) {
          v1[n - 1] = 2;
        } else if (v[n - 1] == v[0]) {
          v1[n - 1] = 1;
        } else {
          v1[0] = 2;
          int i = 0;
          int y = 0;
          bool val1 = 1;
          for (; i < n - 1; i++) {
            if (v[i] == v[i + 1] && val1) {
              v1[i] = y + 1;
              v1[i + 1] = y + 1;
              val1 = 0;
              i++;
            } else {
              v1[i] = y + 1;
            }
            y = 1 - y;
          }
          v1[i] = y + 1;
          if (val1) {
            x++;
            for (int i = 0; i < n; i++) {
              v1[i] = (3 - (i % 3));
            }
            if (n % 3 == 1) v1[n - 1] = 2;
          }
        }
      }
      cout << x << "\n";
    }
    for (int i = 0; i < n; i++) {
      cout << v1[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
