#include <bits/stdc++.h>
#define ll long long
#define dbl double
using namespace std;
const int N = 111;
const int INF = 1000 * 1000 * 1000;
vector<pair<int,int>> g[N];
int memo[N][N][50];
int first_wins(int a, int b, int prev){
if(memo[a][b][prev] != -1) return memo[a][b][prev];
// if can do smth such that second loses then true
int res = 0;
for(auto p : g[a]){
int to = p.first;
int letter = p.second;
if(letter >= prev){
if(!first_wins(b,to,letter)){
res = 1;
}
}
}
return memo[a][b][prev] = res;
}
int main() {
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
for(int k= 0 ; k < 50; k++){
memo[i][j][k]= -1;
}
}
}
int n,m;
cin >> n >> m;
for(int i = 0; i < m; i++){
int u,v;
string s;
cin >> u >> v >> s;
u--,v--;
g[u].push_back({v,s[0]-'a'+1});
}
for(int av = 0; av < n; av++){
for(int bv = 0; bv < n; bv++){
int a_wins = first_wins(av,bv,0);
if(a_wins){
cout << 'A';
}
else{
cout << 'B';
}
}
cout << endl;
}
return 0;
}
CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBkYmwgIGRvdWJsZQoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBOID0gMTExOwpjb25zdCBpbnQgSU5GID0gMTAwMCAqIDEwMDAgKiAxMDAwOwoKdmVjdG9yPHBhaXI8aW50LGludD4+IGdbTl07CgppbnQgbWVtb1tOXVtOXVs1MF07CgppbnQgZmlyc3Rfd2lucyhpbnQgYSwgaW50IGIsIGludCBwcmV2KXsKICAgIGlmKG1lbW9bYV1bYl1bcHJldl0gIT0gLTEpIHJldHVybiBtZW1vW2FdW2JdW3ByZXZdOwoKICAgIC8vIGlmIGNhbiBkbyBzbXRoIHN1Y2ggdGhhdCBzZWNvbmQgbG9zZXMgdGhlbiB0cnVlCiAgICBpbnQgcmVzID0gMDsKICAgIGZvcihhdXRvIHAgOiBnW2FdKXsKICAgICAgICBpbnQgdG8gPSBwLmZpcnN0OwogICAgICAgIGludCBsZXR0ZXIgPSBwLnNlY29uZDsKICAgICAgICBpZihsZXR0ZXIgPj0gcHJldil7CiAgICAgICAgICAgIGlmKCFmaXJzdF93aW5zKGIsdG8sbGV0dGVyKSl7CiAgICAgICAgICAgICAgICByZXMgPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIG1lbW9bYV1bYl1bcHJldl0gPSByZXM7Cn0KCmludCBtYWluKCkgewogICAgZm9yKGludCBpID0gMDsgaSA8IE47IGkrKyl7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IE47IGorKyl7CiAgICAgICAgICAgIGZvcihpbnQgaz0gMCA7IGsgPCA1MDsgaysrKXsKICAgICAgICAgICAgICAgIG1lbW9baV1bal1ba109IC0xOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGludCBuLG07CiAgICBjaW4gPj4gbiA+PiBtOwogICAgZm9yKGludCBpID0gMDsgaSA8IG07IGkrKyl7CiAgICAgICAgaW50IHUsdjsKICAgICAgICBzdHJpbmcgczsKICAgICAgICBjaW4gPj4gdSA+PiB2ID4+IHM7CiAgICAgICAgdS0tLHYtLTsKICAgICAgICBnW3VdLnB1c2hfYmFjayh7dixzWzBdLSdhJysxfSk7CiAgICB9CgoKICAgIGZvcihpbnQgYXYgPSAwOyBhdiA8IG47IGF2KyspewogICAgICAgIGZvcihpbnQgYnYgPSAwOyBidiA8IG47IGJ2KyspewogICAgICAgICAgICBpbnQgYV93aW5zID0gZmlyc3Rfd2lucyhhdixidiwwKTsKICAgICAgICAgICAgaWYoYV93aW5zKXsKICAgICAgICAgICAgICAgIGNvdXQgPDwgJ0EnOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICBjb3V0IDw8ICdCJzsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==