#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int T, N, init[30], answer;
int *getArrayCopy(int *src) {
int *copy = new int[N];
for (int i = 0; i < N; i++) {
copy[i] = src[i];
}
return copy;
}
int calcResult(int *chess){
int result = 0;
for (int i = 0; i < 30; i++) {
if (chess[i] == 1){
result++;
}
}
return result;
}
void turnOver(int *chess, int position, int type){
int opposition = type == 1 ? 2 : 1;
int left = position;
int right = position;
for (int i = position - 1; i >= 0; i--) {
if (i == 0){
if (chess[i] == 0){
left = position;
}
else {
left = 0;
}
}
else {
if (chess[i] == opposition){
left = i;
}
else if (chess[i] == type){
break;
}
else {
left = position;
break;
}
}
}
for (int i = position + 1; i < N; i++) {
if (i == N - 1){
if (chess[i] == 0){
right = position;
}
else{
right = N - 1;
}
}
else {
if (chess[i] == opposition){
right = i;
}
else if (chess[i] == type){
break;
}
else {
right = position;
break;
}
}
}
for (int i = left; i <= right; i++) {
chess[i] = type;
}
}
void whiteStep(int *chess){
for (int i = 0; i < N; i++) {
if (chess[i] == 0){
chess[i] = 2;
turnOver(chess, i, 2);
return;
}
}
}
void printResult(int *chess){
for (int i = 0; i < N; i++) {
printf("%d ", chess[i]);
}
printf("\n");
}
void dfs(int *chess, int steps){
if (steps == 3){
int result = calcResult(chess);
if (answer < result){
printf("%d: ", result);
printResult(chess);
answer = result;
}
return;
}
for (int i = 0; i < N; i++) {
if (chess[i] == 0){
int *chessCopy = getArrayCopy(chess);
chessCopy[i] = 1;
turnOver(chessCopy, i, 1);
whiteStep(chessCopy);
dfs(chessCopy, steps + 1);
}
}
}
int main(int argc, char** argv) {
freopen("sample_input.txt", "r", stdin);
setbuf(stdout, NULL);
scanf("%d", &T);
for (int test_case = 1; test_case <= T; ++test_case){
scanf("%d", &N);
for (int i = 0; i < N; i++){
scanf("%d", &init[i]);
}
answer = -1;
dfs(init, 0);
printf("#%d %d\n", test_case, answer);
}
return 0;
}