#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
typedef long long ll;
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,int y){x=upd(x+y-mod);}
inline void iadd(int &x,int y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
/*
typedef pair<int,int> P;
*/
#define rep(i,l,r) for (int i(l);i<=(r);i++)
#define per(i,l,r) for (int i(r);i>=(l);i--)

int n;
void solve(){
	n=read();
	printf("%d\n",(1<<n)-1);
	rep(i,1,(1<<n)-1){
		rep(j,0,(1<<n)-1) putchar("AB"[__builtin_parity(i&j)]);
		puts("");
	}
}
int main()
{
	for (int T=1;T--;) solve();
}
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<bool>>se(50,vector<bool>(50));
vector<vector<int>>sc(50,vector<int>(50));
vector<vector<int>>pe(50,vector<int>(50));//タイプ
vector<bool>ty(2505);//色
int pmax=0;
string smax;
int kaisu=0;
int ti=clock();
void dfs(int nx,int ny,int P,string S){//今のx,今のy,スコア,ルート
  if(pmax<P){
    pmax=P;smax=S;
  }
  kaisu++;
  //cout<<(long double)(clock())/(long double)(CLOCKS_PER_SEC)<<" "<<pmax<<endl;
  se[nx][ny]=true;
  ty[pe[nx][ny]]=true;
  if(nx!=0&&!se[nx-1][ny]&&!ty[pe[nx-1][ny]]){
    dfs(nx-1,ny,P+sc[nx-1][ny],S+'U');
    if(kaisu>14600000)return;
    se[nx-1][ny]=false;
    ty[pe[nx-1][ny]]=false;
  }
  if(nx!=49&&!se[nx+1][ny]&&!ty[pe[nx+1][ny]]){
    dfs(nx+1,ny,P+sc[nx+1][ny],S+'D');
    if(kaisu>14600000)return;
    se[nx+1][ny]=false;
    ty[pe[nx+1][ny]]=false;
  }
  if(ny!=0&&!se[nx][ny-1]&&!ty[pe[nx][ny-1]]){
    dfs(nx,ny-1,P+sc[nx][ny-1],S+'L');
    if(kaisu>14600000)return;
    se[nx][ny-1]=false;
    ty[pe[nx][ny-1]]=false;
  }
  if(ny!=49&&!se[nx][ny+1]&&!ty[pe[nx][ny+1]]){
    dfs(nx,ny+1,P+sc[nx][ny+1],S+'R');
    if(kaisu>14600000)return;
    se[nx][ny+1]=false;
    ty[pe[nx][ny+1]]=false;
  }
}
signed main(){
  int I,J;cin>>I>>J;
  ty.assign(2505,false);
  for(int X=0;X<50;X++){
    for(int Y=0;Y<50;Y++){
      cin>>pe[X][Y];
    }
  }
  for(int X=0;X<50;X++){
    for(int Y=0;Y<50;Y++){
      cin>>sc[X][Y];
      se[X][Y]=false;
    }
  }
  dfs(I,J,sc[I][J],"");
  cout<<smax<<endl;
}