#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=266,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int n,pos[maxn],s[maxn][maxn],t[maxn][maxn];
int main(){
	n=read();
	s[1][1]=0;s[1][2]=1;
	FOR(i,2,n){
		memcpy(t,s,sizeof(t));
		memset(s,0,sizeof(s));
		FOR(j,1,(1<<i)) s[1][j]=j>(1<<(i-1));
		FOR(j,1,(1<<i)){
			FOR(k,1,(1<<(i-1))) s[j+1][k]=t[(j+1)/2][k];
			FOR(k,1,(1<<(i-1))) s[j+1][k+(1<<(i-1))]=j%2?t[(j+1)/2][k]:t[(j+1)/2][k]^1;
		}
/*		FOR(j,1,(1<<(i-1))-1){
			FOR(k,1,(1<<(i-1))) putchar(t[j][k]?'B':'A');
			puts("");
		}
		puts("");*/
	}
	printf("%d\n",(1<<n)-1);
	FOR(i,1,(1<<n)-1){
		FOR(j,1,(1<<n)) putchar(s[i][j]?'B':'A');
		puts("");
	}
}
/*
n=2
AABB
ABAB
ABBA

n=3
AAAABBBB
AABBAABB
AABBBBAA
ABABABAB
ABABBABA
ABBAABBA
ABBABAAB

(2^n-1)|(2^{n-1}-1)*k
7|3*k

every pair 2^{n-1}-1 times 
*/
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt1[500][500];
int cnt2[500][500];
int team[500][500];
int tgt=0;
bool deta=false;
int col[500][500];

int main(void){
	scanf("%d",&n);
	if(n==1){
		printf("1\n");
		printf("AB\n");
		return 0;
	}
	if(n==2){
		printf("3\n");
		printf("AABB\n");
		printf("ABAB\n");
		printf("ABBA\n");
		return 0;
	}
	col[0][2]=1;
	col[0][3]=1;
	col[1][1]=1;
	col[1][3]=1;
	col[2][1]=1;
	col[2][2]=1;
	int m=(1<<n);
	int s=2;
	int sz=3;
	int len=4;
	for(int i=2;i<n;i++){
		for(int j=0;j<sz;j++){
			for(int k=0;k<len;k++){
				col[j+sz][k]=col[j][k];
			}
		}
		for(int j=0;j<sz;j++){
			for(int k=0;k<len;k++){
				col[j][k+len]=col[j][k];
				col[j+sz][k+len]=1-col[j+sz][k];
			}
		}
		for(int j=0;j<len;j++){
			col[sz*2][j+len]=1;
		}
		sz=sz*2+1;
		len=len*2;
	}
	printf("%d\n",m-1);
	for(int i=0;i<m-1;i++){
		for(int j=0;j<m;j++){
			printf("%c",col[i][j]==0?'A':'B');
		}
		printf("\n");
	}
	return 0;
}
