#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int main(){
    long n;
    cin >> n;
    vector<vector<int>> vviNum(1, vector<int>(2));
    vviNum[0][0] = 0;
    vviNum[0][1] = 1;
    long iTmp = 4;
    for(long i = 0; i < n-1; i++){
        vector<vector<int>> vviNumTmp = vviNum;
        vviNum.resize(iTmp-1);
        for(int j = 0 ; j < iTmp -1; j++){
            vviNum[j].resize(iTmp);
        }
        for(int j = 0; j < iTmp/2; j++){
            for(int k = 0; k < iTmp/2 - 1; k++){
                vviNum[2*k][2*j] = vviNumTmp[k][j];
                vviNum[2*k][2*j+1] = vviNumTmp[k][j];
                vviNum[2*k+1][2*j] = vviNumTmp[k][j];
                vviNum[2*k+1][2*j+1] = 1-vviNumTmp[k][j];
            }
        }
        vector<int> viBack(iTmp,0);
        for(int j = 0; j < iTmp/2; j++){
            viBack[2*j+1] = 1;
        }
        vviNum[iTmp-2] = viBack;
        iTmp *= 2;
    }
    cout << vviNum.size() << endl;
    for(int i = 0; i < vviNum.size(); i++){
        for(int j = 0; j < vviNum[i].size(); j++){
            if(vviNum[i][j] == 0){
                printf("A");
            } else {
                printf("B");
            }
        }
        printf("\n");
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define PB push_back
constexpr int kN = int(1E3 + 10);
int n, tot, cnt[kN][kN];
vector<string> v;

bool check() {
	for (string i : v) {
		for (int j = 0; j < tot; j++) for (int k = j + 1; k < tot; k++) if (i[j] != i[k]) cnt[j][k]++;
	}
	
	for (int i = 0; i < tot; i++) for (int j = i + 1; j < tot; j++) if (cnt[i][j] != cnt[0][1]) {
		printf("cnt[%d][%d] = %d\n", i, j, cnt[i][j]);
		return false;
	}
	return true;
}

vector<string> solve(int n) {
	vector<string> ans;
	int tot = 1 << n;
	string s;
	for (int i = 1; i <= tot / 2; i++) s += "A";
	for (int i = 1; i <= tot / 2; i++) s += "B";
	ans.PB(s);
	if (n == 1) return ans;
	else {
		vector<string> tmp = solve(n - 1);
		for (string i : tmp) ans.PB(i + i);
		for (string i : tmp) {
			string ss = i;
			for (int j = 0; j < tot / 2; j++) if (i[j] == 'A') ss += "B";
			else ss += "A";
			ans.PB(ss);
		}
		return ans;
	}
}

int main() {
	cin >> n;
	//for (int i = 3; i <= tot; i++) {
	//	for (int j = tot - 1; j > 1; j--) if (s[j] == 'B' && s[j - 1] == 'A') {
	//		swap(s[j], s[j - 1]);
	//		j--;
	//	}
	//	v.PB(s);
	//}

	v = solve(n);
	assert(check());
	cout << int(v.size()) << "\n";
	for (string i : v) cout << i << "\n";
}
