s="| |";i=13;main(n,v){for(n=v%3;gets(v);puts(i--?n?i/8+~n?s:i<5?v:"| r|\x00| b|\x00|g b|"+63-9*i:i<2?"|b yyg|\x00|y |"+9*i:s:v));printf("%d chains",n?~n?19:2:9);}
Note that non-ascii characters in the above source code will be escaped (such as \x9f).