#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define foor(x,s,y) for(ll x = s ; x < y ; x++)
#define ff first
#define ss second
#define mod 1000000007LL
#define mmst(ar,va) memset(ar , va , sizeof(ar))
#define ndl "\n"
typedef long long ll;
typedef long double ld;
using namespace std;
//const ld PI = acos(-1);
char ccc;
ll n, m, ma, lu, l, r;
ll mem[101][101][2][30];
ll adj[101][101] , ret;
ll dfs(ll pm , ll pl ,bool turn , ll ch){
ll &ret = mem[pm][pl][turn][ch];
if(~ret)
return ret;
ret = !turn;
if(turn){
foor(i,1,n+1){
if(adj[pm][i] >= ch){
ret = max(ret , dfs(i , pl , !turn , adj[pm][i]));
}
}
}
else{
foor(i,1,n+1){
if(adj[pl][i] >= ch){
ret = min(ret , dfs(pm , i , !turn , adj[pl][i]));
}
}
}
return ret;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(NULL);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin>>n>>m;
mmst(adj , -1);
foor(i,0,m){
cin>>l>>r>>ccc;
adj[l][r] = (ccc - 'a');
}
mmst(mem , -1);
foor(i,1,n+1){
foor(j,1,n+1){
cout<<(dfs(i,j,1,0) ? 'A' : 'B');
}
cout<<ndl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSx4LmVuZCgpCiNkZWZpbmUgc3ooeCkgKGxsKXguc2l6ZSgpCiNkZWZpbmUgZm9vcih4LHMseSkgZm9yKGxsIHggPSBzIDsgeCA8IHkgOyB4KyspCiNkZWZpbmUgZmYgZmlyc3QKI2RlZmluZSBzcyBzZWNvbmQKI2RlZmluZSBtb2QgMTAwMDAwMDAwN0xMCiNkZWZpbmUgbW1zdChhcix2YSkgbWVtc2V0KGFyICwgdmEgLCBzaXplb2YoYXIpKQojZGVmaW5lIG5kbCAiXG4iCgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsK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gIGNpbj4+bD4+cj4+Y2NjOwogICAgICAgIGFkaltsXVtyXSA9IChjY2MgLSAnYScpOwogICAgfQogICAgCiAgICBtbXN0KG1lbSAsIC0xKTsKCiAgICBmb29yKGksMSxuKzEpewogICAgICAgIGZvb3IoaiwxLG4rMSl7CiAgICAgICAgICAgIGNvdXQ8PChkZnMoaSxqLDEsMCkgPyAnQScgOiAnQicpOwogICAgICAgIH0KICAgICAgICBjb3V0PDxuZGw7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K