#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//common consts
#define FILE_IN "numbers.in"
#define FILE_OUT "numbers.out"

//common structs

//common values
unsigned char lnum[6][3],dnum[6][3];
int a1,a2;
//common functions
int cmp(unsigned char *a,unsigned char *b){
	return (a[0]==b[0])	&& (a[1]==b[1]) && (a[2]==b[2]);
}

void cpy(unsigned char *a,unsigned char *b){
	a[0] = b[0];
	a[1] = b[1];
	a[2] = b[2];
}

int Gen(unsigned char a[6][3]){
	int i,j,t=0,ans;
	for (i=1;i<6;i++){
		a[++t][0] = a[0][i%3]; 
		a[t][1+i/3] = a[0][(i+1)%3];
		a[t][2-i/3] = a[0][(i+2)%3];
	}

	i = 1;
	ans = 6;
	
	while (i<ans) {
		for (j=0;j<i;j++) {
			if (cmp(a[i],a[j])) {
				j=-1;
				break;
			}
		}
		if (j==-1) {
			cpy(a[i],a[--ans]);
		} else i++;
	}
    
	return ans;                    
}

void Init(){

}

void OutData(){
	freopen(FILE_OUT,"w",stdout);
	int i,j;
	printf("%d\n",a1*a2);
	for (i=0;i<a1;i++)
		for (j=0;j<a2;j++) {
			printf("%c%c%c%c%c%c\n",lnum[i][0],dnum[j][0],dnum[j][1],dnum[j][2],lnum[i][1],lnum[i][2]);	
		}
	
	fclose(stdout);
	exit(0);
}

void ReadData(){
	freopen(FILE_IN,"r",stdin);
	
	scanf("%c",&lnum[0][0]);
	scanf("%c",&dnum[0][0]);
	scanf("%c",&dnum[0][1]);
	scanf("%c",&dnum[0][2]);
	scanf("%c",&lnum[0][1]);
	scanf("%c",&lnum[0][2]);
	
	fclose(stdin);
}

void Solve(){
	a1 = Gen(lnum);
	a2 = Gen(dnum);

}

int main() {
	Init();
	ReadData();
	Solve();
	OutData();
	
	return 0;
}