//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = 1'000'000'000;
const ll llINF = 1'000'000'000'000'000'000;

int main() {
    int N;
    cin >> N;

    cout << (1<<N) - 1 << endl;
    if (N == 1) {
        cout << "AB" << endl;
        return 0;
    }

    vector<vector<int>> had2 = {{1,1},{1,-1}};
    vector<vector<int>> prev = had2, ans = had2;
    rep(k,2,N+1) {
        ans = vector<vector<int>>(1<<k,vector<int>(1<<k));
        rep(i,0,1<<k) rep(j,0,1<<k) {
            //cout << i << " " << j << endl;
            ans[i][j] = prev[i & ~(1<<k-1)][j & ~(1<<k-1)];
        }
        rep(i,1<<k-1,1<<k) rep(j,1<<k-1,1<<k) {
            ans[i][j] *= -1;
        }
        prev = ans;
    }

    rep(i,1,1<<N) {
        rep(j,0,1<<N) {
            cout << (ans[i][j] == 1 ? 'A' : 'B');
        }
        cout << endl;
    }
}
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define li long long
#define pii pair<int, int>
#define vi vector<int>
#define li long long

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

const int MAXN = 2005;

bool visited[MAXN];
vi edges[MAXN];
int n, m;

void dfs(int v) {
	visited[v] = true;
	for (int u : edges[v]) {
		if (!visited[u])
			dfs(u);
	}
}

void add_edge(int row, int col) {
	edges[row].pb(col + n);
	edges[col + n].pb(row);
}

int main() {
	scanf("%d%d", &n, &m);
	forn(i, n) {
		string s;
		cin >> s;
		forn(j, m) {
			if (s[j] == '#') {
				add_edge(i, j);
			}
		}
	}
	/*forn(i, n) {
		add_edge(i, 0);
		add_edge(i, m - 1);
	}
	forn(j, m) {
		add_edge(0, j);
		add_edge(n - 1, j);
	}*/
	add_edge(0, 0);
	add_edge(0, m);
	add_edge(n - 1, 0);
	add_edge(n - 1, m - 1);
	int row_comp = 0;
	forn(i, n) {
		if (!visited[i]) {
			++row_comp;
			dfs(i);
		}
	}
	memset(visited, false, sizeof(visited));
	int col_comp = 0;
	fore(i, n, n + m - 1) {
		if (!visited[i]) {
			++col_comp;
			dfs(i);
		}
	}
	//cerr << row_comp << " " << col_comp << endl;
	printf("%d", min(row_comp - 1, col_comp - 1));
}